Navigation Menu

Skip to content

Commit

Permalink
Use index.html for all rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyespo committed Sep 22, 2013
1 parent 86c9824 commit 5c6c4ed
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 41 deletions.
4 changes: 2 additions & 2 deletions grip/exporter.py
Expand Up @@ -22,11 +22,11 @@ def write_html(path=None):

style_urls = _get_style_urls(config['STYLE_URLS_SOURCE'],
config['STYLE_URLS_RE'], None)
style_url_contents = [urlopen(css).read().decode('utf-8') for css in style_urls]
styles = [urlopen(css).read().decode('utf-8') for css in style_urls]

text = _read_file(path)
outname = os.path.splitext(path)[0] + '.html'
page = render_page(text=text, style_url_contents=style_url_contents)
page = render_page(text=text, styles=styles)

with open(outname, 'w') as f:
f.write(page.encode('utf-8'))
13 changes: 4 additions & 9 deletions grip/renderer.py
@@ -1,11 +1,12 @@
from jinja2 import Environment, PackageLoader
from flask import make_response
from .github_renderer import render_content as github_render
from .offline_renderer import render_content as offline_render
from flask import make_response


# Get jinja templates
env = Environment(loader=PackageLoader('grip', 'templates'))
index_template = env.get_template('index.html')


def render_content(text, gfm=False, context=None, render_offline=False,
Expand All @@ -17,17 +18,11 @@ def render_content(text, gfm=False, context=None, render_offline=False,


def render_page(text, filename=None, gfm=False, context=None, render_offline=False,
username=None, password=None, style_urls=[], style_url_contents=None):
username=None, password=None, style_urls=[], styles=None):
"""Renders the specified markup text to an HTML page."""
if style_url_contents:
index_template = env.get_template('index_export.html')
else:
index_template = env.get_template('index.html')

content = render_content(text, gfm, context, render_offline, username, password)
return index_template.render(content=content, filename=filename,
style_urls=style_urls,
style_url_contents=style_url_contents)
style_urls=style_urls, styles=styles)


def render_image(image_data, content_type):
Expand Down
7 changes: 7 additions & 0 deletions grip/templates/index.html
Expand Up @@ -6,6 +6,13 @@
{%- for style_url in style_urls -%}
<link rel="stylesheet" href="{{ style_url }}" />
{% endfor -%}
{%- if styles %}
<style>
{% for style in styles -%}
{{ style }}
{% endfor -%}
</style>
{% endif -%}
<style>
.previewPage {
margin: 64px auto;
Expand Down
30 changes: 0 additions & 30 deletions grip/templates/index_export.html

This file was deleted.

0 comments on commit 5c6c4ed

Please sign in to comment.