Skip to content

Commit

Permalink
Merge 78712fc into eb1780e
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex L. Urban committed Mar 26, 2019
2 parents eb1780e + 78712fc commit e817b8a
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ script:
- python -m coverage run ./setup.py test
- bash ci/test-bin.sh
- acorn --silent gwdetchar/_static/bootstrap-ligo.min.js
- acorn --silent gwdetchar/_static/gwdetchar-omega.min.js
- acorn --silent gwdetchar/_static/gwdetchar.min.js

after_success:
- python -m pip install ${PIP_FLAGS} coveralls
Expand Down
7 changes: 1 addition & 6 deletions bin/gwdetchar-lasso-correlation
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,6 @@ def style_table(html_table):
# write html
title = '%s Lasso Slow Correlations: %d-%d' % (args.ifo, start, end)
page = htmlio.new_bootstrap_page(title=title)
page.div(class_='container')

page.div(class_='page-header')
page.h1(title)
Expand Down Expand Up @@ -760,9 +759,5 @@ for i, (ch, lassocoef, plot4, plot5, plot6, ts) in enumerate(results):
page.div.close() # panel-collapse
page.div.close() # panel
page.div.close() # panel-group
page.add(htmlio.write_footer())
page.div.close() # container
with open('index.html', 'w') as f:
print(str(page), file=f)

htmlio.close_page(page, 'index.html') # save and close
print("-- Process Completed")
7 changes: 2 additions & 5 deletions bin/gwdetchar-overflow
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ if args.html:
args.ifo, int(args.gpsstart), int(args.gpsend)))
else:
page = htmlio.markup.page()
page.div(class_='container')
page.div(class_='container')

# -- header
page.div(class_='page-header')
Expand Down Expand Up @@ -348,8 +348,5 @@ if args.html:
page.table.close()

# -- close and write
page.add(htmlio.write_footer())
page.div.close()
with open(args.html, 'w') as fp:
print(str(page), file=fp)
htmlio.close_page(page, args.html)
gprint("HTML written to %s" % args.html)
9 changes: 4 additions & 5 deletions bin/gwdetchar-scattering
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ if args.verbose:
# -- prepare HTML -------------------------------------------------------------

page = htmlio.new_bootstrap_page(title='%s Scattering' % args.ifo)
page.div(class_='container')
page.div(class_='page-header')
page.h1('%s scattering: %d-%d'
% (args.ifo, int(args.gpsstart), int(args.gpsend)))
Expand Down Expand Up @@ -500,6 +499,9 @@ for i, channel in enumerate(sorted(alldata[0].keys())):
page.div.close()
page.div.close()

# close panel group
page.div.close()

# -- finalize -----------------------------------------------------------------

# write segments
Expand All @@ -508,9 +510,6 @@ if args.verbose:
gprint("%s written" % segfile)

# write HTML
page.add(htmlio.write_footer())
page.div.close()
with open('index.html', 'w') as fp:
fp.write(str(page))
htmlio.close_page(page, 'index.html')
if args.verbose:
gprint("-- index.html written, all done --")
7 changes: 1 addition & 6 deletions bin/gwdetchar-slow-correlation
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ with open('results.txt', 'w') as f:
# -- write html
title = '%s Slow Correlations: %d-%d' % (args.ifo, start, end)
page = htmlio.new_bootstrap_page(title=title)
page.div(class_='container')

# header
if flower:
Expand Down Expand Up @@ -471,10 +470,6 @@ for i, (ch, corr1, corr2, plot1, plot2, plot3,
page.div.close() # panel-collapse
page.div.close() # panel
page.div.close() # panel-group

page.add(htmlio.write_footer())
page.div.close() # container
with open('index.html', 'w') as f:
print(str(page), file=f)
htmlio.close_page(page, 'index.html') # save and close

print("-- Process Completed")
7 changes: 2 additions & 5 deletions bin/gwdetchar-software-saturations
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ if args.html:
page = htmlio.new_bootstrap_page()
else:
page = markup.page()
page.div(class_='container')
page.div(class_='container')
# -- header
page.div(class_='page-header')
page.h1('%s Software Saturations: %d-%d'
Expand Down Expand Up @@ -277,7 +277,4 @@ if args.html:
page.tbody.close()
page.table.close()
# close and write
page.add(htmlio.write_footer())
page.div.close()
with open(args.html, 'w') as fp:
print(str(page), file=fp)
htmlio.close_page(page, args.html)
165 changes: 125 additions & 40 deletions gwdetchar/io/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from .._version import get_versions

__author__ = 'Duncan Macleod <duncan.macleod@ligo.org>'
__credit__ = 'Alex Urban <alexander.urban@ligo.org>'

# -- HTML URLs ----------------------------------------------------------------

Expand All @@ -77,20 +78,30 @@
'_static/bootstrap-ligo.min.js',
)

GWDETCHAR_CSS = resource_filename(
'gwdetchar',
'_static/gwdetchar.min.css',
)
GWDETCHAR_JS = resource_filename(
'gwdetchar',
'_static/gwdetchar.min.js',
)

CSS_FILES = [
BOOTSTRAP_CSS,
FANCYBOX_CSS,
BOOTSTRAP_LIGO_CSS,
GWDETCHAR_CSS
]
JS_FILES = [
JQUERY_JS,
MOMENT_JS,
BOOTSTRAP_JS,
FANCYBOX_JS,
BOOTSTRAP_LIGO_JS,
GWDETCHAR_JS,
]


FORMATTER = HtmlFormatter(noclasses=True)


Expand Down Expand Up @@ -176,27 +187,62 @@ def _local_url(path):
return cssfiles, jsfiles


def new_bootstrap_page(*args, **kwargs):
"""Create a new `~markup.page` with twitter bootstrap CSS and JS headers
def new_bootstrap_page(base=os.path.curdir, lang='en', refresh=False,
navbar=None, **kwargs):
"""Create a new `~markup.page` with custom twitter bootstrap CSS and
JS headers
Parameters
----------
base : `str`
relative path to the base directory where the page is located
lang : `str`, optional
language of the page, default: en
refresh : `bool`, optional
boolean switch to enable periodic page refresh, default: False
navbar : `str`, optional
HTML enconding of a floating navbar, will be ignored if not given,
default: None
"""
# add bootstrap CSS if needed
css = kwargs.pop('css', [])
if BOOTSTRAP_CSS not in css:
css.insert(0, BOOTSTRAP_CSS)
# add jquery and bootstrap JS if needed
script = kwargs.pop('script', [])
for js in [BOOTSTRAP_JS, JQUERY_JS]:
if js not in script:
script.insert(0, js)
# ensure nice formatting on mobile screens
metainfo = {
'viewport': 'width=device-width, initial-scale=1.0'}
# create page and init
kwargs['css'] = css
kwargs['script'] = script
kwargs['metainfo'] = metainfo
# get kwargs with sensible defaults
css = kwargs.get('css', CSS_FILES)
script = kwargs.get('script', JS_FILES)
# write CSS to static dir
css, script = finalize_static_urls(
os.path.join(os.path.curdir, 'static'),
css,
script,
)
# create page
page = markup.page()
page.init(*args, **kwargs)
page.header.append('<!DOCTYPE HTML>')
page.html(lang=lang)
page.head()
if refresh: # force-refresh if requested
page.meta(http_equiv='refresh', content='60')
# ensure nice formatting on most devices
page.meta(http_equiv='Content-Type', content='text/html; charset=utf-8')
page.meta(content='width=device-width, initial-scale=1.0', name='viewport')
page.base(href=base)
page._full = True
# link files
for f in css:
page.link(href=f, rel='stylesheet', type='text/css', media='all')
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()
# open body and container
page.body()
if navbar is not None:
page.add(navbar)
page.div(class_='container')
return page


Expand All @@ -212,7 +258,7 @@ def write_param(param, value):


def render_code(code, language):
"""Render a black of code with syntax highlighting
"""Render a block of code with syntax highlighting
Parameters
----------
Expand Down Expand Up @@ -437,49 +483,88 @@ def write_flag_html(flag, span=None, id=0, parent='accordion',
return page()


def write_footer(about=None, date=None, class_=False,
linkstyle='color:#000;'):
def write_footer(about=None, link=None, issues=None, linkstyle='color:#eee;'):
"""Write a <footer> for a bootstrap page
Parameters
----------
about : `str`, optional
path of about page to link
date : `datetime.datetime`, optional
the datetime representing when this analysis was generated, defaults
to `~datetime.datetime.now`
link : `str`, optional
HTML link to software name and version
issues : `str`, optional
HTML link to issue report page
linkstyle : `str`, optional
style options for rendering `link`
Returns
-------
page : `~MarkupPy.markup.page`
the markup object containing the footer HTML
"""
page = markup.page()
if class_:
page.twotags.append('footer')
markup.element('footer', case=page.case, parent=page)(class_='footer')
page.twotags.append('footer')
markup.element('footer', case=page.case, parent=page)(class_='footer')
page.div(class_='container')
# write user/time for analysis
if date is None:
date = datetime.datetime.now().replace(second=0, microsecond=0)
version = get_versions()['version']
commit = get_versions()['full-revisionid']
url = 'https://github.com/gwdetchar/gwdetchar/tree/{}'.format(commit)
link = markup.oneliner.a('gwdetchar version {}'.format(version), href=url,
target='_blank', style=linkstyle)
if link is None:
version = get_versions()['version']
commit = get_versions()['full-revisionid']
url = 'https://github.com/gwdetchar/gwdetchar/tree/{}'.format(commit)
link = markup.oneliner.a('View gwdetchar-{} on GitHub'.format(version),
href=url, target='_blank', style=linkstyle)
if issues is None:
report = 'https://github.com/gwdetchar/gwdetchar/issues'
issues = markup.oneliner.a('Report an issue', href=report,
target='_blank', style=linkstyle)
page.div(class_='row')
page.div(class_='col-md-12')
page.p('These results were obtained using {link} by {user} at '
'{date}.'.format(link=link, user=getuser(), date=date))
date = datetime.datetime.now().strftime('%H:%m %Z on %d %B %Y')
page.p('This page was created by {user} at {date}.'.format(
user=getuser(), date=date))
page.p('{link} | {issues}'.format(link=link, issues=issues))
# link to 'about'
if about is not None:
page.a('How was this page generated?', href=about, style=linkstyle)
page.div.close() # col-md-12
page.div.close() # row
page.div.close() # container
if class_:
markup.element('footer', case=page.case, parent=page).close()
markup.element('footer', case=page.case, parent=page).close()
return page()


def close_page(page, target, **kwargs):
"""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
</div>
<footer>
<!-- some stuff -->
</footer>
</body>
</html>
Parameters
----------
page : `markup.page`
the markup object to close
target : `str`
the output filename for HTML
"""
page.div.close() # container
page.add(write_footer(**kwargs))
if not page._full:
page.body.close()
page.html.close()
with open(target, 'w') as f:
f.write(page())
return page()


Expand Down
Loading

0 comments on commit e817b8a

Please sign in to comment.