[BangPypers] Code Extractor in Python

Dhruv Baldawa dhruvbaldawa at gmail.com
Thu Jun 13 06:21:37 CEST 2013


I use something similar to this on my blog to parse rST.


from docutils.parsers.rst import Directive, directives


class ScriptBlock(Directive):
    """
    Usage:
    .. script:: <link_to_image>

    """
    required_arguments = 1
    optional_arguments = 2
    has_content = False
    CODE = '\
    <code class="javascript">{0}</code>\
    '

    def run(self):
        """ Required by the Directive interface. Create docutils nodes """
        # get the file path
        file_path = self.arguments[0]
        script_contents = open(file_path).read()
        return [nodes.raw('', self.CODE.format(
            script_contents,
        ), format='html')]

directives.register_directive('image-link', ImageLinkBlock)


--
Dhruv Baldawa
(http://www.dhruvb.com)


On Thu, Jun 13, 2013 at 8:57 AM, Gopalakrishnan Subramani <
gopalakrishnan.subramani at gmail.com> wrote:

> Just found that, Javascript has got toString() to display the function
> source code, that does portion of what is expected, I think, it is similar
> to Python inspect. I will update my findings here.
>
>
>
> On Wed, Jun 12, 2013 at 10:12 PM, Harish Vishwanath <
> harish.shastry at gmail.com> wrote:
>
> > I remember reading this blog about how pydanny wrote the book - two
> scoops
> > of django.
> > http://pydanny.com/tools-we-used-to-write-2scoops.html. May be you will
> > find some tools that they used to be helpful.
> >
> > Regards,
> > Harish
> >
> >
> > On Thu, Jun 13, 2013 at 8:24 AM, Noufal Ibrahim <noufal at nibrahim.net.in
> > >wrote:
> >
> > > Anand Chitipothu <anandology at gmail.com> writes:
> > >
> > >
> > > [...]
> > >
> > > > I think the best way to do it is by separating extracting code from
> > > > including code. You can write a script to preprocess the source files
> > and
> > > > extracts each function and writes into a different files. Once you
> have
> > > > solved that problem, then all you have to do just include one file in
> > > your
> > > > markdown.
> > >
> > > Dexy[1] allows you to do this. It's a little hairy to setup but quite
> > > flexible once you do so.
> > >
> > > [...]
> > >
> > >
> > > Footnotes:
> > > [1]  http://dexy.it/
> > >
> > > --
> > > Cordially,
> > > Noufal
> > > http://nibrahim.net.in
> > > _______________________________________________
> > > BangPypers mailing list
> > > BangPypers at python.org
> > > http://mail.python.org/mailman/listinfo/bangpypers
> > >
> > _______________________________________________
> > BangPypers mailing list
> > BangPypers at python.org
> > http://mail.python.org/mailman/listinfo/bangpypers
> >
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>


More information about the BangPypers mailing list