MezzoNZ / crunchy

Automatically exported from code.google.com/p/crunchy
0 stars 0 forks source link

Displaying python source files dynamically #94

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Currently, Crunchy requires the Python code (desired to be displayed in the
browser) to be embedded inside an html/rst file.  However, it should be
possible to specify a .py file to be inserted, either entirely or in parts,
inside a pre element.  Something like
<pre title="python_file relative_path/script.py crunchy_element">
or perhaps

<pre title="python_file relative_path/script.py linenumbers = [min, max]
crunchy_element">

or perhaps

<pre title="python_file relative_path/script.py function=function_name
crunchy_element">

where crunchy_element is an interpreter/editor/py_code.

This would ensure that Python code could always be up to date with the
tutorial/documentation it is referred in, while being easily tested/run
independently.

Original issue reported on code.google.com by andre.ro...@gmail.com on 29 Jan 2008 at 6:29

GoogleCodeExporter commented 8 years ago
An alternative notation, easier to parse (with ElementTree) and also more 
useful when
displaying the documentation without using Crunchy might be
<pre title="python_file crunchy_element">
<span title="python_file_name">path</span>
<span title="python_file_linenumbers">range</span>
<span title="python_file_function">function</span>
etc.
</pre>

Original comment by andre.ro...@gmail.com on 29 Jan 2008 at 6:36

GoogleCodeExporter commented 8 years ago
If you come up with the specification then I can add the necessary rst 
directives.

Original comment by crack...@gmail.com on 16 Feb 2008 at 10:47

GoogleCodeExporter commented 8 years ago
docutils already has the ability to include files (or parts of files) via the
"include" directive.
http://docutils.sourceforge.net/docs/ref/rst/directives.html#including-an-extern
al-document-fragment

It might be worthwhile exploring this.

As for the vlam specification, here's something to try to aim for:
<pre title="include file_name=path crunchy_element [class=class_name]
[function=function_name or list_of_functions] [method=method_name or 
list_of_methods]
[linenumbers=(start, finish) or a list of (start, finish) tuples]
[start_after=string] [end_before=string] ">

start_after and end_before are like the docutils include options.  It might be 
worth
including the encoding option as well.

crunchy_element is a standard crunchy option (interpreter, editor, doctest, 
.....)

Original comment by andre.ro...@gmail.com on 16 Feb 2008 at 5:32

GoogleCodeExporter commented 8 years ago
To implement this functionality in Crunchy (html....), one can make use of the
inspect module, in particular the getsource function.

Original comment by andre.ro...@gmail.com on 16 Feb 2008 at 5:42

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
A first part has been done with python styling.  The plugin name is getsource.py

Original comment by andre.ro...@gmail.com on 23 Aug 2009 at 9:20

GoogleCodeExporter commented 8 years ago
This is essentially done.  Options are to style the code, to embed an 
interpreter or
an editor.  It works with both rst and html files. (r1353 is the latest 
version).

Original comment by andre.ro...@gmail.com on 24 Aug 2009 at 12:08