def tabbedPane(self, ctx, data): tab_names = [element[0] for element in data] return t.invisible[ t.div(class_='tabbedPane')[ t.ul(class_='tabs')[ [t.li(id_="tab-"+name.replace(' ', '_'))[name] for name in tab_names] ], [t.div(id_="page-"+name.replace(' ', '_'))[fragment] for name, fragment in data] ], t.inlineJS('setupTabbedPane(['+','.join([le.flt(le.js['tab-'+name.replace(' ', '_'),'page-'+name.replace(' ', '_')], quote=False) for name, junk in data])+']);') ]
def tabbedPane(self, ctx, data): tab_names = [element[0] for element in data] return t.invisible[t.div(class_='tabbedPane')[t.ul(class_='tabs')[[ t.li(id_="tab-" + name.replace(' ', '_'))[name] for name in tab_names ]], [ t.div(id_="page-" + name.replace(' ', '_'))[fragment] for name, fragment in data ]], t.inlineJS('setupTabbedPane([' + ','.join([ le.flt(le.js['tab-' + name.replace(' ', '_'), 'page-' + name.replace(' ', '_')], quote=False) for name, junk in data ]) + ']);')]
class tabbedPaneGlue: _css = util.resource_filename('nevow.taglibrary', "tabbedPane.css") _js = util.resource_filename('nevow', "js/Nevow/TagLibrary/TabbedPane.js") fileCSS = static.File(_css, 'text/css') fileJS = static.File(_js, 'text/javascript') fileGlue = (t.link(rel='stylesheet', type='text/css', href='/tabbedPane.css'), t.script(type='text/javascript', src='/tabbedPane.js')) inlineCSS = t.style(type_='text/css')[t.xml(file(_css).read())] inlineJS = t.inlineJS(file(_js).read()) inlineGlue = inlineJS, inlineCSS
class progressBarGlue: _css = util.resource_filename('nevow.taglibrary', "progressBar.css") _js = util.resource_filename('nevow.taglibrary', "progressBar.js") fileCSS = static.Data(_css, 'text/css') fileJS = static.Data(_js, 'text/javascript') fileGlue = ( t.link(rel='stylesheet', type_='text/css', href='/progressBar.css'), t.script(type_='text/javascript', src='/progressBar.js') ) inlineCSS = t.style(type_='text/css')[ t.xml(file(_css).read()) ] inlineJS = t.inlineJS(file(_js).read()) inlineGlue = inlineJS, inlineCSS
class tabbedPaneGlue: """ Record which holds information about the Javascript & CSS requirements of L{TabbedPane} and L{TabbedPaneFragment}. @type stylesheetPath: C{str} @ivar stylesheetPath: Filesystem path of the tabbed pane stylesheet. @type javascriptPath: C{str} @ivar javascriptPath: Filesystem path of the tabbed pane Javascript module. @type fileCSS: L{static.File} @ivar fileCSS: Resource which serves L{stylesheetPath}. @type fileJS: L{static.File} @ivar fileJS: Resource which serves L{javascriptPath}. @type fileGlue: Stan @ivar fileGlue: Stan which, when placed in the <head> of an HTML document, will include the required CSS & Javascript. @type inlineCSS: L{t.style} @ivar inlineCSS: <style> tag containing the tabbedpane CSS inline. @type inlineJS: L{t.script} @ivar inlineJS: <script> tag containing the tabbedpane Javascript inline. @type inlineGlue: Stan @ivar inlineGlue: A tuple of L{inlineCSS} and L{inlineJS}. """ stylesheetPath = util.resource_filename('nevow', 'css/Nevow/TagLibrary/TabbedPane.css') javascriptPath = util.resource_filename('nevow', 'js/Nevow/TagLibrary/TabbedPane.js') fileCSS = static.File(stylesheetPath, 'text/css') fileJS = static.File(javascriptPath, 'text/javascript') fileGlue = ( t.link(rel='stylesheet', type='text/css', href='/tabbedPane.css'), t.script(type='text/javascript', src='/tabbedPane.js') ) inlineCSS = t.style(type_='text/css')[ t.xml(file(stylesheetPath).read()) ] inlineJS = t.inlineJS(file(javascriptPath).read()) inlineGlue = inlineJS, inlineCSS
def tabbedPane(self, ctx, data): tab_names = [element[0] for element in data] return t.invisible[ t.div(class_="tabbedPane")[ t.ul(class_="tabs")[[t.li(id_="tab-" + name.replace(" ", "_"))[name] for name in tab_names]], [t.div(id_="page-" + name.replace(" ", "_"))[fragment] for name, fragment in data], ], t.inlineJS( "setupTabbedPane([" + ",".join( [ le.flt(le.js["tab-" + name.replace(" ", "_"), "page-" + name.replace(" ", "_")], quote=False) for name, junk in data ] ) + "]);" ), ]
def test_inlineJS(self): # there is a tendency for people to change inlineJS to something like this: # # return script(type="text/javascript")[xml('\n//<![CDATA[\n'), s, xml(\n//]]>\n'] # # however, this is broken because it replaces & < and > with entities, # which is wrong. If the CDATA thingers are omitted, then it is correct # by the XML spec, but not in reality, because browsers do not resolve # entities in script tags for historic reasons, and the content of # script tags is defined to be CDATA by XHTML, even without CDATA # directives. # # Anyway, the end result is that & becomes & resulting in a syntax # error. ctx = context.WovenContext() tag = tags.inlineJS('correct && elegant;') flatted = flat.flatten(tag, ctx) self.failIf('&' in flatted)
def test_inlineJS(self): # there is a tendency for people to change inlineJS to something like this: # # return script(type="text/javascript")[xml('\n//<![CDATA[\n'), s, xml(\n//]]>\n'] # # however, this is broken because it replaces & < and > with entities, # which is wrong. If the CDATA thingers are omitted, then it is correct # by the XML spec, but not in reality, because browsers do not resolve # entities in script tags for historic reasons, and the content of # script tags is defined to be CDATA by XHTML, even without CDATA # directives. # # Anyway, the end result is that & becomes & resulting in a syntax # error. ctx = context.WovenContext() tag = tags.inlineJS("correct && elegant;") flatted = flat.flatten(tag, ctx) self.failIf("&" in flatted)
def tabbedPane(self, ctx, data): name = data.get('name', 'theTabbedPane') pages = data.get('pages') selected = data.get('selected', 0) def _(): for n, (tab, page) in enumerate(pages): tID = '%s_tab_%i' % (name, n) pID = '%s_page_%i' % (name, n) yield (t.li(class_='nevow-tabbedpane-tab', id_=tID)[tab], t.div(class_='nevow-tabbedpane-pane', id_=pID)[page], flt(js[tID, pID], quote=False)) tabs, pages, j = zip(*_()) if selected >= len(tabs): selected = 0 return t.invisible[t.div(class_='nevow-tabbedpane', id_=name)[t.ul( class_='nevow-tabbedpane-tabs')[tabs], pages], t.inlineJS('setupTabbedPane([' + ','.join(j) + '], %i);' % selected)]
def render_glue(self, ctx, data): "All in one glue!" stans = [] stans.append(T.script(src="liveevil", language="javascript")) stans.append(T.script(src="js/codehack.js", langauge="javascript")) js = """ function onLoad(){ var isrunning = %(isrunning)s; if (isrunning){ time_start(%(age)s, %(duration)s); }else{ time_stop(); } } """ age = None if self.mind.isrunning: age = self.mind.avatar.contest.getContestAge() info_dict = {"isrunning": self.mind.isrunning and "true" or "false", "age": age, "duration": self.mind.duration} stans.append(T.inlineJS(js % info_dict)) return stans
def tabbedPane(self, ctx, data): name = data.get('name', 'theTabbedPane') pages = data.get('pages') selected = data.get('selected', 0) def _(): for n, (tab, page) in enumerate(pages): tID = '%s_tab_%i'%(name, n) pID = '%s_page_%i'%(name, n) yield (t.li(class_='nevow-tabbedpane-tab', id_=tID)[tab], t.div(class_='nevow-tabbedpane-pane', id_=pID)[page], flt(js[tID,pID], quote = False)) tabs, pages, j = zip(*_()) if selected >= len(tabs): selected = 0 return t.invisible[ t.div(class_='nevow-tabbedpane',id_=name)[ t.ul(class_='nevow-tabbedpane-tabs')[tabs], pages ], t.inlineJS('setupTabbedPane([' + ','.join(j) + '], %i);'%selected) ]
from nevow import tags as t, static, livepage as le def _locateFile(filename): import os.path dirname = os.path.abspath(os.path.dirname(__file__)) return os.path.join(dirname, filename) _tp_style_fn = _locateFile("tabbedPane-style.css") _tp_layout_fn = _locateFile("tabbedPane-layout.css") _tp_JS = _locateFile("tabbedPane.js") tabbedPaneStyle = t.style(type_='text/css')[open(_tp_style_fn).read()] tabbedPaneLayout = t.style(type_='text/css')[open(_tp_layout_fn).read()] tabbedPaneJS = t.inlineJS(open(_tp_JS).read()) tabbedPaneHeadInline = t.invisible[tabbedPaneStyle, tabbedPaneLayout, tabbedPaneJS, ] tabbedPaneStyleFile = static.File(_tp_style_fn, 'text/css') tabbedPaneLayoutFile = static.File(_tp_layout_fn, 'text/css') tabbedPaneJSFile = static.File(_tp_JS, 'text/javascript') tabbedPaneHeadFiles = t.invisible[ t.link(rel='stylesheet', type='text/css', href='/tabbedPane-style.css'), t.link(rel='stylesheet', type='text/css', href='/tabbedPane-layout.css'), t.script(type='text/javascript', src='/tabbedPane.js'), ] class TabbedPane(object):
import os.path dirname = os.path.abspath(os.path.dirname(__file__)) return os.path.join(dirname, filename) _tp_style_fn = _locateFile("tabbedPane-style.css") _tp_layout_fn = _locateFile("tabbedPane-layout.css") _tp_JS = _locateFile("tabbedPane.js") tabbedPaneStyle = t.style(type_='text/css')[ open(_tp_style_fn).read() ] tabbedPaneLayout = t.style(type_='text/css')[ open(_tp_layout_fn).read() ] tabbedPaneJS = t.inlineJS( open(_tp_JS).read() ) tabbedPaneHeadInline = t.invisible[ tabbedPaneStyle, tabbedPaneLayout, tabbedPaneJS, ] tabbedPaneStyleFile = static.File(_tp_style_fn, 'text/css') tabbedPaneLayoutFile = static.File(_tp_layout_fn, 'text/css') tabbedPaneJSFile = static.File(_tp_JS, 'text/javascript') tabbedPaneHeadFiles = t.invisible[ t.link(rel='stylesheet', type='text/css', href='/tabbedPane-style.css'), t.link(rel='stylesheet', type='text/css', href='/tabbedPane-layout.css'),
} node.style['width'] = val+'%'; } """ _progress_css = """ .progressbar { width: 50%; height: 15px; border-style: solid; border-width: 1px; } .progressbar div { height: 15px; background-color: #aaaaaa; } """ progressGlueJS = static.File(_progress_glue, 'text/javascript') progressGlue = t.inlineJS(_progress_glue) progressCSSFile = static.File(_progress_css, 'text/css') progressCSS = t.style(type_='text/css')[_progress_css] class ProgressBarComponent(object): def progressBar(self, ctx, data): name = data.get('name', 'progressbar') start_perc = data.get('start', 0) bar = t.div(id_=str(name), class_="progressbar") meter = t.div(id_="%s_meter" % str(name)) return bar[meter(style="width:%s%%" % (start_perc))] progressBar = ProgressBarComponent().progressBar __all__ = ["progressGlueJS", "progressGlue", "progressBar", "progressCSS", "progressCSSFile"]
"""Calculate and return the full path to the liveevil glue JavaScript. """ import os.path dirname = os.path.abspath(os.path.dirname(__file__)) return os.path.join(dirname, "liveevil.js") try: _glueJS = _locateGlueJS() # A static.File resource that can be used from a <link> glueJS = static.File(_glueJS, "text/javascript") # Inline JavaScript glue. TODO: deprecate this. glue = tags.inlineJS(open(_glueJS).read()) # Glue which tells livepage to only allow clientToServer events, not async serverToClient events inputOnlyGlue = tags.inlineJS( "var auto_open = false; var liveevil_unload = true;\n" + "".join(open(_glueJS).readlines()[1:]) ) except EnvironmentError: glueJS = inputOnlyGlue = glue = None warnings.warn("Could not open liveevil.js") ctsTemplate = "nevow_clientToServerEvent('%s',this%s);%s" handledEventPostlude = " return false;" class strWithCallit(str):
def _locateGlueJS(): """Calculate and return the full path to the liveevil glue JavaScript. """ import os.path dirname = os.path.abspath(os.path.dirname(__file__)) return os.path.join(dirname, 'liveevil.js') try: _glueJS = _locateGlueJS() # A static.File resource that can be used from a <link> glueJS = static.File(_glueJS, 'text/javascript') # Inline JavaScript glue. TODO: deprecate this. glue = tags.inlineJS(open(_glueJS).read()) # Glue which tells livepage to only allow clientToServer events, not async serverToClient events inputOnlyGlue = tags.inlineJS( "var auto_open = false; var liveevil_unload = true;\n" + ''.join(open(_glueJS).readlines()[1:])) except EnvironmentError: glueJS = inputOnlyGlue = glue = None warnings.warn("Could not open liveevil.js") ctsTemplate = "nevow_clientToServerEvent('%s',this%s);%s" handledEventPostlude = ' return false;' class strWithCallit(str): pass
""" _progress_css = """ .progressbar { width: 50%; height: 15px; border-style: solid; border-width: 1px; } .progressbar div { height: 15px; background-color: #aaaaaa; } """ progressGlueJS = static.File(_progress_glue, 'text/javascript') progressGlue = t.inlineJS(_progress_glue) progressCSSFile = static.File(_progress_css, 'text/css') progressCSS = t.style(type_='text/css')[_progress_css] class ProgressBarComponent(object): def progressBar(self, ctx, data): name = data.get('name', 'progressbar') start_perc = data.get('start', 0) bar = t.div(id_=str(name), class_="progressbar") meter = t.div(id_="%s_meter" % str(name)) return bar[meter(style="width:%s%%" % (start_perc))] progressBar = ProgressBarComponent().progressBar