From: Nick Fitzgerald resources/pycco.html
This module contains all of our static resources.
+ +import pycco_resources
Import our external dependencies.
resources/pycco.html
from pygments import lexers, formatters
from subprocess import Popen, PIPE
A list of the languages that Pycco supports, mapping the file extension to the name of the Pygments lexer and the symbol that indicates a comment. To @@ -219,30 +229,30 @@ add another language to Pycco's repertoire, add it here.
".lua": { "name": "lua", "symbol": "--" }, }Build out the appropriate matchers and delimiters for each language.
for ext, l in languages.items():
Does the line begin with a comment?
l["comment_matcher"] = re.compile(r"^\s*" + l["symbol"] + "\s?")
The dividing token we feed into Pygments, to delimit the boundaries between sections.
@@ -250,10 +260,10 @@ sections. l["divider_text"] = "\n" + l["symbol"] + "DIVIDER\n"
The mirror of divider_text that we expect Pygments to return. We can split
on this to recover the original sections.
l["divider_html"] = re.compile(r'\n*<span class="c[1]?">' + l["symbol"] + 'DIVIDER</span>\n*')
Get the Pygments Lexer for this language.
l["lexer"] = lexers.get_lexer_by_name(l["name"])
Get the current language we're documenting, based on the extension.
Compute the destination HTML path for an input source file path. If the source
is lib/example.py, the HTML will be at docs/example.html
lib/example.py, the HTML will be at docs/example.htmlname = filepath
return "docs/" + path.basename(name) + ".html"
Shift items off the front of the list until it is empty, then return
default.
lib/example.py, the HTML will be at docs/example.htmlexcept IndexError:
return default
Ensure that the destination directory exists.
lib/example.py, the HTML will be at docs/example.htmldef template(source):
return lambda context: pystache.render(source, context)
- Create the template that we will use to generate the Pycco HTML page.
pycco_template = template(open(path.join(path.dirname(__file__),
- "resources/pycco.html")).read())
pycco_template = template(pycco_resources.html)
The CSS styles we"d like to apply to the documentation.
pycco_styles = open(path.join(path.dirname(__file__),
- "resources/pycco.css")).read()
pycco_styles = pycco_resources.css
The start of each Pygments highlight block.
highlight_start = "<div class=\"highlight\"><pre>"
The end of each Pygments highlight block.
highlight_end = "</pre></div>"
Run the script. For each source file passed in as an argument, generate the documentation.