Esempio n. 1
0
 def lookup_widget_action(self, path_info):
     try:
         widget_path, action = path_info.strip('/').split('/')
     except ValueError:
         widget_path, action = path_info, 'index'
     if widget_path:
         try:
             widget = util.import_widget(widget_path.strip('/'))
         except (ImportError, ValueError):
             widget = None
         if widget:
             return widget, action
     raise LookupError(path_info)
Esempio n. 2
0
 def lookup_widget_action(self, path_info):
     try:
         widget_path, action = path_info.strip('/').split('/')
     except ValueError:
         widget_path, action = path_info, 'index'
     if widget_path:
         try:
             widget = util.import_widget(widget_path.strip('/'))
         except (ImportError, ValueError):
             widget = None
         if widget:
             return widget, action
     raise LookupError(path_info)
Esempio n. 3
0
def widgetbrowser_directive(dirname, arguments, options, content, lineno,
                            content_offset, block_text, state, state_machine):
    """Processes the `widgetbrowser` reStructuredText directive.
    
    When generating the URL for the widget it peeks into os.environ for the
    'TW_BROWSER_PREFIX' environment variable.
    """
    widget_path = arguments[0]
    widget = util.import_widget(widget_path)
    if not widget:
        reporter = state.document.reporter
        msg = reporter.warning(
            'No widget found at %r' % widget_path, line=lineno)
        prb = nodes.problematic(block_text, block_text, msg)
        return [msg, prb]
    tabs = options.get('tabs') or widget_tabs.tabs
    prefix = os.environ.get('TW_BROWSER_PREFIX', '/apps/docs')
    size = options.get('size')
    html = widget_tabs(widget, tabs=tabs, prefix=prefix, size=size)
    node = nodes.raw('', html, format='html')
    return [node]