Skip to content

Commit

Permalink
Use new template option for sos convert #307
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Nov 18, 2020
1 parent 7d93231 commit 6a48af7
Show file tree
Hide file tree
Showing 49 changed files with 1,713 additions and 27 deletions.
19 changes: 5 additions & 14 deletions src/sos_notebook/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,9 @@ def convert(self, notebook_file, sos_file, args=None, unknown_args=None):
# notebook to HTML
#

def get_template_args(name):
if not name:
return []
for path in [
'',
os.path.join('{os.path.split(os.path.abspath(sos.__file__))[0]}', 'templates'),
os.path.join('{os.path.split(os.path.abspath(__file__))[0]}', 'templates')]:
for template in [name, name + '.tpl']:
template_file = os.path.join(path, template)
if os.path.isfile(template_file):
return ['--template-file', template_file]
return []
def get_template_args():
return ['--TemplateExporter.extra_template_basedirs', os.path.join('{os.path.split(os.path.abspath(__file__))[0]}', 'templates')]


def export_notebook(exporter_class,
to_format,
Expand Down Expand Up @@ -484,7 +475,7 @@ def convert(self,
if unknown_args is None:
unknown_args = []
if sargs.template:
unknown_args = get_template_args(sargs.template) + unknown_args
unknown_args = get_template_args() + unknown_args

if sargs.execute is not None:
notebook_file = execute_sos_notebook(
Expand Down Expand Up @@ -553,7 +544,7 @@ def convert(self,
if unknown_args is None:
unknown_args = []
if sargs.template:
unknown_args = get_template_args(sargs.template) + unknown_args
unknown_args = get_template_args() + unknown_args
# jupyter convert will add extension to output file...
if output_file is not None and output_file.endswith('.pdf'):
output_file = output_file[:-4]
Expand Down
6 changes: 6 additions & 0 deletions src/sos_notebook/templates/sos-cm-toc/conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"base_template": "sos-cm",
"mimetypes": {
"text/html": true
}
}
1 change: 1 addition & 0 deletions src/sos_notebook/templates/sos-cm-toc/index.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends 'sos-cm-toc.html.j2' %}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

{% extends 'sos-cm.tpl' %}
{% extends 'sos-cm.html.j2' %}

{% import 'parts/toc.tpl' as toc %}

Expand Down
6 changes: 6 additions & 0 deletions src/sos_notebook/templates/sos-cm/conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"base_template": "sos-full",
"mimetypes": {
"text/html": true
}
}
1 change: 1 addition & 0 deletions src/sos_notebook/templates/sos-cm/index.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends 'sos-cm.html.j2' %}
File renamed without changes.
Loading

0 comments on commit 6a48af7

Please sign in to comment.