ext/rest.py
changeset 10953 8b8193046600
parent 10952 4f28cb25b6c1
child 10957 2fdf67ef3341
equal deleted inserted replaced
10952:4f28cb25b6c1 10953:8b8193046600
    49 from logilab.mtconverter import ESC_UCAR_TABLE, ESC_CAR_TABLE, xml_escape
    49 from logilab.mtconverter import ESC_UCAR_TABLE, ESC_CAR_TABLE, xml_escape
    50 
    50 
    51 from cubicweb import UnknownEid
    51 from cubicweb import UnknownEid
    52 from cubicweb.ext.html4zope import Writer
    52 from cubicweb.ext.html4zope import Writer
    53 
    53 
    54 from cubicweb.web.views import vid_from_rset # XXX better not to import c.w.views here...
    54 from cubicweb.web.views import vid_from_rset  # XXX better not to import c.w.views here...
    55 
    55 
    56 # We provide our own parser as an attempt to get rid of
    56 # We provide our own parser as an attempt to get rid of
    57 # state machine reinstanciation
    57 # state machine reinstanciation
    58 
    58 
    59 import re
    59 import re
    67 mimetypes.add_type('text/rest', '.rest')
    67 mimetypes.add_type('text/rest', '.rest')
    68 mimetypes.add_type('text/rest', '.rst')
    68 mimetypes.add_type('text/rest', '.rst')
    69 
    69 
    70 
    70 
    71 LOGGER = getLogger('cubicweb.rest')
    71 LOGGER = getLogger('cubicweb.rest')
       
    72 
    72 
    73 
    73 def eid_reference_role(role, rawtext, text, lineno, inliner,
    74 def eid_reference_role(role, rawtext, text, lineno, inliner,
    74                        options={}, content=[]):
    75                        options={}, content=[]):
    75     try:
    76     try:
    76         try:
    77         try:
    97         ref = refedentity.absolute_url()
    98         ref = refedentity.absolute_url()
    98     set_classes(options)
    99     set_classes(options)
    99     return [nodes.reference(rawtext, utils.unescape(rest), refuri=ref,
   100     return [nodes.reference(rawtext, utils.unescape(rest), refuri=ref,
   100                             **options)], []
   101                             **options)], []
   101 
   102 
       
   103 
   102 def rql_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
   104 def rql_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
   103     """``:rql:`<rql-expr>``` or ``:rql:`<rql-expr>:<vid>```
   105     """``:rql:`<rql-expr>``` or ``:rql:`<rql-expr>:<vid>```
   104 
   106 
   105     Example: ``:rql:`Any X,Y WHERE X is CWUser, X login Y:table```
   107     Example: ``:rql:`Any X,Y WHERE X is CWUser, X login Y:table```
   106 
   108 
   130     except Exception as exc:
   132     except Exception as exc:
   131         content = 'an error occurred while interpreting this rql directive: %r' % exc
   133         content = 'an error occurred while interpreting this rql directive: %r' % exc
   132     set_classes(options)
   134     set_classes(options)
   133     return [nodes.raw('', content, format='html')], []
   135     return [nodes.raw('', content, format='html')], []
   134 
   136 
       
   137 
   135 def bookmark_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
   138 def bookmark_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
   136     """``:bookmark:`<bookmark-eid>``` or ``:bookmark:`<eid>:<vid>```
   139     """``:bookmark:`<bookmark-eid>``` or ``:bookmark:`<eid>:<vid>```
   137 
   140 
   138     Example: ``:bookmark:`1234:table```
   141     Example: ``:bookmark:`1234:table```
   139 
   142 
   186         content = view.render()
   189         content = view.render()
   187     except Exception, exc:
   190     except Exception, exc:
   188         content = 'An error occurred while interpreting directive bookmark: %r' % exc
   191         content = 'An error occurred while interpreting directive bookmark: %r' % exc
   189     set_classes(options)
   192     set_classes(options)
   190     return [nodes.raw('', content, format='html')], []
   193     return [nodes.raw('', content, format='html')], []
       
   194 
   191 
   195 
   192 def winclude_directive(name, arguments, options, content, lineno,
   196 def winclude_directive(name, arguments, options, content, lineno,
   193                        content_offset, block_text, state, state_machine):
   197                        content_offset, block_text, state, state_machine):
   194     """Include a reST file as part of the content of this reST file.
   198     """Include a reST file as part of the content of this reST file.
   195 
   199 
   251         return []
   255         return []
   252 
   256 
   253 winclude_directive.arguments = (1, 0, 1)
   257 winclude_directive.arguments = (1, 0, 1)
   254 winclude_directive.options = {'literal': directives.flag,
   258 winclude_directive.options = {'literal': directives.flag,
   255                               'encoding': directives.encoding}
   259                               'encoding': directives.encoding}
       
   260 
   256 
   261 
   257 class RQLTableDirective(Directive):
   262 class RQLTableDirective(Directive):
   258     """rql-table directive
   263     """rql-table directive
   259 
   264 
   260     Example:
   265     Example: