/hveto.js`
- the paths of the two files written by this method, which will be
- `hveto.css` and `hveto.js` inside `static`
-
- Notes
- -----
- This method modifies the module-level variables ``CSS_FILES` and
- ``JS_FILES`` to guarantee that the static files are actually only
- written once per process.
- """
- if not os.path.isdir(static):
- os.makedirs(static)
- hvetocss = os.path.join(static, 'hveto.css')
- if hvetocss not in CSS_FILES:
- with open(hvetocss, 'w') as f:
- f.write(HVETO_CSS)
- CSS_FILES.append(hvetocss)
- hvetojs = os.path.join(static, 'hveto.js')
- if hvetojs not in JS_FILES:
- with open(hvetojs, 'w') as f:
- f.write(HVETO_JS)
- JS_FILES.append(hvetojs)
- return hvetocss, hvetojs
-
-
-def init_page(ifo, start, end, css=[], script=[], base=os.path.curdir,
- **kwargs):
- """Initialise a new `markup.page`
-
- This method constructs an HTML page with the following structure
-
- .. code-block:: html
-
-
-
-
-
-
-
-
-
-
+def banner(ifo, start, end):
+ """Initialise a new markup banner
Parameters
----------
@@ -160,50 +47,14 @@ def init_page(ifo, start, end, css=[], script=[], base=os.path.curdir,
the GPS start time of the analysis
end : `int`
the GPS end time of the analysis
- css : `list`, optional
- the list of stylesheets to link in the ``
- script : `list`, optional
- the list of javascript files to link in the ``
- base : `str`, optional, default '.'
- the path for the `` tag to link in the ``
Returns
-------
page : `markup.page`
the structured markup to open an HTML document
"""
- # write CSS to static dir
- staticdir = os.path.join(os.path.curdir, 'static')
- write_static_files(staticdir)
# create page
page = markup.page()
- page.header.append('')
- page.html(lang='en')
- page.head()
- page.base(href=base)
- page._full = True
- # link stylesheets (appending bootstrap if needed)
- css = css[:]
- for cssf in CSS_FILES[::-1]:
- b = os.path.basename(cssf)
- if not any(f.endswith(b) for f in css):
- css.insert(0, cssf)
- for f in css:
- page.link(href=f, rel='stylesheet', type='text/css', media='all')
- # link javascript
- script = script[:]
- for jsf in JS_FILES[::-1]:
- b = os.path.basename(jsf)
- if not any(f.endswith(b) for f in script):
- script.insert(0, jsf)
- for f in script:
- page.script('', src=f, type='text/javascript')
- # add other attributes
- for key in kwargs:
- getattr(page, key)(kwargs[key])
- # finalize header
- page.head.close()
- page.body()
# write banner
page.div(class_='container')
page.div(class_='page-header', role='banner')
@@ -211,47 +62,7 @@ def init_page(ifo, start, end, css=[], script=[], base=os.path.curdir,
page.h3("%d-%d" % (start, end))
page.div.close()
page.div.close() # container
-
- # open container
- page.div(class_='container')
- return page
-
-
-def close_page(page, target, about=None, date=None):
- """Close an HTML document with markup then write to disk
-
- This method writes the closing markup to complement the opening
- written by `init_page`, something like:
-
- .. code-block:: html
-
-
-
-
-
-
- Parameters
- ----------
- page : `markup.page`
- the markup object to close
- target : `str`
- the output filename for HTML
- about : `str`, optional
- the path of the 'about' page to link in the footer
- date : `datetime.datetime`, optional
- the timestamp to place in the footer, defaults to
- `~datetime.datetime.now`
- """
- page.div.close() # container
- page.add(str(write_footer(about=about, date=date)))
- if not page._full:
- page.body.close()
- page.html.close()
- with open(target, 'w') as f:
- f.write(page())
- return page
+ return page()
def wrap_html(func):
@@ -289,7 +100,8 @@ def decorated_func(ifo, start, end, *args, **kwargs):
if os.path.basename(about) == 'index.html':
about = about[:-10]
# open page
- page = init_page(ifo, start, end, **initargs)
+ header = banner(ifo, start, end)
+ page = gwhtml.new_bootstrap_page(navbar=header, **initargs)
# write content
contentf = os.path.join(outdir, '_inner.html')
with open(contentf, 'w') as f:
@@ -297,9 +109,19 @@ def decorated_func(ifo, start, end, *args, **kwargs):
# embed content
page.div('', id_='content')
page.script("$('#content').load('%s');" % contentf)
- # close page
+ # close page with custom footer
index = os.path.join(outdir, 'index.html')
- close_page(page, index, about=about)
+ version = get_versions()['version']
+ commit = get_versions()['full-revisionid']
+ url = 'https://github.com/gwdetchar/hveto/tree/{}'.format(commit)
+ link = markup.oneliner.a(
+ 'View hveto-{} on GitHub'.format(version), href=url,
+ target='_blank', style='color:#eee;')
+ report = 'https://github.com/gwdetchar/hveto/issues'
+ issues = markup.oneliner.a(
+ 'Report an issue', href=report, target='_blank',
+ style='color:#eee;')
+ gwhtml.close_page(page, index, about=about, link=link, issues=issues)
return index
return decorated_func
@@ -325,44 +147,6 @@ def bold_param(key, value, **attrs):
return markup.oneliner.p('%s: %s' % (key, value), **attrs)
-def write_footer(about=None, date=None):
- """Write a