Changeset 1503
- Timestamp:
- 25.03.2008 09:24:47 (2 months ago)
- Files:
-
- trunk/pylucid/PyLucid/middlewares/headline_anchor.py (added)
- trunk/pylucid/PyLucid/middlewares/pagestats.py (modified) (1 diff)
- trunk/pylucid/PyLucid/middlewares/page_cache_debug.py (modified) (1 diff)
- trunk/pylucid/PyLucid/settings_example.py (modified) (1 diff)
- trunk/pylucid/PyLucid/system/tinyTextile.py (modified) (4 diffs)
- trunk/pylucid/PyLucid/tools/content_processors.py (modified) (1 diff)
- trunk/pylucid/PyLucid/tools/shortcuts.py (modified) (4 diffs)
- trunk/pylucid/tests/test_tinyTextile.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/pylucid/PyLucid/middlewares/pagestats.py
r1481 r1503 67 67 68 68 # Put only the statistic into HTML pages 69 if response._headers.get('content-type', None) == "text/html":69 if not "html" in response._headers["content-type"][1]: 70 70 # No HTML Page -> do nothing 71 71 return response trunk/pylucid/PyLucid/middlewares/page_cache_debug.py
r1168 r1503 53 53 54 54 content = response.content 55 if "html" in response. headers['Content-Type']:55 if "html" in response._headers["content-type"][1]: 56 56 # Try to insert the info into a html valid way. 57 57 old_content = content trunk/pylucid/PyLucid/settings_example.py
r1499 r1503 105 105 'django.middleware.doc.XViewMiddleware', 106 106 107 # Add a human readable anchor to every html headline: 108 'PyLucid.middlewares.headline_anchor.HeadlineAnchor', 109 110 # Insert a statistic line into the generated page: 107 111 'PyLucid.middlewares.pagestats.PageStatsMiddleware', 108 112 ) trunk/pylucid/PyLucid/system/tinyTextile.py
r1500 r1503 28 28 __version__ = "$Rev$" 29 29 30 import sys, re , string30 import sys, re 31 31 32 32 from PyLucid.tools.utils import escape … … 34 34 35 35 36 HEADLINE = (37 '<h%(no)s id="%(anchor)s">'38 '<a title="Link to this section" href="%(link)s#%(anchor)s" class="anchor">'39 '%(txt)s</a>'40 '</h%(no)s>\n'41 )42 43 44 36 class TinyTextileParser: 45 def __init__(self, out_obj, permalink,context):37 def __init__(self, out_obj, context): 46 38 self.out = out_obj 47 self.permalink = permalink48 39 self.context = context 49 40 self.page_msg = context["page_msg"] … … 53 44 [ # <h1>-Headlines 54 45 r"\Ah(\d)\. (.+)(?usm)", 55 self.headline46 r"<h\1>\2</h\1>" 56 47 ], 57 48 ]) … … 165 156 def escaping(self, matchobj): 166 157 return escape(matchobj.group(1)) 167 168 def headline(self, matchobj):169 """170 Insert a html headline with a anchor.171 """172 text = matchobj.group(2)173 anchor = "".join(174 [char for char in text if char in string.ascii_letters]175 )176 result = HEADLINE % {177 "no": matchobj.group(1),178 "txt": text,179 "link": self.permalink,180 "anchor": anchor,181 }182 return result183 158 184 159 def shortcutLink(self, matchobj): trunk/pylucid/PyLucid/tools/content_processors.py
r1500 r1503 46 46 from PyLucid.system.tinyTextile import TinyTextileParser 47 47 out_obj = SimpleStringIO() 48 49 current_page = context["PAGE"] 50 permalink = current_page.get_permalink() 51 52 markup_parser = TinyTextileParser(out_obj, permalink, context) 48 markup_parser = TinyTextileParser(out_obj, context) 53 49 markup_parser.parse(content) 54 50 content = out_obj.getvalue() trunk/pylucid/PyLucid/tools/shortcuts.py
r1331 r1503 11 11 $Author$ 12 12 13 :copy right: 2007by Jens Diemer.13 :copyleft: 2007-2008 by Jens Diemer. 14 14 :license: GNU GPL v3, see LICENSE.txt for more details. 15 15 """ 16 16 17 17 import string 18 18 19 ALLOW_CHARS = string.ascii_letters + string.digits + "_" 20 19 21 20 22 def makeUnique(item_name, name_list): 21 23 """ 22 returns a unique shortcut.24 returns a URL safe, unique shortcut. 23 25 - delete all non-ALLOW_CHARS characters. 24 26 - if the shotcut already exists in name_list -> add a sequential number 25 27 Note: 26 Not only used for making page shortcuts unique. 27 Also used in PyLucid.defaulttags.lucidTag.lucidTagNode._add_unique_div() 28 Not only used for making page shortcuts unique with getUniqueShortcut(), 29 also used in: 30 -PyLucid.defaulttags.lucidTag.lucidTagNode._add_unique_div() 31 -PyLucid.middlewares.headline_anchor.HeadlineAnchor() 28 32 """ 29 33 # delete all non-ALLOW_CHARS characters and separate in parts … … 32 36 if not char in ALLOW_CHARS: 33 37 if parts[-1] != "": 34 # No double "-" e.g.: "foo - bar" -> "foo-bar" not "foo---bar" 38 # No double "-" e.g.: "foo - bar" -> "foo-bar" not "foo---bar" 35 39 parts.append("") 36 40 else: … … 56 60 return item_name 57 61 62 58 63 def getUniqueShortcut(shortcut, exclude_shortcut=None): 59 64 from PyLucid.models import Page … … 67 72 # print "existing_shortcuts:", existing_shortcuts 68 73 return makeUnique(shortcut, existing_shortcuts) 74 69 75 70 76 trunk/pylucid/tests/test_tinyTextile.py
r1500 r1503 35 35 #VERBOSE = 1 36 36 VERBOSE = 2 37 38 PERMALINK = "/permalink/"39 37 40 38 … … 113 111 self.fake_context = get_fake_context() 114 112 self.out = SimpleStringIO() 115 self.textile = TinyTextileParser(self.out, PERMALINK,self.fake_context)113 self.textile = TinyTextileParser(self.out, self.fake_context) 116 114 117 115 def tearDown(self): … … 243 241 """) 244 242 out_test = self._prepare_text(""" 245 <h1 id="headlineA"><a title="Link to this section" href="/permalink/#headlineA" class="anchor">headline A</a></h1> 246 243 <h1>headline A</h1> 247 244 <p>Text1</p> 248 <h2 id="headlineB"><a title="Link to this section" href="/permalink/#headlineB" class="anchor">headline B $%#</a></h2> 249 245 <h2>headline B $%#</h2> 250 246 <p>Text2</p> 251 247
