Skip to content

Commit

Permalink
removed iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasChiroux committed Oct 15, 2012
1 parent 4544100 commit cbe4b32
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 77 deletions.
12 changes: 7 additions & 5 deletions src/attowiki/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,20 @@ def main():
app.route('/', method='GET')(serve_pages.view_page)
# new page
app.route('/', method='POST')(serve_pages.view_page)
# meta pages
app.route('/__index__')(serve_pages.view_meta_index)
app.route('/__todo__')(serve_pages.view_meta_todos)
app.route('/__cheatsheet__')(serve_pages.view_meta_cheat_sheet)

app.route('/__todo__.__iframe__', method='GET')(serve_pages.view_meta_todos)
app.route('/__cheatsheet__.__iframe__')(serve_pages.view_meta_cheat_sheet)

# new page
app.route('/edit/')(serve_pages.view_edit)
# edit an existing page
app.route('/edit/<name>')(serve_pages.view_edit)

# cancel the edition of an existing page
app.route('/cancel-edit/')(serve_pages.view_cancel_edit)
app.route('/cancel-edit/<name>')(serve_pages.view_cancel_edit)
# render an existing page using docutils
app.route('/<name>.__iframe__', method='GET')(serve_pages.view_iframe)

# view an existing page
app.route('/<name>', method='GET')(serve_pages.view_page)
# write new content to an existing page
Expand Down
82 changes: 33 additions & 49 deletions src/attowiki/serve_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import datetime

# dependencies imports
from bottle import request, response, template, abort
from bottle import request, response, template, abort, redirect
import docutils
from docutils.core import publish_string
from docutils.core import publish_string, publish_parts
from docutils.writers.html4css1 import Writer as HisWriter
from docutils import io, nodes
from git import Repo, InvalidGitRepositoryError
Expand Down Expand Up @@ -132,19 +132,19 @@ def view_meta_index():
view_meta_index is called by the 'meta' url : /__index__
"""
rst_files = [filename[2:-4] for filename in glob.glob("./*.rst")]
rst_files = [filename[2:-4] for filename in sorted(glob.glob("./*.rst"))]
rst_files.reverse()
return template('index', filelist=rst_files, name="__index__")
return template('index',
filelist=rst_files,
name="__index__",
is_repo=check_repo())


def view_meta_todos():
"""List all todos from all the rst files found in directory
view_meta_todos is called by the 'meta' url: /__todos__
"""
args = {'stylesheet_path':
attowiki_distro_path() + '/views/attowiki_docutils.css'}

doc2_content=""

doc2_output, doc2_pub = docutils.core.publish_programmatically(
Expand All @@ -157,15 +157,15 @@ def view_meta_todos():
parser=None, parser_name='restructuredtext',
writer=HisWriter(), writer_name=None,
settings=None, settings_spec=None,
settings_overrides=args,
settings_overrides=None,
config_section=None,
enable_exit_status=False)

section1 = nodes.section("todo_list_file")
doc2_pub.reader.document.append(section1)
title1 = nodes.title("TODO LIST", "TODO LIST")
doc2_pub.reader.document.append(title1)
rst_files = [filename[2:-4] for filename in glob.glob("./*.rst")]
rst_files = [filename[2:-4] for filename in sorted(glob.glob("./*.rst"))]
rst_files.reverse()
for file in rst_files:
file_title = False
Expand Down Expand Up @@ -215,8 +215,13 @@ def view_meta_todos():
doc2_pub.reader.document.append(node)
doc2_pub.apply_transforms()

result = doc2_pub.writer.write(doc2_pub.document, doc2_pub.destination)
return result
doc2_pub.writer.write(doc2_pub.document, doc2_pub.destination)
doc2_pub.writer.assemble_parts()
return template('page',
name='__todo__',
is_repo=check_repo(),
content=doc2_pub.writer.parts['html_body'])



def view_cancel_edit(name=None):
Expand All @@ -235,12 +240,12 @@ def view_cancel_edit(name=None):
bottle response object
"""
if name is None:
return view_page(None)
return redirect('/')
else:
files = glob.glob("{0}.rst".format(name))
if len(files) > 0:
reset_to_last_commit()
return view_page(name)
return redirect('/'+name)
else:
return abort(404)

Expand All @@ -264,7 +269,6 @@ def view_edit(name=None):
# new page
return template('edit',
name=name,
display_name=name,
is_repo=check_repo(),
today=datetime.datetime.now().strftime("%Y%m%d"),
content="")
Expand All @@ -274,7 +278,6 @@ def view_edit(name=None):
file_handle = open(files[0], 'r')
return template('edit',
name=name,
display_name=name,
is_repo=check_repo(),
today=datetime.datetime.now().strftime("%Y%m%d"),
content=file_handle.read())
Expand Down Expand Up @@ -330,10 +333,23 @@ def view_page(name=None):
if len(index_files) == 0:
# not found
# redirect to __index__
name = "__index__"
return view_meta_index()
else:
name = index_files[0][2:-4]
return template('page', name=name, display_name=name, is_repo=check_repo())

files = glob.glob("{0}.rst".format(name))
if len(files) > 0:
file_handle = open(files[0], 'r')
html_body = publish_parts(file_handle.read(),
writer=HisWriter(),
settings=None,
settings_overrides=None)['html_body']
return template('page',
name=name,
is_repo=check_repo(),
content=html_body)
else:
return abort(404)


def view_quick_save_page(name=None):
Expand Down Expand Up @@ -368,35 +384,3 @@ def view_quick_save_page(name=None):
return "OK"
else:
return abort(404)


def view_iframe(name):
"""serve the iframe : the html converted rst file
.. note:: this is a bottle view
Take a filename in argument (without .rst) and uses docutils to
render the rst file in html.
Keyword Arguments:
:name: (str) -- name of the file (MANDATORY)
"""

args = {'stylesheet_path':
attowiki_distro_path() + '/views/attowiki_docutils.css'}

response.set_header('Cache-control', 'no-cache')
response.set_header('Pragma', 'no-cache')
if name == '__index__':
# we should generate and index page
return view_meta_index()
else:
files = glob.glob("{0}.rst".format(name))
if len(files) > 0:
file_handle = open(files[0], 'r')
return publish_string(file_handle.read(),
writer=HisWriter(),
settings=None,
settings_overrides=args)
else:
return abort(404)
File renamed without changes.
16 changes: 8 additions & 8 deletions src/attowiki/views/edit.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%include header name=name
<body>
<body class="edit">
<script type="text/javascript">
function quickSave()
{
Expand All @@ -15,7 +15,7 @@
return;
}
%else:
httpRequest.open('PUT','/{{display_name}}',true);
httpRequest.open('PUT','/{{name}}',true);
%end
// change the color of 'save' button
addClass(document.getElementById("btn_save"), 'saving');
Expand Down Expand Up @@ -53,7 +53,7 @@
%if name is None:
[<a href="/__index__">i</a>]:<a href="/">attowiki</a>:
%else:
[<a href="/__index__">i</a>]:<a href="/">attowiki</a>:<a href="/{{display_name}}">{{display_name}}</a>
[<a href="/__index__">i</a>]:<a href="/">attowiki</a>:<a href="/{{name}}">{{name}}</a>
%end
</div>
%if not is_repo:
Expand All @@ -63,23 +63,23 @@
%if name is None:
<a href="/cancel-edit/" id="btn_cancel">cancel</a>
%else:
<a href="/cancel-edit/{{display_name}}" id="btn_cancel">cancel</a>
<a href="/cancel-edit/{{name}}" id="btn_cancel">cancel</a>
%end
<a href="#" id="btn_save" onclick="document.forms['page_edit'].submit();">save</a>
</div>
</div>
<div class="main_content">
<!--<div class="main_content">-->

%if name is None:
<form name="page_edit" method="post" action="/" class="main_content">
<form name="page_edit" method="post" action="/" class="edit_form">
filename: <input name="filename" size="20" value="{{today}}_"></input>
%else:
<form name="page_edit" method="post" action="/{{display_name}}" class="main_content">
<form name="page_edit" method="post" action="/{{name}}" class="edit_form">
%end
<textarea id="textcontent" name="content" cols="80" rows="40" class="textcontent">{{content}}</textarea>

</form>
</div>
<!--</div>-->

</body>
<script type="text/javascript">
Expand Down
27 changes: 20 additions & 7 deletions src/attowiki/views/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@
%else:
<title>{{name}}</title>
%end
<style type="text/css">
%include attowiki_docutils_css
</style>
<style type="text/css">
html {height:100%}
body {
margin:0;
height:100%;
overflow:hidden;
}
body.edit {
overflow: hidden;
}
.header {
width: 100%;
height: 20px;
font-family:monospace;
font-family: "Consolas", "Monaco", "Lucida Console", "Liberation Mono", "Deja Vu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace;
font-size: 12px;
border-bottom-style:solid;
border-width: 1px;
Expand Down Expand Up @@ -99,28 +105,35 @@
border:1px solid #777777;
}
.warning {
.header .warning {
position:absolute;
top:3px;
right:150px;
color:darkred;
font-weight:bold;
}
.main_content {
form.edit_form {
/*position: absolute;*/
top: 21px;
top: 0;
left: 0;
bottom: 0;
right:0;
width: 100%;
overflow: hidden;
height: 100%;
width: 100%;
}
#textcontent {
font-family: "Consolas", "Monaco", "Lucida Console", "Liberation Mono", "Deja Vu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace;
height:100%;
/*margin-right: 5px;*/
margin: 0;
padding: 0;
width:100%;
height:100%;
/*height:100%;
width:100%;*/
}
}
</style>
Expand Down
14 changes: 14 additions & 0 deletions src/attowiki/views/index.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
%include header name=name
<body>
<div class="header header_view">
<div class="text">
[<a href="/__index__">i</a>]:<a href="/">attowiki</a>:<a href="/{{name}}">{{name}}</a>
</div>
%if not is_repo:
<span class="warning">WARNING: no git repository found !!</span>
%end
<div class="buttons">
<a href="/edit/" id="btn_new">new page</a>
%if name != '__index__':
<a href="/edit/{{name}}" id="btn_edit">edit</a>
%end
</div>
</div>
Meta pages:
<ul>
<li><a target="_blank" href="__cheatsheet__">__cheatsheet__</a> (reST cheat sheet)</li>
Expand Down
10 changes: 2 additions & 8 deletions src/attowiki/views/page.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<body onload = "parent.htmlpage.location='/{{name}}.__iframe__'">
<div class="header header_view">
<div class="text">
[<a href="/__index__">i</a>]:<a href="/">attowiki</a>:<a href="/{{display_name}}">{{display_name}}</a>
[<a href="/__index__">i</a>]:<a href="/">attowiki</a>:<a href="/{{name}}">{{name}}</a>
</div>
%if not is_repo:
<span class="warning">WARNING: no git repository found !!</span>
Expand All @@ -14,12 +14,6 @@
%end
</div>
</div>

<iframe name="htmlpage" vspace="0" hspace="0"
style="margin:0;width:100%;height:100%;position: absolute;"
scrolling="auto" marginwidth="0"
marginheight="0" frameborder="0">
</iframe>

{{!content}}
</body>
</html>

0 comments on commit cbe4b32

Please sign in to comment.