To clarify, this is the end result that I want.  The following:

    .. asmfile:: cat

will get expanded into the equivalent of:


.. container:: sourceandoutput

   .. container:: source

      .. container:: header

         cat.nasm


      .. literalinclude:: /code/cat/clip.nasm

   .. container:: output

      .. container:: header

         .. container:: filename

            ./cat

         .. container:: arguments

            .. literalinclude:: /code/cat/args.txt
               :language: none

      .. literalinclude:: /code/cat/output.txt
         :language: none


Basically, I pass in an identifier for a directory which contains (1) source
code, and (2) the output from running it.  With appropriate CSS, I then get
a pretty side-by-side comparison.


Best


James

On Wed, Jul 28, 2010 at 5:13 PM, eegg <jameshfis...@gmail.com> wrote:

> I'm attempting to create a custom reST directive, which returns a tree
> of `containers`, two of which contain a `LiteralInclude` directive.
> Here's the code for my extension module:
>
>
> class AsmFileDirective(rst.Directive):
>  required_arguments = 1
>  optional_arguments = 0
>  has_content = False
>
>  def run(self):
>    reference = self.arguments[0]
>
>    sourceandoutput = nodes.container(classes=["sourceandoutput"])
>    source = nodes.container(classes=["source"])
>    source_header = nodes.container(classes=["header"])
>    source_header.append(nodes.Text(reference + ".nasm"))
>    source.append(source_header)
>    """source.append(LiteralInclude(
>        name = self.name,
>        arguments = ["code/" + reference + "/prog.nasm"],
>        options = self.options,
>        content = self.content,
>        lineno = self.lineno,
>        content_offset = self.content_offset,
>        block_text = self.block_text,
>        state = self.state,
>        state_machine = self.state_machine
>        ))"""
>
>    output = nodes.container(classes=["source"])
>    output_header = nodes.container(classes=["header"])
>    filename = nodes.container(classes=["filename"])
>    filename.append(nodes.Text("./" + reference))
>    output_header.append(filename)
>    output.append(output_header)
>
>    sourceandoutput.append(source)
>    sourceandoutput.append(output)
>    return [sourceandoutput]
>
> def setup(app):
>  app.add_directive("asmfile", AsmFileDirective)
>
>
> I have two (and possibly more) problems with this:
>
>
> (ERROR THE FIRST) When a `container` is written as html, I get the
> error:
>
> Exception occurred:
>  File "/usr/local/lib/python2.6/dist-packages/docutils-0.6-py2.6.egg/
> docutils/writers/html4css1/__init__.py", line 362, in starttag
>    classes.append(atts['class'])
> AttributeError: 'str' object has no attribute 'append'
>
> So for some reason, the array that I'm passing in is getting converted
> to a string .... ?  When I instead pass in a string, I get the same
> error, obviously.
>
>
> (ERROR THE SECOND) the arguments for instantiating a LiteralInclude
> are horrendous, and I can't even identify the problems I'm having with
> that.

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to sphinx-...@googlegroups.com.
To unsubscribe from this group, send email to 
sphinx-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en.

Reply via email to