gluon.tools.Expose
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 1.99.4 (2012-02-19 22:47:06) stable
|
Version 1.99.4 (2012-02-21 00:06:19) stable
|
||||||
|
|||||||
@@ -4,6 +4,22 @@
|
|||||||
import re
|
import re
|
||||||
import cgi
|
import cgi
|
||||||
|
|
||||||
|
"""
|
||||||
|
TODO: next version should use MathJax
|
||||||
|
|
||||||
|
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js">
|
||||||
|
MathJax.Hub.Config({
|
||||||
|
extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js"],
|
||||||
|
jax: ["input/TeX", "output/HTML-CSS"],
|
||||||
|
tex2jax: {
|
||||||
|
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
|
||||||
|
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
|
||||||
|
},
|
||||||
|
"HTML-CSS": { availableFonts: ["TeX"] }
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
"""
|
||||||
|
|
||||||
__all__ = ['render', 'markmin2html']
|
__all__ = ['render', 'markmin2html']
|
||||||
|
|
||||||
__doc__ = """
|
__doc__ = """
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import datetime
|
|||||||
import thread
|
import thread
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
@@ -4146,6 +4147,54 @@ class PluginManager(object):
|
|||||||
def __contains__(self,key):
|
def __contains__(self,key):
|
||||||
return key in self.__dict__
|
return key in self.__dict__
|
||||||
|
|
||||||
|
class Expose(object):
|
||||||
|
def __init__(self,base=None):
|
||||||
|
current.session.forget()
|
||||||
|
base = base or os.path.join(current.request.folder,'static','work')
|
||||||
|
filename = os.path.join(base,'/'.join(current.request.args))
|
||||||
|
if not os.path.isdir(filename):
|
||||||
|
current.response.headers['Content-Type'] = contenttype(filename)
|
||||||
|
raise HTTP(200,open(filename,'rb'),**current.response.headers)
|
||||||
|
self.path = path = os.path.join(filename,'*')
|
||||||
|
self.folders = [f[len(path)-1:] for f in sorted(glob.glob(path)) \
|
||||||
|
if os.path.isdir(f) and not self.isprivate(f)]
|
||||||
|
self.filenames = [f[len(path)-1:] for f in sorted(glob.glob(path)) \
|
||||||
|
if not os.path.isdir(f) and not self.isprivate(f)]
|
||||||
|
def breadcrumbs(self):
|
||||||
|
path = []
|
||||||
|
span = SPAN()
|
||||||
|
span.append(A('base',_href=URL()))
|
||||||
|
span.append('/')
|
||||||
|
args = current.request.args
|
||||||
|
for arg in args:
|
||||||
|
path.append(arg)
|
||||||
|
span.append(A(arg,_href=URL(args='/'.join(path))))
|
||||||
|
span.append('/')
|
||||||
|
return span
|
||||||
|
def table_folders(self):
|
||||||
|
args = current.request.args
|
||||||
|
return TABLE(*[TR(TD(A(folder,_href=URL(args=args+[folder])))) \
|
||||||
|
for folder in self.folders])
|
||||||
|
@staticmethod
|
||||||
|
def isprivate(f):
|
||||||
|
return 'private' in f or f.startswith('.') or f.endswith('~')
|
||||||
|
@staticmethod
|
||||||
|
def isimage(f):
|
||||||
|
return f.rsplit('.')[-1].lower() in ('png','jpg','jpeg','gif','tiff')
|
||||||
|
def table_files(self,width=160):
|
||||||
|
args = current.request.args
|
||||||
|
return TABLE(*[TR(TD(A(f,_href=URL(args=args+[f]))),
|
||||||
|
TD(IMG(_src=URL(args=args+[f]),_style='max-width:%spx' % width) \
|
||||||
|
if width and self.isimage(f) else '')) \
|
||||||
|
for f in self.filenames])
|
||||||
|
def xml(self):
|
||||||
|
return DIV(
|
||||||
|
H2(self.breadcrumbs()),
|
||||||
|
H3('Folders'),
|
||||||
|
self.table_folders(),
|
||||||
|
H3('Files'),
|
||||||
|
self.table_files()).xml()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
|||||||
Reference in New Issue
Block a user