On Wed, Jun 24, 2009 at 5:06 PM, Chris Withers<ch...@simplistix.co.uk> wrote:
> One thing you may have solved already, but if not would make a fantastic
> addition is a plugin that writes matching sections to a file.
>
> So, rather than having the following in a doctest:
>
>>>> f = open(os.path.join('mytempdir','myfile.zcml'),'w')
>>>> f.write('''
>>>> <configure xmlns="http://namespaces.zope.org/zope";>
>>>> blah blah blah
>>>> </configure>
>>>> '''.strip())
>>>> f.close()
>>>> zope.configuration.xmlconfig.file(join('mytempdir','myfile.zxml'))
>
> I could have:
>
> .. file:: myfile.zcml
>
> <configure xmlns="http://namespaces.zope.org/zope";>
> blah blah blah
> </configure>

There's no super-nice way to do exactly that, but here's a pretty
reasonable version:

--- begin quote ---

Contents of myfile.zcml::

    <configure xmlns="http://namespaces.zope.org/zope";>
    blah blah blah
    </configure>

.. -> config

    >>> import tmpfile
    >>> f = tmpfile.mkstemp()
    >>> f.write(config)
    >>> f.close()
    >>> zope.configuration.xmlconfig.string(config)

--- end quote ---

Or, a much nicer version that doesn't use a temporary file (note the
change from .file to .string) in the code:

--- begin quote ---

Contents of myfile.zcml::

    <configure xmlns="http://namespaces.zope.org/zope";>
    blah blah blah
    </configure>

.. -> config

    >>> zope.configuration.xmlconfig.string(config)

--- end quote ---

> ...with bonus points for telling me how to get this to render nicely with
> Sphinx into a box with the file contents in it and a caption of the file
> name :-)

The contents will be in a box, but the file name would be up to you to
describe in prose (as shown).

I could imagine a plug-in that understood the Sphinx
"..  literalinclude:: example.file" directive and made the included
lines available in a variable.  That might be handy when you *really*
want to keep a file on-disk but still include part or all of it in a
document.
-- 
Benji York
Senior Software Engineer
Zope Corporation
_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to