Skip to content

Commit

Permalink
Basic new API implemented, with a few Bootstrap components now availa…
Browse files Browse the repository at this point in the history
…ble.
  • Loading branch information
transientlunatic committed Jan 26, 2016
1 parent 6e4777d commit 99d64da
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 54 deletions.
21 changes: 18 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'numpydoc']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand All @@ -56,7 +56,7 @@

# General information about the project.
project = u'Otter'
copyright = u'2015, Daniel WIlliams'
copyright = u'2015, Daniel Williams'

# The version info for the project you're documenting, acts as replacement
# for |version| and |release|, also used in various other places throughout
Expand Down Expand Up @@ -111,7 +111,22 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
#html_theme = 'default'

# -- Options for HTML output -------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#html_theme = 'default'
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
if not on_rtd: # only import and set the theme if we're building docs locally
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

else:
#sys.path.insert(0, os.path.abspath('../../'))
sys.path.insert(0, os.path.abspath('../otter'))

# Theme options are theme-specific and customize the look and feel of a
# theme further. For a list of options available for each theme, see the
Expand Down
51 changes: 40 additions & 11 deletions otter/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


from itertools import cycle
import markdown

class Row():
def __init__(self, cols=1, size='md', hclass=''):
Expand Down Expand Up @@ -36,24 +37,18 @@ def __init__(self, cols=1, size='md', hclass=''):

# We want this to degrade nicely so if there's only one column we interface directly with the row
def __add__(self, item):
if len(self.columns==1):
if len(self.columns)==1:
self.columns[0] + item
else:
# Need to throw an error
pass

def __set__(self, item):
if len(self.columns==1):
self.columns[0] = item
else:
# Need to throw an error
pass


def __getitem__(self, i):
return self.columns[i]

def __setitem__(self, i, item):
self.columns[i].content = item
self.columns[i].content = markdown.markdown(item, output_format='xhtml5')

def __repr__(self):
output = ''
Expand All @@ -77,11 +72,45 @@ def __iadd__(self, item):
return self.content

def __add__(self, item):
self.content += str(item)
self.content += markdown.markdown(str(item), output_format='xhtml5')

def __repr__(self):
output = ''
output += self.colopen.format(size=self.size, width=self.width, hclass=self.hclass)
output += self.content
output += self.colclose
return output


class Panel():
def __init__(self, title='', footer = '', style='default', hclass=''):
self.title = title
self.footer = footer
self.style = style
self.hclass = hclass

self.panopen = "<div class='panel panel-{style} {hclass}'>"
self.panclose = "</div>"

self.panbody = "<div class='panel-body'>{}</div>"
self.panheader = "<div class='panel-heading'>{}</div>"
self.panfooter = "<div class='panel-footer'>{}</div>"

self.content = ''

def __iadd__(self, item):
self.__add__(item)
return self.content

def __add__(self, item):
self.content += markdown.markdown(item, output_format='xhtml5')

def __repr__(self):
output = ''
output += self.panopen.format(style=self.style, hclass=self.hclass)
if self.panheader != '': output += self.panheader.format(self.title)
output += self.panbody.format(self.content)
if self.footer != '': output += self.panfooter.format(self.footer)
return output

__str__ = __repr__
56 changes: 16 additions & 40 deletions otter/otter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import uuid
import os

import ConfigParser

from jinja2 import Template, Environment, FileSystemLoader

import matplotlib as mpl
Expand All @@ -15,7 +17,7 @@ class Otter():
reports for long-running or complex jobs where and iPython
notebook would be an impractical way of presenting information.
"""
def __init__(self, filename, theme, meta):
def __init__(self, filename, theme, **kwargs):
"""
An Otter report is created by this class.
Expand All @@ -27,18 +29,25 @@ def __init__(self, filename, theme, meta):
A dictionary of metadata. This is likely to change very soon, but at present a dictionary is required for the title, subtitle, and author's name of the report.
"""

# Attempt to load in default meta data from a config file
# At the moment just the current directory, but should
# extend to look in home directory and environment variable location too

config = ConfigParser.ConfigParser()
config.read('otter.cfg')
self.meta = {}
for option in config.options('meta'):
self.meta[option] = config.get('meta', option)

self.env = Environment(loader=FileSystemLoader(theme))

self.reportfolder = filename+"_files"
self.foldername = os.path.basename(filename)+"_files/"
if not os.path.exists(self.reportfolder):
os.makedirs(self.reportfolder)
self.reportfile= open(filename,"w")
self.meta = meta

self.meta.update(kwargs)
self.items = []

self.write_preamble()

def __add__(self, item):
return self.add(item)
Expand All @@ -51,7 +60,8 @@ def show(self):
html = ''
for item in self.items:
html += repr(item)
self._write(html)
output_html = self.env.get_template('body.html').render(meta=self.meta, body=html)
self._write(output_html)

def _write(self, text):
self.reportfile.write(text)
Expand All @@ -68,47 +78,13 @@ def _mkdir_recursive(self, path):
if not os.path.exists(path):
os.mkdir(path)

def write_preamble(self):
head = self.env.get_template('head.html')
self._write(head.render(meta=self.meta))

def write_footer(self):
footer = self.env.get_template('footer.html')
self._write(footer.render(meta=self.meta))
self.reportfile.close()


def write_page_header(self):
header = self.env.get_template('header.html')
self._write(header.render(meta=self.meta))

def write_header(self, level, text):
html_str= """
<div class="row">
<h{0}>
{1}
</h{0}>
</div>
""".format(level,text)
self._write(html_str)

def write_image(self, url):
html_str= """
<div class="row">
<img src="{}" style="max-width: 100%;" class="img-responsive"></img>
</div>
""".format(url)
self._write(html_str)

def write_breadcrumb(self, crumbs):
start ="""
<ol class="breadcrumb">
"""
self._write(start)
for level in crumbs:
crumb, link = level[0], level[1]
self._write("""<li><a href="{0}">{1}</a></li>""".format(link, crumb))
self._write("""</ol>""")

def write_warning(self, warning, text):
html_str = """
Expand Down

0 comments on commit 99d64da

Please sign in to comment.