Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

book code improvements, thanks Niphlod

  • Loading branch information...
commit 1cada428779485d9d851ac0c06210802c4460196 1 parent f975166
@mdipierro authored
View
18 controllers/default.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import os, datetime
+from gluon.validators import urlify
session.forget()
TIME_EXPIRE = 60*60*24
@@ -18,6 +19,11 @@ def splitter(x):
a,b = x.split(':',1)
return a.strip(),b.strip()
+def splitter_urlify(x):
+ a,b = x.split(':',1)
+ return a.strip(),b.strip(), urlify(b)
+
+
@cache('folders',None)
def get_folders(dummy=None):
folder = os.path.join(request.folder,'sources')
@@ -44,7 +50,7 @@ def get_info(subfolder):
def get_chapters(subfolder):
filename = os.path.join(FOLDER,subfolder,'chapters.txt')
- chapters = [splitter(line)
+ chapters = [splitter_urlify(line)
for line in open(filename).readlines()
if ':' in line]
return chapters
@@ -98,6 +104,8 @@ def chapter():
subfolder = get_subfolder(book_id)
info = cache.ram('info_%s' % subfolder, lambda: get_info(subfolder), time_expire=TIME_EXPIRE)
chapters = cache.ram('chapters_%s' % subfolder, lambda: get_chapters(subfolder), time_expire=TIME_EXPIRE)
+ chapter_title = chapters[chapter_id][1]
+ response.title = '%s - %s' % (info['title'], chapter_title)
filename = os.path.join(FOLDER,subfolder,'%.2i.markmin' % chapter_id)
dest = os.path.join(request.folder, 'static_chaps', subfolder, '%.2i.html' % chapter_id)
if not FORCE_RENDER:
@@ -131,15 +139,15 @@ def search():
k = data.find(search)
if k>=0:
snippet = data[data.rfind('\n\n',0,k)+1:data.find('\n\n',k)].strip()
- results.append((chapter[0],chapter[1],convert2html(book_id,snippet)))
+ results.append((chapter[0],chapter[1],chapter[2],convert2html(book_id,snippet)))
content = CAT(*[DIV(H2(A(chapter[1],
_href=URL('chapter',
vars=dict(search=search),
- args=(book_id,chapter[0])))),
- chapter[2],BR(),
+ args=(book_id,chapter[0],chapter[2])))),
+ chapter[3],BR(),
A('more',_href=URL('chapter',
vars=dict(search=search),
- args=(book_id,chapter[0])),_class="btn"))
+ args=(book_id,chapter[0],chapter[2])),_class="btn"))
for chapter in results])
response.view = 'default/chapter.html'
return locals()
View
5 views/default/chapter.html
@@ -4,7 +4,6 @@
response.files.append(URL('static','js/jquery.scrollTo-min.js'))
response.files.append(URL('static','js/jquery.toc-0.1.js'))
response.files.append(URL('static','js/jquery.qtip-1.0.0-rc3.min.js'))
-response.title = info['title']
response.subtitle = SPAN(info['subtitle']," written by "+(info['authors'] and info['authors'] or 'unknown')+" in " + info['language'])
}}
{{extend 'layout.html'}}
@@ -49,8 +48,8 @@
<form action="{{=URL('search',args=book_id)}}"><input name="search" value="{{=request.vars.search or ''}}" onkeyup="jQuery('.article').unhighlight(); var v=jQuery(this).val(); if(v!='') jQuery('.article').highlight(v);"/><input type="submit" value="Search" style="padding: 0 5px"></form>
<h4>Table of Content</h4>
<ul>
-{{for key,item in chapters:}}
-{{=LI(A(item,_href=URL(args=(book_id,key))))}}
+{{for key,item,slug in chapters:}}
+{{=LI(A(item,_href=URL(args=(book_id,key,slug))))}}
{{pass}}
</ul>
{{end}}
View
54 views/layout.html
@@ -14,30 +14,30 @@
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge{{=not request.is_local and ',chrome=1' or ''}}">
<![endif]-->
-
+
<title>{{=response.title or request.application}}</title>
-
+
<!-- http://dev.w3.org/html5/markup/meta.name.html -->
<meta name="application-name" content="{{=request.application}}" />
-
+
<!-- Speaking of Google, don't forget to set your site up:
http://google.com/webmasters -->
<meta name="google-site-verification" content="" />
-
+
<!-- Mobile Viewport Fix
j.mp/mobileviewport & davidbcalhoun.com/2010/viewport-metatag
device-width: Occupy full width of the screen in its current orientation
initial-scale = 1.0 retains dimensions instead of zooming out if page height > device height
user-scalable = yes allows the user to zoom in -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-
+
<link rel="shortcut icon" href="{{=URL('static','images/favicon.ico')}}" type="image/x-icon">
<link rel="apple-touch-icon" href="{{=URL('static','images/favicon.png')}}">
-
- <!-- All JavaScript at the bottom, except for Modernizr which enables
+
+ <!-- All JavaScript at the bottom, except for Modernizr which enables
HTML5 elements & feature detects -->
- <script src="{{=URL('static','js/modernizr.custom.js')}}"></script>
-
+ <script src="{{=URL('static','js/modernizr.custom.js')}}"></script>
+
<!-- include stylesheets -->
{{
response.files.append(URL('static','css/bootstrap.min.css'))
@@ -47,7 +47,7 @@
}}
{{include 'web2py_ajax.html'}}
-
+
{{
# using sidebars need to know what sidebar you want to use
left_sidebar_enabled = globals().get('left_sidebar_enabled',False)
@@ -86,7 +86,7 @@
</div>
</div>
</div><!--/top navbar -->
-
+
<div class="container">
<div class="flash">{{=response.flash or ''}}</div>
@@ -94,14 +94,14 @@
<header class="mastheader" id="header">
<div class="page-header">
<h1>
- {{=response.title or request.application}}
+ web2py
</h1>
<h2>
<small>{{=response.subtitle or ''}}</small>
</h2>
</div>
</header>
-
+
<section id="main" class="main">
<div class="row">
{{if left_sidebar_enabled:}}
@@ -112,24 +112,24 @@
{{end}}
</div>
{{pass}}
-
+
<div class="{{=middle_columns}}">
{{block center}}
{{include}}
{{end}}
</div>
-
+
{{if right_sidebar_enabled:}}
<div class="span3">
{{block right_sidebar}}
<h3>Right Sidebar</h3>
<p></p>
{{end}}
- </div>
+ </div>
{{pass}}
</div><!--/row-->
</section><!--/main-->
-
+
<!-- Footer ================================================== -->
<footer class="footer">
{{block footer}} <!-- this is default footer -->
@@ -142,38 +142,38 @@
</div>
{{end}}
</footer>
-
+
</div> <!-- /container -->
-
+
<!-- The javascript =============================================
(Placed at the end of the document so the pages load faster) -->
<script>
// this code improves bootstrap menus and adds dropdown support
jQuery(function(){
- jQuery('.nav>li>a').each(function(){
+ jQuery('.nav>li>a').each(function(){
if(jQuery(this).parent().find('ul').length)
jQuery(this).attr({'class':'dropdown-toggle','data-toggle':'dropdown'}).append('<b class="caret"></b>');
});
- jQuery('.nav li li').each(function(){
+ jQuery('.nav li li').each(function(){
if(jQuery(this).find('ul').length)
- jQuery(this).children('a').contents().before('<i class="chevron-right"></i>');
+ jQuery(this).children('a').contents().before('<i class="chevron-right"></i>');
});
if(jQuery(document).width()>=980) {
jQuery('ul.nav li.dropdown').hover(function() {
- jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn();
+ jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn();
}, function() {
- jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut();
+ jQuery(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut();
});
}
jQuery('ul.nav li.dropdown a').click(function(){window.location=jQuery(this).attr('href');});
});
- </script>
- <script src="{{=URL('static','js/bootstrap.min.js')}}"></script>
+ </script>
+ <script src="{{=URL('static','js/bootstrap.min.js')}}"></script>
<!--[if lt IE 7 ]>
<script src="{{=URL('static','js/dd_belatedpng.js')}}"></script>
<script> DD_belatedPNG.fix('img, .png_bg'); //fix any <img> or .png_bg background-images </script>
<![endif]-->
{{if response.google_analytics_id:}}<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', '{{=response.google_analytics_id}}']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> {{pass}}
- <script src="{{=URL('static','js/share.js',vars=dict(static=URL('static','images')))}}"></script>
+ <script src="{{=URL('static','js/share.js',vars=dict(static=URL('static','images')))}}"></script>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.