Edgewall Software

Changeset 3730


Ignore:
Timestamp:
Sep 13, 2006, 6:30:26 PM (17 years ago)
Author:
Christian Boos
Message:

Genshi branch: converted text templates to use the new TextTemplate template format (see Genshi:wiki:ApiDocs/genshi.template#genshi.template:TextTemplate).

Location:
sandbox/genshi
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sandbox/genshi/templates/revisionlog.txt

    r3725 r3730  
    1 <changelog xmlns:py="http://genshi.edgewall.org/" py:strip="">
    21#
    32# ChangeLog for $path
     
    54# Generated by Trac $trac.version
    65# ${format_datetime}
    7 #
    8   <py:for each="item in items" py:with="change = changes[item.rev]">
    9 $change.date $change.author [$item.rev]<!--!
    10     --><py:for each="idx, file in enumerate(change.files)">
    11         * $file (<py:choose test="change.actions[idx]"><!--! FIXME: much simpler solution with #M37
    12         --><py:when test="'edit'">modified</py:when><!--!
    13         --><py:when test="'add'">added</py:when><!--!
    14         --><py:when test="'delete'">deleted</py:when><!--!
    15         --><py:when test="'copy'">copied</py:when><!--!
    16         --><py:when test="'move'">moved</py:when><!--!
    17         --></py:choose>)</py:for>
     6#for item in items
     7  #with change = changes[item.rev]
     8$change.date $change.author [$item.rev]
     9    #for idx, file in enumerate(change.files)
     10        * $file (${dict(edit='modified', add='added', delete='deleted',
     11                        copy='copied', move='moved')[change.actions[idx]]})
     12    #end
    1813$change.message
    19     </py:for>
    20 </changelog>
     14  #end
     15#end
  • sandbox/genshi/templates/ticket_notify_email.txt

    r3725 r3730  
    1 <mail xmlns:py="http://genshi.edgewall.org/" py:strip=""><!--!
    2 
    3   Some notes about how to handle white-spaces in text templates:
    4 
    5   - every structure tag should be followed by a comment start: < ! - - !
    6 
    7   - every tag but the first should be preceeded by a comment end: - - >
    8 
    9   - text data following a new line will be inserted either directly,
    10     by first ending the comment then placing the content on the same
    11     line, or inserted after a newline, by first closing the comment,
    12     then placing the data on a line of its own.
    13 
    14   - after text data, a comment start should be started on a newline,
    15     which will effectively insert a newline.
    16     Sometimes though this is not wanted, for example when the data
    17     itself ends with a newline... (see $changes_body below)
    18 
    19 -->
    201$ticket_body_hdr
    212$ticket_props
    22 <!--!
    23   --><py:choose test="ticket.new"><!--!
    24     --><py:when test="True"><!--!
    25 -->
     3#choose ticket.new
     4  #when True
    265$ticket.description
    27 <!--!
    28     --></py:when><!--!
    29     --><py:otherwise><!--!
    30       --><py:if test="changes_body"><!--!
    31 -->
     6  #end
     7  #otherwise
     8    #if changes_body
    329Changes (by $change.author):
    3310
    34 $changes_body<!--!
    35       --></py:if><!--!
    36       --><py:if test="changes_descr"><!--!
    37 -->
     11$changes_body
     12    #end
     13    #if changes_descr
    3814$changes_descr
    3915--
    40 <!--!
    41       --></py:if><!--!
    42       --><py:if test="change.comment"><!--!
    43 -->
    44 Comment<py:if test="not changes_body"> (by $change.author)</py:if>:
     16    #end
     17    #if change.comment
     18
     19Comment${not changes_body and '(by %s)' % change.author or ''}:
    4520
    4621$change.comment
    47 <!--!
    48       --></py:if><!--!
    49     --></py:otherwise><!--!
    50   --></py:choose><!--!
    51 -->
     22    #end
     23  #end
     24#end
     25
    5226--
    53 Ticket URL: &lt;$ticket.link&gt;
    54 $project.name &lt;${abs_href}&gt;
     27Ticket URL: <$ticket.link>
     28$project.name <${abs_href}>
    5529$project.descr
    56 </mail>
  • sandbox/genshi/trac/notification.py

    r3725 r3730  
    9797        self.db = env.get_db_cnx()
    9898
    99         self.template = Chrome(self.env).load_template(self.template_name)
     99        self.template = Chrome(self.env).load_template(self.template_name,
     100                                                       method='text')
    100101        self.data = {'CRLF': CRLF}
    101102        Chrome(self.env).populate_data(None, self.data)
  • sandbox/genshi/trac/web/chrome.py

    r3725 r3730  
    2222from genshi.builder import tag
    2323from genshi.output import DocType
    24 from genshi.template import TemplateLoader
     24from genshi.template import TemplateLoader, MarkupTemplate, TextTemplate
    2525
    2626from trac import mimeview
     
    419419        from pprint import pformat
    420420        data['pprint'] = pformat
    421         if req:
    422             data['GENSHI_DEBUG'] = req.args.get('genshi_debug')
    423 
    424     def load_template(self, filename, req=None, data=None):
    425         """Retrieve a Template and optionally preset the template data"""
     421
     422    def load_template(self, filename, req=None, data=None, method=None):
     423        """Retrieve a Template and optionally preset the template data.
     424
     425        If `req` and `data` are given, the `data` dictionary will be preset
     426        with the "standard" Trac information and helper methods.
     427
     428        Also, if the optional `method` argument is set to `'text'`, a
     429        TextTemplate instance will be created instead of a MarkupTemplate.
     430        """
    426431        if req and data:
    427432            self.populate_data(req, data)
     
    429434            self.templateloader = TemplateLoader(self.get_all_templates_dirs(),
    430435                                                 auto_reload=self.auto_reload)
    431         return self.templateloader.load(filename)
     436        cls = method == 'text' and TextTemplate or MarkupTemplate
     437        return self.templateloader.load(filename, cls=cls)
    432438
    433439    def render_response(self, req, template_name, content_type, data):
    434         self.populate_data(req, data)
    435 
    436         stream = self.load_template(template_name).generate(**data)
    437 
     440        """Render the `template_name` using the `data` for the context.
     441
     442        The MIME `content_type` argument is used to choose the kind of template
     443        used (TextTemplate if `'text/plain'`, MarkupTemplate otherwise), and
     444        tweak the rendering process (use of XHTML Strict doctype if
     445        `'text/html'` is given).
     446        """
    438447        if content_type is None:
    439448            content_type = 'text/html'
     449        doctype = {'text/html': DocType.XHTML_STRICT}.get(content_type)
    440450        method = {'text/html': 'xhtml',
    441451                  'text/plain': 'text'}.get(content_type, 'xml')
    442         doctype = {'text/html': DocType.XHTML_STRICT}.get(content_type)
     452       
     453        template = self.load_template(template_name, req, data, method=method)
     454        stream = template.generate(**data)
    443455
    444456        if method == 'text':
    445457            return stream.render('text')
    446         return stream.render(method, doctype=doctype)
     458        else:
     459            return stream.render(method, doctype=doctype)
Note: See TracChangeset for help on using the changeset viewer.