Source

yummy / src / yummy / spx.py

# -*- coding: utf-8 -*-
#"""
#    yummy.spx
#    ~~~~~~~~~~~~~~~
#
#    A Sphinx extension to render Delicious links  in ".. yummy-list::" directive.
#"""
#
from docutils import nodes

from sphinx.locale import _
from sphinx.environment import NoUri
from sphinx.util.nodes import set_source_info
from sphinx.util.compat import Directive, make_admonition

#:Node class
class yummylist(nodes.General, nodes.Element): pass

#:Directive class
class YummyList(Directive):
    """
    A list of URL bookmarks
    """
    def run(self):
        return [yummylist('')]


#: Sphinx Evennt Handlers
def on_doctree_resolved(app, doctree, fromdocname):

    #: configuration check
#    if not app.config['yummy_enable']:
#        for node in doctree.traverse(todo_node):
#            node.parent.remove(node)

    for node in doctree.traverse(yummylist):
#        content = [nodes.literal_block('hoge','hoge',)]
#        content = [
#            nodes.literal('xxxxxxxx'),
#            nodes.bullet_list('', classes=['yummy-list'])
#        ]
#        content[0].append( nodes.list_item('xxxx',classes=['yummy-item']) )
#

#        blist = nodes.bullet_list()
#        for i in range(1, 6):
#            item = nodes.list_item()
#            for j in range(1, 4):
#                item += nodes.paragraph('', 'Item %s, paragraph %s.' % (i, j))
#            blist += item
        content = [
            nodes.raw('','<h2>Links</h2>',format='html',),
            nodes.raw('','<ul>',format='html',),
            nodes.raw('','<li><a href="http://google.com">Google.com</a></li>',format='html',),
            nodes.raw('','<li><a href="http://amazon.com">Amazon.com</a></li>',format='html',),
            nodes.raw('','</ul>',format='html',),
        ]
        node.replace_self(content)

#
def setup(app):
#    app.add_config_value('todo_include_todos', False, False)

    #: config.py : configuraton 
    app.add_config_value(
        'yummy_enable',         #: Name
        False,                  #: Default value is "False"
        False)                  #: Rebuild (?) ['env','html','',]

    #: Node
    app.add_node(yummylist)

    #: Directives
    app.add_directive('yummy_list', YummyList)

    #: Event Handler
    app.connect('doctree-resolved', on_doctree_resolved )