Skip to content

Commit

Permalink
Blurb xhtml
Browse files Browse the repository at this point in the history
  • Loading branch information
jpn-- committed Feb 3, 2017
1 parent c0d208d commit 7188742
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 11 deletions.
4 changes: 4 additions & 0 deletions doc/_static/larch_rtfd.css
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,8 @@ table.dictionary {
border-collapse: collapse !important;
}

div.blurb {
margin-top: 15px;
}

}
50 changes: 47 additions & 3 deletions py/dt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2483,7 +2483,7 @@ def crack_idca(self, idca_var=None):
self.h5f.create_carray(self.idco._v_node, idca_var, obj=newarr)
self.idca._v_children[idca_var]._f_remove()

def new_idco(self, name, expression, dtype=numpy.float64, *, overwrite=False, title=None):
def new_idco(self, name, expression, dtype=numpy.float64, *, overwrite=False, title=None, dictionary=None):
"""Create a new :ref:`idco` variable.
Creating a new variable in the data might be convenient in some instances.
Expand All @@ -2505,6 +2505,13 @@ def new_idco(self, name, expression, dtype=numpy.float64, *, overwrite=False, ti
The dtype for the array of new data.
overwrite : bool
Should the variable be overwritten if it already exists, default to False.
title : str, optional
A descriptive title for the variable, typically a short phrase but an
arbitrary length description is allowed.
dictionary : dict, optional
A data dictionary explaining some or all of the values in this field.
Even for otherwise self-explanatory numerical values, the dictionary
may give useful information about particular out of range values.
Raises
------
Expand All @@ -2521,6 +2528,8 @@ def new_idco(self, name, expression, dtype=numpy.float64, *, overwrite=False, ti
self.idco[name]._v_attrs.ORIGINAL_SOURCE = "= {}".format(expression)
if title is not None:
self.idco[name]._v_attrs.TITLE = title
if dictionary is not None:
self.idco[name]._v_attrs.DICTIONARY = dictionary

def recast_idco(self, name, newtype, invalid_values=()):
"""
Expand Down Expand Up @@ -2555,12 +2564,40 @@ def recast_idco(self, name, newtype, invalid_values=()):



def new_blank_idco(self, name, dtype=None, overwrite=False, title=None, initializer=0):
def new_blank_idco(self, name, dtype=None, overwrite=False, title=None, initializer=0, dictionary=None):
"""Create a new blank :ref:`idco` variable.
Parameters
----------
name : str
The name of the new :ref:`idco` variable.
initializer : value, optional
If given, initialize the array with this value (defaults to zero.
dtype : dtype
The dtype for the array of new data.
overwrite : bool
Should the variable be overwritten if it already exists, default to False.
title : str, optional
A descriptive title for the variable, typically a short phrase but an
arbitrary length description is allowed.
dictionary : dict, optional
A data dictionary explaining some or all of the values in this field.
Even for otherwise self-explanatory numerical values, the dictionary
may give useful information about particular out of range values.
Raises
------
tables.exceptions.NodeError
If a variable of the same name already exists and overwrite is False.
NameError
If the expression contains a name that cannot be evaluated from within
the existing :ref:`idco` data.
"""
if initializer is 0:
zer = numpy.zeros(self.nAllCases(), dtype=dtype or numpy.float64)
else:
zer = numpy.full(self.nAllCases(), initializer, dtype=dtype or numpy.float64)
return self.new_idco_from_array(name, zer, overwrite=overwrite, title=title)
return self.new_idco_from_array(name, zer, overwrite=overwrite, title=title, dictionary=dictionary)

def new_seqential_idco(self, name, dtype=None, overwrite=False, title=None):
zer = numpy.arange(self.nAllCases(), dtype=dtype or numpy.float64)
Expand Down Expand Up @@ -2593,6 +2630,13 @@ def new_idco_from_array(self, name, arr, *, overwrite=False, original_source=Non
Optionally, give the file name or other description of the source of the data in this array.
rel_original_source : bool
If true, change the absolute path of the original_source to a relative path viz this file.
title : str, optional
A descriptive title for the variable, typically a short phrase but an
arbitrary length description is allowed.
dictionary : dict, optional
A data dictionary explaining some or all of the values in this field.
Even for otherwise self-explanatory numerical values, the dictionary
may give useful information about particular out of range values.
Raises
------
Expand Down
4 changes: 4 additions & 0 deletions py/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def __call__(self, *arg):
table.dictionary { border:0px hidden !important; border-collapse: collapse !important; }
div.blurb {
margin-top: 15px;
}
"""


Expand Down
44 changes: 36 additions & 8 deletions py/model_reporter/xhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import os
import re
from xml.etree import ElementTree
import textwrap
from docutils.core import publish_parts



XhtmlModelReporter_default_format = {
'LL' : '0.2f',
Expand Down Expand Up @@ -2795,29 +2799,53 @@ def xhtml_headnote(self,**format):
x.end('ul')
return x.close()

def xhtml_blurb(self, h_stepdown=2, **format):
def _xhtml_blurb_n(self, h_stepdown=2, n='', **format):
try:
blurb_rst = self.blurb
blurb_rst = getattr(self, 'blurb'+str(n))
except AttributeError:
return None
if isinstance(blurb_rst, bytes):
blurb_rst = blurb_rst.decode()
if not isinstance(blurb_rst, str):
raise TypeError('blurb must be reStructuredText as str ot bytes')

import textwrap
blurb_rst = textwrap.dedent(blurb_rst).strip()

from docutils.core import publish_parts
blurb_div = ElementTree.fromstring(publish_parts(blurb_rst, writer_name='html')['html_body'])
blurb_div.attrib['class'] = 'blurb'

for hlevel in (6,5,4,3,2,1):
for bh1 in blurb_div.iter('h{}'.format(hlevel)):
bh1.tag = 'h{}'.format(hlevel+h_stepdown)

return blurb_div

def xhtml_blurb(self, h_stepdown=2, **format):
return self._xhtml_blurb_n(h_stepdown=h_stepdown, **format)

def xhtml_blurb1(self, h_stepdown=2, **format):
return self._xhtml_blurb_n(h_stepdown=h_stepdown, n=1, **format)

def xhtml_blurb2(self, h_stepdown=2, **format):
return self._xhtml_blurb_n(h_stepdown=h_stepdown, n=2, **format)

def xhtml_blurb3(self, h_stepdown=2, **format):
return self._xhtml_blurb_n(h_stepdown=h_stepdown, n=3, **format)

def xhtml_blurb4(self, h_stepdown=2, **format):
return self._xhtml_blurb_n(h_stepdown=h_stepdown, n=4, **format)

def xhtml_blurb5(self, h_stepdown=2, **format):
return self._xhtml_blurb_n(h_stepdown=h_stepdown, n=5, **format)

def xhtml_blurb6(self, h_stepdown=2, **format):
return self._xhtml_blurb_n(h_stepdown=h_stepdown, n=6, **format)

def xhtml_blurb7(self, h_stepdown=2, **format):
return self._xhtml_blurb_n(h_stepdown=h_stepdown, n=7, **format)

def xhtml_blurb8(self, h_stepdown=2, **format):
return self._xhtml_blurb_n(h_stepdown=h_stepdown, n=8, **format)

def xhtml_blurb9(self, h_stepdown=2, **format):
return self._xhtml_blurb_n(h_stepdown=h_stepdown, n=9, **format)



def xhtml_dt_info(self, **format):
Expand Down
1 change: 1 addition & 0 deletions py/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def multireport(models_or_filenames, params=(), ratios=(), *, filename=None, ove
.larch_signature {""" + styles.signature_font + """}
.larch_name_signature {""" + styles.signature_name_font + """}
table.dictionary { border:0px hidden !important; border-collapse: collapse !important; }
div.blurb { margin-top: 15px; }
</style>
"""

Expand Down
3 changes: 3 additions & 0 deletions py/util/xhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
}
table.dictionary { border:0px hidden !important; border-collapse: collapse !important; }
div.blurb {
margin-top: 15px;
}
"""

Expand Down

0 comments on commit 7188742

Please sign in to comment.