It's been a month. I stepped away for a month to avoid trichotillomania. I'm actually working on a completely different project, not related to coding, but one where I feel Restructured Text and Sphinx could be useful.
If I can get these to work. I have a bunch of roles and directives I would like to use in my text, and create index pages with back references. It's a discussion and analysis of short stories, so I'd like to write one story per page, and use directives like .. writer:: Josh English .. magazine:: Aoife's Kiss .. issue:: 24 .. pov:: Third person .. tense:: past and so on. I would like to have a page where I can create a WriterList, and list all the writers in alphabetical order (with backlinks to the stories), and do the same with magazines (with back links), and so on. I followed the tutorial at http://sphinx-doc.org/ext/tutorial.html. I ignored the configuration file options. I get the error File "c:\Users\Josh\Desktop\storyaday\extensions\writernode.py", line 62, in process_writer_nodes for writer_info in env.writer_all_writers: AttributeError: BuildEnvironment instance has no attribute 'writer_all_writers' I've attached the extension, and the error log. I swear I have crossed checked every character from the tutorial, and the only changes are using "writer" instead of "todo" (minus the configuration variable). Can someone please take a look at this and tell me what I'm doing wrong? Josh -- You received this message because you are subscribed to the Google Groups "sphinx-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sphinx-users. For more options, visit https://groups.google.com/groups/opt_out.
#!/usr/bin/env python
from docutils import nodes
from sphinx.util.compat import Directive, make_admonition
class writer(nodes.Admonition, nodes.Element):
pass
class writerlist(nodes.General, nodes.Element):
pass
def visit_writer_node(self, node):
self.visit_admonition(node)
def depart_writer_node(self, node):
self.depart_admonition(node)
class writerlistDirective(Directive):
def run(self):
return [writerlist('')]
class writerDirective(Directive):
has_content = True
def run(self):
env = self.state.document.settings.env
targetid = "writer-%d" % env.new_serialno('writer')
targetnode = nodes.target('', '', ids=[targetid])
ad = make_admonition(writer, self.name, ['writer'], self.options,
self.content, self.lineno, self.content_offset,
self.block_text, self.state, self.state_machine)
if not hasattr(env, 'writer_all_writers'):
env.writer_all_writers = []
env.writer_all_writers.append({
'docmane': env.docname,
'lineno': self.lineno,
'writer': ad[0].deepcopy(),
'target': targetnode})
return [targetnode] + ad
def purge_writers(app, env, docmane):
if not hasattr(env, 'writer_all_writers'):
return
env.writer_all_writers = [writer for writer in env.writer_all_writers
if writer['docname'] != docname]
def process_writer_nodes(app, doctree, fromdocname):
env = app.builder.env
for node in doctree.traverse(writerlist):
content = []
for writer_info in env.writer_all_writers:
para = node.paragraph()
filename = env.doc2path(writer_info['docname'], base=None)
description = (
('(The original entry is located in %s, line %d and can be found' %
(filename, writer_info['lineno'])))
para += nodes.Text(description, description)
#create a reference
newnode = nodes.reference('', '')
innernode = nodes.emphasis('here', 'here')
newnode['refdocname'] = writer_info['docname']
newnode['refuri'] = app.builder.get_relative_uri(
fromdocname, writer_info['docname'])
newnode['refuri'] += "#" + writer_info['target']['refid']
newnode.append(innernode)
para += newnode
para += nodes.Text('.)', '.)')
# insert the writerlist
content.append(writer_info['writer'])
content.append(para)
node.replace_self(content)
def setup(app):
app.add_node(writerlist)
app.add_node(writer,
html=(visit_writer_node, depart_writer_node),
text=(visit_writer_node, depart_writer_node))
app.add_directive('writer', writerDirective)
app.add_directive('writerlist', writerlistDirective)
app.connect('doctree-resolved', process_writer_nodes)
app.connect('env-purge-doc', purge_writers)
sphinx-err-eycwkf.log
Description: Binary data
