Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes
MoinMoin.support.pygments.lexers.templates.ErbLexer Class Reference
Inheritance diagram for MoinMoin.support.pygments.lexers.templates.ErbLexer:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.pygments.lexers.templates.ErbLexer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_tokens_unprocessed
def analyse_text

Public Attributes

 ruby_lexer

Static Public Attributes

string name = 'ERB'
list aliases = ['erb']
list mimetypes = ['application/x-ruby-templating']

Static Private Attributes

tuple _block_re = re.compile(r'(<%%|%%>|<%=|<%#|<%-|<%|-%>|%>|^%[^%].*?$)', re.M)

Detailed Description

Generic `ERB <http://ruby-doc.org/core/classes/ERB.html>`_ (Ruby Templating)
lexer.

Just highlights ruby code between the preprocessor directives, other data
is left untouched by the lexer.

All options are also forwarded to the `RubyLexer`.

Definition at line 44 of file templates.py.


Constructor & Destructor Documentation

Definition at line 61 of file templates.py.

00061 
00062     def __init__(self, **options):
00063         from pygments.lexers.agile import RubyLexer
00064         self.ruby_lexer = RubyLexer(**options)
00065         Lexer.__init__(self, **options)


Member Function Documentation

Definition at line 134 of file templates.py.

00134 
00135     def analyse_text(text):
00136         if '<%' in text and '%>' in text:
00137             return 0.4
00138 

Since ERB doesn't allow "<%" and other tags inside of ruby
blocks we have to use a split approach here that fails for
that too.

Definition at line 66 of file templates.py.

00066 
00067     def get_tokens_unprocessed(self, text):
00068         """
00069         Since ERB doesn't allow "<%" and other tags inside of ruby
00070         blocks we have to use a split approach here that fails for
00071         that too.
00072         """
00073         tokens = self._block_re.split(text)
00074         tokens.reverse()
00075         state = idx = 0
00076         try:
00077             while True:
00078                 # text
00079                 if state == 0:
00080                     val = tokens.pop()
00081                     yield idx, Other, val
00082                     idx += len(val)
00083                     state = 1
00084                 # block starts
00085                 elif state == 1:
00086                     tag = tokens.pop()
00087                     # literals
00088                     if tag in ('<%%', '%%>'):
00089                         yield idx, Other, tag
00090                         idx += 3
00091                         state = 0
00092                     # comment
00093                     elif tag == '<%#':
00094                         yield idx, Comment.Preproc, tag
00095                         val = tokens.pop()
00096                         yield idx + 3, Comment, val
00097                         idx += 3 + len(val)
00098                         state = 2
00099                     # blocks or output
00100                     elif tag in ('<%', '<%=', '<%-'):
00101                         yield idx, Comment.Preproc, tag
00102                         idx += len(tag)
00103                         data = tokens.pop()
00104                         r_idx = 0
00105                         for r_idx, r_token, r_value in \
00106                             self.ruby_lexer.get_tokens_unprocessed(data):
00107                             yield r_idx + idx, r_token, r_value
00108                         idx += len(data)
00109                         state = 2
00110                     elif tag in ('%>', '-%>'):
00111                         yield idx, Error, tag
00112                         idx += len(tag)
00113                         state = 0
00114                     # % raw ruby statements
00115                     else:
00116                         yield idx, Comment.Preproc, tag[0]
00117                         r_idx = 0
00118                         for r_idx, r_token, r_value in \
00119                             self.ruby_lexer.get_tokens_unprocessed(tag[1:]):
00120                             yield idx + 1 + r_idx, r_token, r_value
00121                         idx += len(tag)
00122                         state = 0
00123                 # block ends
00124                 elif state == 2:
00125                     tag = tokens.pop()
00126                     if tag not in ('%>', '-%>'):
00127                         yield idx, Other, tag
00128                     else:
00129                         yield idx, Comment.Preproc, tag
00130                     idx += len(tag)
00131                     state = 0
00132         except IndexError:
00133             return

Here is the caller graph for this function:


Member Data Documentation

tuple MoinMoin.support.pygments.lexers.templates.ErbLexer._block_re = re.compile(r'(<%%|%%>|<%=|<%#|<%-|<%|-%>|%>|^%[^%].*?$)', re.M) [static, private]

Definition at line 59 of file templates.py.

Definition at line 56 of file templates.py.

list MoinMoin.support.pygments.lexers.templates.ErbLexer.mimetypes = ['application/x-ruby-templating'] [static]

Definition at line 57 of file templates.py.

Definition at line 55 of file templates.py.

Definition at line 63 of file templates.py.


The documentation for this class was generated from the following file: