ChristopherLenz: wiki2x_in_templates.diff
| File wiki2x_in_templates.diff, 7.7 KB (added by cmlenz, 6 years ago) |
|---|
-
trac/mimeview/patch.py
55 55 56 56 add_stylesheet(req, 'common/css/diff.css') 57 57 return Chrome(self.env).render_response(req, 'diff_div.html', 58 'text/html', data) 58 'text/html', data, 59 fragment=True) 59 60 60 61 # Internal methods 61 62 -
trac/wiki/web_ui.py
396 396 if page.name == 'WikiStart': 397 397 data['title'] = '' 398 398 399 page_html = comment_html = attach_href = '' 400 latest_page = WikiPage(self.env, page.name) 401 399 comment_html = attach_href = '' 402 400 if page.exists: 403 page_html = wiki_to_html(page.text, self.env, req, db)401 latest_page = WikiPage(self.env, page.name) 404 402 if version: 405 403 comment_html = wiki_to_oneliner(page.comment or '--', 406 404 self.env, db) 407 405 else: 408 406 if not req.perm.has_permission('WIKI_CREATE'): 409 407 raise HTTPNotFound('Page %s not found', page.name) 410 page_html = html.P('Describe "%s" here' % data['page_name'])411 408 412 409 # Show attachments 413 410 attachments = attachments_data(self.env, req, db, 'wiki', page.name) … … 419 416 WikiSystem(self.env).get_pages(prefix)] 420 417 421 418 data.update({'action': 'view', 422 'page_html': page_html,423 419 'comment_html': comment_html, 424 420 'latest_version': latest_page.version, 425 421 'attachments': attachments, -
trac/web/chrome.py
36 36 format_time, http_date 37 37 from trac.web.api import IRequestHandler, HTTPNotFound 38 38 from trac.web.href import Href 39 from trac.wiki import IWikiSyntaxProvider39 from trac.wiki import wiki_to_html, wiki_to_oneliner, IWikiSyntaxProvider 40 40 41 41 def add_link(req, rel, href, title=None, mimetype=None, classname=None): 42 42 """Add a link to the HDF data set that will be inserted as <link> element in 43 43 the <head> of the generated HTML 44 44 """ 45 linkid = '%s:%s' % (rel, href) 46 linkset = req.environ.setdefault('trac.chrome.linkset', {}) 47 if linkid in linkset: 48 return # Already added that link 49 45 50 link = {'href': href} 46 51 if title: 47 52 link['title'] = title … … 49 54 link['type'] = mimetype 50 55 if classname: 51 56 link['class'] = classname 52 # FIXME: don't add the same link more than once53 req.environ.setdefault('trac.chrome.links', {}).setdefault(rel, []).append(link)54 57 58 links = req.environ.setdefault('trac.chrome.links', {}) 59 links.setdefault(rel, []).append(link) 60 linkset[linkid] = True 61 55 62 def add_stylesheet(req, filename, mimetype='text/css'): 56 63 """Add a link to a style sheet to the HDF data set so that it gets included 57 64 in the generated HTML page. … … 61 68 filename = filename[7:] 62 69 else: 63 70 href = Href(req.base_path).chrome 64 add_link(req, 'stylesheet', href(filename), mimetype=mimetype) 71 link = href(filename) 72 add_link(req, 'stylesheet', link, mimetype=mimetype) 65 73 66 74 def add_script(req, filename, mimetype='text/javascript'): 67 75 """Add a reference to an external javascript file to the template.""" 76 scriptset = req.environ.setdefault('trac.chrome.scriptset', {}) 77 if filename in scriptset: 78 return False # Already added that script 79 68 80 if filename.startswith('common/') and 'trac.htdocs_location' in req.environ: 69 81 href = Href(req.environ['trac.htdocs_location']) 70 82 filename = filename[7:] 71 83 else: 72 84 href = Href(req.base_path).chrome 73 85 script = {'href': href(filename), 'type': mimetype} 74 # FIXME: don't add the same script more than once 86 75 87 req.environ.setdefault('trac.chrome.scripts', []).append(script) 88 scriptset[filename] = True 76 89 77 90 def add_javascript(req, filename): 78 91 """Deprecated: use `add_script()` instead.""" 79 add_script(req, filename, mimetype='text/javascript')92 return add_script(req, filename, mimetype='text/javascript') 80 93 81 94 82 95 class INavigationContributor(Interface): … … 412 425 data['format_time'] = partial(format_time, tzinfo=req.tz) 413 426 data['fromtimestamp'] = partial(datetime.fromtimestamp, tz=req.tz) 414 427 428 # Wiki-formatting functions 429 data['wiki_to_html'] = partial(wiki_to_html, env=self.env, req=req) 430 data['wiki_to_oneliner'] = partial(wiki_to_html, env=self.env, req=req) 431 415 432 def load_template(self, filename, method=None): 416 433 """Retrieve a Template and optionally preset the template data. 417 434 … … 428 445 429 446 return self.templateloader.load(filename, cls=cls) 430 447 431 def render_response(self, req, template_name, content_type, data): 448 def render_response(self, req, template_name, content_type, data, 449 fragment=False): 432 450 """Render the `template_name` using the `data` for the context. 433 451 434 452 The MIME `content_type` argument is used to choose the kind of template … … 438 456 """ 439 457 if content_type is None: 440 458 content_type = 'text/html' 441 doctype = {'text/html': DocType.XHTML_STRICT}.get(content_type)442 459 method = {'text/html': 'xhtml', 443 460 'text/plain': 'text'}.get(content_type, 'xml') 444 461 445 462 template = self.load_template(template_name, method=method) 446 463 self.populate_data(req, data) 447 448 464 stream = template.generate(**data) 465 if fragment: 466 return stream 449 467 468 doctype = {'text/html': DocType.XHTML_STRICT}.get(content_type) 469 req.environ['trac.chrome.links'] = {} 470 req.environ['trac.chrome.scripts'] = [] 471 data['chrome'].update({ 472 'post_links': req.environ['trac.chrome.links'], 473 'post_scripts': req.environ['trac.chrome.scripts'], 474 }) 475 450 476 if method == 'text': 451 477 return stream.render('text') 452 478 else: -
templates/layout.html
50 50 <div id="main"> 51 51 ${select('*|text()')} 52 52 53 <script type="text/javascript" py:if="chrome.post_links"> 54 <py:for each="link in chrome.post_links.get('stylesheet')"> 55 $.loadStyleSheet("${link.href}", "${link.title}"); 56 </py:for> 57 </script> 58 <script py:for="script in chrome.post_scripts" 59 type="${script.type}" src="${script.href}"></script> 60 53 61 <div id="altlinks" py:if="chrome.links.alternate"> 54 62 <h3>Download in other formats:</h3> 55 63 <ul> -
templates/wiki_view.html
40 40 </table> 41 41 </py:if> 42 42 43 <div class="wikipage searchable"> 44 $page_html 43 <div class="wikipage searchable" py:choose=""> 44 <py:when test="page.exists"> 45 ${wiki_to_html(page.text)} 46 </py:when> 47 <py:otherwise> 48 Describe ${page.name} here. 49 </py:otherwise> 45 50 </div> 46 51 47 52 ${list_of_attachments(attachments, attach_href, compact=True)}
