Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to remove borders and titles #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions grip/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
def create_app(path=None, user_content=False, context=None, username=None,
password=None, render_offline=False, render_wide=False,
render_inline=False, api_url=None, title=None, text=None,
autorefresh=None, quiet=None, grip_class=None):
hide_border=False, hide_title=False, autorefresh=None, quiet=None,
grip_class=None):
"""
Creates a Grip application with the specified overrides.
"""
Expand Down Expand Up @@ -43,20 +44,23 @@ def create_app(path=None, user_content=False, context=None, username=None,

# Create the customized app with default asset manager
return grip_class(source, auth, renderer, None, render_wide,
render_inline, title, autorefresh, quiet)
render_inline, title, hide_border, hide_title,
autorefresh, quiet)


def serve(path=None, host=None, port=None, user_content=False, context=None,
username=None, password=None, render_offline=False,
render_wide=False, render_inline=False, api_url=None, title=None,
autorefresh=True, browser=False, quiet=None, grip_class=None):
hide_border=False, hide_title=False, autorefresh=True, browser=False,
quiet=None, grip_class=None):
"""
Starts a server to render the specified file or directory containing
a README.
"""
app = create_app(path, user_content, context, username, password,
render_offline, render_wide, render_inline, api_url,
title, None, autorefresh, quiet, grip_class)
title, None, hide_border, hide_title, autorefresh,
quiet, grip_class)
app.run(host, port, open_browser=browser)


Expand All @@ -72,13 +76,15 @@ def clear_cache(grip_class=None):
def render_page(path=None, user_content=False, context=None,
username=None, password=None,
render_offline=False, render_wide=False, render_inline=False,
api_url=None, title=None, text=None, grip_class=None):
api_url=None, title=None, hide_border=False, hide_title=False,
text=None, grip_class=None):
"""
Renders the specified markup text to an HTML page and returns it.
"""
return create_app(path, user_content, context, username, password,
render_offline, render_wide, render_inline, api_url,
title, text, False, None, grip_class).render()
title, text, hide_border, hide_title, False, None,
grip_class).render()


def render_content(text, user_content=False, context=None, username=None,
Expand All @@ -96,7 +102,7 @@ def render_content(text, user_content=False, context=None, username=None,
def export(path=None, user_content=False, context=None, username=None,
password=None, render_offline=False, render_wide=False,
render_inline=True, out_filename=None, api_url=None, title=None,
grip_class=None):
hide_border=False, hide_title=False, grip_class=None):
"""
Exports the rendered HTML to a file.
"""
Expand All @@ -114,7 +120,7 @@ def export(path=None, user_content=False, context=None, username=None,

page = render_page(path, user_content, context, username, password,
render_offline, render_wide, render_inline, api_url,
title, None, grip_class)
title, hide_border, hide_title, None, grip_class)

if export_to_stdout:
try:
Expand Down
8 changes: 6 additions & 2 deletions grip/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class Grip(Flask):
containing a README.
"""
def __init__(self, source=None, auth=None, renderer=None,
assets=None, render_wide=None, render_inline=None, title=None,
assets=None, render_wide=None, render_inline=None,
title=None, hide_border=False, hide_title=False,
autorefresh=None, quiet=None, grip_url=None,
static_url_path=None, instance_path=None, **kwargs):
# Defaults
Expand Down Expand Up @@ -99,6 +100,8 @@ def __init__(self, source=None, auth=None, renderer=None,
self.render_wide = render_wide
self.render_inline = render_inline
self.title = title
self.hide_border = hide_border
self.hide_title = hide_title
self.quiet = quiet
if self.quiet:
import logging
Expand Down Expand Up @@ -189,7 +192,8 @@ def _render_page(self, subpath=None):

return render_template(
'index.html', filename=self.reader.filename_for(subpath),
title=self.title, content=content, favicon=favicon,
title=self.title, hide_border=self.hide_border,
hide_title=self.hide_title, content=content, favicon=favicon,
user_content=self.renderer.user_content,
wide_style=self.render_wide, style_urls=self.assets.style_urls,
styles=self.assets.styles, autorefresh_url=autorefresh_url)
Expand Down
9 changes: 6 additions & 3 deletions grip/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
for example that of a Github Enterprise instance.
Default is the public API: https://api.github.com
--title=<title> Manually sets the page's title.
-B Remove borders (currently not supported when running
with --user-content).
-T Remove title.
The default is the filename.
--norefresh Do not automatically refresh the Readme content when
the file changes.
Expand Down Expand Up @@ -107,7 +110,7 @@ def main(argv=None, force_utf8=True, patch_svg=True):
export(args['<path>'], args['--user-content'], args['--context'],
args['--user'], password, False, args['--wide'],
not args['--no-inline'], args['<address>'],
args['--api-url'], args['--title'])
args['--api-url'], args['--title'], args['-B'], args['-T'])
return 0
except ReadmeNotFoundError as ex:
print('Error:', ex)
Expand All @@ -125,8 +128,8 @@ def main(argv=None, force_utf8=True, patch_svg=True):
try:
serve(path, host, port, args['--user-content'], args['--context'],
args['--user'], password, False, args['--wide'], False,
args['--api-url'], args['--title'], not args['--norefresh'],
args['--browser'], args['--quiet'], None)
args['--api-url'], args['--title'], args['-B'], args['-T'],
not args['--norefresh'], args['--browser'], args['--quiet'], None)
return 0
except ReadmeNotFoundError as ex:
print('Error:', ex)
Expand Down
6 changes: 3 additions & 3 deletions grip/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@
<div class="container new-discussion-timeline experiment-repo-nav">
<div class="repository-content">
<div id="readme" class="readme boxed-group clearfix announce instapaper_body md">
{% if not user_content and title or filename %}
<h3>
{% if not hide_title and (not user_content and title or filename) %}
<h3 {% if hide_border %}style="border:0px solid #ddd;"{% endif %}>
<span class="octicon octicon-book"></span>
{% if title %}{{ title }}{% else %}{{ filename }}{% endif %}
</h3>
{% endif %}
<article class="markdown-body entry-content" itemprop="text" id="grip-content">
<article class="markdown-body entry-content" itemprop="text" id="grip-content" {% if hide_border %}style="border:0px solid #ddd;"{% endif %}>
{{ content|safe }}
</article>
</div>
Expand Down