Skip to content

Commit

Permalink
more universal meta page: looks for any admonition now. Added also a …
Browse files Browse the repository at this point in the history
…meta suffix for any file which does the same for one file only
  • Loading branch information
ThomasChiroux committed Oct 15, 2012
1 parent 567af32 commit 107d225
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 15 deletions.
34 changes: 34 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
Version History
---------------

current
"""""""

* added __todo__ meta page which scan all the directory for todo directives
and display it in one page
* added more generic __xxxxxxxx__ meta page which scan all the directory
for the xxxxxxxx admnonition. This may work with any registered node,
especially admonitions:

* __todo__
* __done__
* __attention__
* __caution__
* __danger__
* __error__
* __hint__
* __important__
* __note__
* __tip__
* __warning__
* __admonition__

* added possibility to use the "admonition" meta pages for one page only
using this kind of url: /name of the doc.__admonition_name__

* added __cheatsheet__ meta page which provides locally a docutils reST
cheatsheet
* added 'done' directive, in order to work with todo: when a task is done,
edit the page and change 'todo' to 'done' (it will remove it from
__todo__ meta page)
* removed iframe
* improved docutils css
* some other refactors

v0.3
""""

Expand Down
5 changes: 4 additions & 1 deletion src/attowiki/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def main():
app.route('/', method='POST')(views.view_page)
# meta pages
app.route('/__index__')(views.view_meta_index)
app.route('/__todo__')(views.view_meta_todos)
app.route('/__cheatsheet__')(views.view_meta_cheat_sheet)
app.route('/__<admonition_name>__')(views.view_meta_admonition)

# new page
app.route('/edit/')(views.view_edit)
Expand All @@ -102,8 +102,11 @@ def main():
app.route('/cancel-edit/')(views.view_cancel_edit)
app.route('/cancel-edit/<name>')(views.view_cancel_edit)

# meta page for one single document
app.route('/<name>.__<admonition_name>__')(views.view_meta_admonition)
# view an existing page
app.route('/<name>', method='GET')(views.view_page)

# write new content to an existing page
app.route('/<name>', method='POST')(views.view_page)
# write new content to an existing page (without commit - for quick save)
Expand Down
58 changes: 48 additions & 10 deletions src/attowiki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


# project imports
from attowiki.rst_directives import todo
from attowiki.rst_directives import todo, done
from attowiki.git_tools import check_repo, commit, \
reset_to_last_commit, add_file_to_repo

Expand All @@ -61,11 +61,36 @@ def view_meta_index():
is_repo=check_repo())


def view_meta_todos():
"""List all todos from all the rst files found in directory
def view_meta_admonition(admonition_name, name=None):
"""List all found admonition from all the rst files found in directory
view_meta_todos is called by the 'meta' url: /__todos__
view_meta_admonition is called by the 'meta' url: /__XXXXXXX__
where XXXXXXX represents and admonition name, like:
* todo
* warning
* danger
* ...
.. note:: this function may works for any docutils node, not only
admonition
Keyword Arguments:
:admonition_name: (str) -- name of the admonition
"""
print "meta admo: %s - %s" % (admonition_name, name)
admonition = None

if admonition_name == 'todo':
admonition = todo
elif admonition_name == 'done':
admonition = done
elif hasattr(nodes, admonition_name):
admonition = getattr(nodes, admonition_name)
else:
return abort(404)

doc2_content=""

doc2_output, doc2_pub = docutils.core.publish_programmatically(
Expand All @@ -82,12 +107,17 @@ def view_meta_todos():
config_section=None,
enable_exit_status=False)

section1 = nodes.section("todo_list_file")
section1 = nodes.section("{0}_list_file".format(admonition_name))
doc2_pub.reader.document.append(section1)
title1 = nodes.title("TODO LIST", "TODO LIST")
title1 = nodes.title("{0} LIST".format(admonition_name.upper()),
"{0} LIST".format(admonition_name.upper()))
doc2_pub.reader.document.append(title1)
rst_files = [filename[2:-4] for filename in sorted(glob.glob("./*.rst"))]
rst_files.reverse()
if name is None:
rst_files = [filename[2:-4] for filename in sorted(glob.glob("./*.rst"))]
rst_files.reverse()
else:
rst_files = [filename[2:-4] for filename in
sorted(glob.glob("./{0}.rst".format(name)))]
for file in rst_files:
file_title = False
file_handle = open(file + '.rst', 'r')
Expand All @@ -112,7 +142,7 @@ def view_meta_todos():
parser = docutils.parsers.rst.Parser()
document = docutils.utils.new_document('test', my_settings)
parser.parse(file_content, document)
for node in document.traverse(todo): # docutils.nodes.note): # todo):
for node in document.traverse(admonition):
if not file_title:
file_title = True
# new section
Expand All @@ -138,8 +168,15 @@ def view_meta_todos():

doc2_pub.writer.write(doc2_pub.document, doc2_pub.destination)
doc2_pub.writer.assemble_parts()
if name is None:
display_file_name = '__{0}__'.format(admonition_name)
extended_name = None
else:
display_file_name = '{0}'.format(name)
extended_name = '__{0}__'.format(admonition_name)
return template('page',
name='__todo__',
name=display_file_name,
extended_name=extended_name,
is_repo=check_repo(),
content=doc2_pub.writer.parts['html_body'])

Expand Down Expand Up @@ -267,6 +304,7 @@ def view_page(name=None):
settings_overrides=None)['html_body']
return template('page',
name=name,
extended_name=None,
is_repo=check_repo(),
content=html_body)
else:
Expand Down
24 changes: 20 additions & 4 deletions src/attowiki/views/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
%end
</div>
</div>
Meta pages:
Main Meta pages:
<ul>
<li><a target="_blank" href="__cheatsheet__">__cheatsheet__</a> (reST cheat sheet)</li>
<li><a target="_parent" href="__index__">__index__</a> (this page)</li>
<li><a target="_parent" href="__todo__">__todo__</a> (list all todos for this directory)</li>
<li><a target="_parent" href="/__index__">__index__</a> (this page)</li>
<li><a target="_blank" href="/__cheatsheet__">__cheatsheet__</a> (reST cheat sheet)</li>
<li><a target="_parent" href="/__todo__">__todo__</a> (list all todo admonitions for this directory)</li>
<li><a target="_parent" href="/__done__">__done__</a> (list all done admonitions for this directory)</li>
</ul>

Pages:
Expand All @@ -27,5 +28,20 @@ Pages:
<li><a target="_parent" href="{{file}}">{{file}}</a></li>
%end
</ul>

Other Meta pages:
<ul>
<li><a target="_parent" href="/__attention__">__attention__</a></li>
<li><a target="_parent" href="/__caution__">__caution__</a></li>
<li><a target="_parent" href="/__danger__">__danger__</a></li>
<li><a target="_parent" href="/__error__">__error__</a></li>
<li><a target="_parent" href="/__hint__">__hint__</a></li>
<li><a target="_parent" href="/__important__">__important__</a></li>
<li><a target="_parent" href="/__note__">__note__</a></li>
<li><a target="_parent" href="/__tip__">__tip__</a></li>
<li><a target="_parent" href="/__warning__">__warning__</a></li>
<li><a target="_parent" href="/__admonition__">__admonition__</a></li>
</ul>

</body>
</html>
4 changes: 4 additions & 0 deletions src/attowiki/views/page.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<body onload = "parent.htmlpage.location='/{{name}}.__iframe__'">
<div class="header header_view">
<div class="text">
%if extended_name is None:
[<a href="/__index__">i</a>]:<a href="/">attowiki</a>:<a href="/{{name}}">{{name}}</a>
%else:
[<a href="/__index__">i</a>]:<a href="/">attowiki</a>:<a href="/{{name}}">{{name}}</a>:{{extended_name}}
%end
</div>
%if not is_repo:
<span class="warning">WARNING: no git repository found !!</span>
Expand Down

0 comments on commit 107d225

Please sign in to comment.