Skip to content

Commit

Permalink
improved template
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Aug 9, 2012
1 parent 6a37ddb commit 3787f80
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 59 deletions.
13 changes: 9 additions & 4 deletions lib/python/moa/plugin/system/doc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
import moa.ui
import moa.args
import moa.utils
import moa.logger as l
import moa.logger
l = moa.logger.getLogger(__name__)
from moa.sysConf import sysConf

from moa.plugin.system.doc import pelican_util

def hook_finish():

job = sysConf['job']

if not sysConf.commands[sysConf.args.command]['logJob']:
return

Expand Down Expand Up @@ -243,6 +242,7 @@ def pelican(job, args):
pelican_util.generate_parameter_page(job)
pelican_util.generate_file_page(job)
pelican_util.generate_readme_page(job)
pelican_util.generate_template_page(job)

if args.force or (not os.path.exists(peliconf)):
jenv = jinja2.Environment(loader=jinja2.PackageLoader('moa.plugin.system.doc'))
Expand All @@ -257,9 +257,14 @@ def pelican(job, args):

cl = 'pelican -q -t %s -s .moa/pelican.conf.py -o doc/pelican/ doc/' % (
themedir)
subprocess.Popen(cl, shell=True)


P = subprocess.Popen(cl, shell=True)
#make a symlink to the index.thml
if not os.path.exists('index.html'):
os.symlink('doc/pelican/index.html', 'index.html')





Expand Down
60 changes: 12 additions & 48 deletions lib/python/moa/plugin/system/doc/pelican_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@
from Yaco import Yaco

def _getpagename(name):
l.critical("creating page for %s" % name)
pagedir = os.path.join('doc', 'pages')
if not os.path.exists(pagedir):
os.makedirs(pagedir)

return os.path.join(pagedir, name)


def generate_template_page(job):
"""
create a page with template parameters
"""
jtemplate = jenv.select_template(['template.page.jinja2'])
pagename = _getpagename('template.md')

with open(pagename, 'w') as F:
F.write(jtemplate.render({
't' : job.template}))

def generate_readme_page(job):
"""
Create a parameter page for pelican
Expand Down Expand Up @@ -53,7 +62,6 @@ def generate_parameter_page(job):
fsv = '%-' + str(mvl) + 's'
head1 = ('%-' + str(mkl) + 's | FLAG | %-' + str(mvl) + 's') % ('key', 'value')
head2 = ('%-' + str(mkl) + 's | ----- | %-' + str(mvl) + 's') % ('-' * mkl, '-' * mvl)
print head1

with open(pagename, 'w') as F:
F.write(jtemplate.render({
Expand Down Expand Up @@ -84,7 +92,7 @@ def generate_file_page(job):

fsets = []
fmaps = []

data = Yaco()

for fsid in filesets:
Expand Down Expand Up @@ -135,47 +143,3 @@ def generate_file_page(job):
F.write(jtemplate.render(data))

return


# if j == 0:
# moa.ui.fprint(" {{bold}}%3d{{reset}}:" % i, f='jinja', newline=False)
# else:
# moa.ui.fprint(" ", f='jinja', newline=False)
# cat = templateInfo.category
# if cat == 'input':
# moa.ui.fprint("{{green}}inp{{reset}}", f='jinja', newline=False)
# elif cat == 'output':
# moa.ui.fprint("{{blue}}out{{reset}}", f='jinja', newline=False)
# else:
# moa.ui.fprint("{{red}}%s{{reset}}" % cat[:3], f='jinja', newline=False)
# moa.ui.fprint(" {{gray}}%-5s{{reset}}" % templateInfo.type, f='jinja', newline=False)
# moa.ui.fprint(" {{bold}}%-20s{{reset}} " % fsid, f='jinja', newline=False)
# moa.ui.fprint(_preformatFile(files[i]), f='jinja', newline=False)
# moa.ui.fprint("")
# moa.ui.fprint("")


# dar = sysConf.www.dataRoot
# wer = sysConf.www.webRoot
# rv = []
# for f in fileList:
# #if f[0] == '.':
# # f = os.path.join(sysConf.job.wd, f)

# fup = os.path.abspath(f)
# if os.path.exists(fup):
# linkClass = 'moaFileExists'
# else:
# linkClass = 'moaFileAbsent'

# if fup.find(dar) == 0:
# fullurl = fup.replace(dar, wer)
# dirurl = os.path.dirname(fup).replace(dar,wer)
# link = '<a class="%s" href="%s#fileBrowser">%s</a>' % (
# linkClass, dirurl, os.path.basename(fup))
# if linkClass == 'moaFileExists':
# link += ' <span style="font-size: 60%%;">(<a href="%s">dl</a>)</span>' % (fullurl)
# rv.append(link)
# else:
# rv.append("%s" % (f)) #os.path.basename(f)))
# return rv
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Title: parameters
{%- set ren=rendered.get(name, '') -%}
**{{ fsk|format(name) }}** | {{ "%5s"|format(conf.getFlags(name)) }} | {{ fsv|format(ren) }}
{%- if val != ren %}
{{ fsk|format(" ") }} | (raw) | {{ fsv|format(val) }}
{{ fsk|format(" ") }} |*(raw)*| {{ fsv|format(val) }}
{%- endif -%}
{%- endmacro %}
{{head1}}
Expand Down
9 changes: 5 additions & 4 deletions lib/python/moa/plugin/system/doc/theme/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>{% block windowtitle %}{{ SITENAME }}{% endblock %}</title>
<title>{% block windowtitle %}{{ SITENAME }} job in {{ WD }} {% endblock %}</title>
<meta name="description" content="">
<meta name="author" content="{{ AUTHOR }}">

Expand All @@ -23,24 +23,25 @@
<a class="brand" href="{{ SITEURL }}/index.html">{{ SITENAME }}</a>
x {{ WD }} x
<ul class="nav">
<li><a href="../..">{{WD}}</a></li>
<li><a href="{% block jobdir %}../../{% endblock %}">{{WD}}</a></li>
</ul>
<p class="pull-right"><a href="{{ SITEURL }}/archives.html">[archives]</a> <a href="{{ SITEURL }}/tags.html">[tags]</a></p>
</div>
</div>
</div>

<div class="container-fluid">
<div class="container-fluid">
<div class="sidebar">
<div class="well">
<h3>Job</h3>
<ul>
<li><a href="{{ self.jobdir() }}">dir</a>
{% for title, link in MENUITEMS %}
<li><a href="{{ link }}">{{ title }}</a></li>
{% endfor %}
{% if DISPLAY_PAGES_ON_MENU %}
{% for page in PAGES %}
<li><a href="{{ SITEURL }}/pages/{{ page.url }}">{{ page.title }}</a></li>
<li><a href="{{ SITEURL }}/{{ page.url }}">{{ page.title }}</a></li>
{% endfor %}
{% endif %}
{% for cat, null in categories %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{% extends "index.html" %}
{% block title %}{{ SITENAME }} <small>{{ category }}</small>{% endblock %}
{% block jobdir %}../../../{% endblock %}
{% block title %}{{ SITENAME }} <small>{{ category }}</small>{% endblock %}
3 changes: 2 additions & 1 deletion lib/python/moa/plugin/system/doc/theme/templates/page.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{% extends "base.html" %}
{% block jobdir %}../../../{% endblock %}
{% block indextitle %}{% endblock %}
{% block content %}
<div class='page'>
<div class="page-header"><h1>{{ page.title }}</h1></div>
<div>{{ page.content }}</div>
</div>
{% endblock %}
{% endblock %}

0 comments on commit 3787f80

Please sign in to comment.