Skip to content

Commit

Permalink
Move API URL value to constants and use it as a fallback GitHubRenderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyespo committed Nov 17, 2015
1 parent c8f2c51 commit 21e5d1c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
13 changes: 7 additions & 6 deletions grip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
clear_cache, create_app, export, render_content, render_page, serve)
from .command import main
from .constants import (
DEFAULT_FILENAMES, DEFAULT_GRIPHOME, DEFAULT_GRIPURL,
DEFAULT_API_URL, DEFAULT_FILENAMES, DEFAULT_GRIPHOME, DEFAULT_GRIPURL,
STYLE_ASSET_URLS_INLINE_FORMAT, STYLE_ASSET_URLS_RE,
STYLE_ASSET_URLS_SUB_FORMAT, STYLE_URLS_RE, STYLE_URLS_SOURCE,
SUPPORTED_EXTENSIONS, SUPPORTED_TITLES)


__all__ = [
'DEFAULT_FILENAMES', 'DEFAULT_GRIPHOME', 'DEFAULT_GRIPURL',
'STYLE_ASSET_URLS_INLINE_FORMAT', 'STYLE_ASSET_URLS_RE',
'STYLE_ASSET_URLS_SUB_FORMAT', 'STYLE_URLS_RE', 'STYLE_URLS_SOURCE',
'SUPPORTED_EXTENSIONS', 'SUPPORTED_TITLES', 'create_app', 'serve',
'clear_cache', 'main', 'render_content', 'render_page', 'export',
'DEFAULT_API_URL', 'DEFAULT_FILENAMES', 'DEFAULT_FILENAME',
'DEFAULT_GRIPHOME', 'DEFAULT_GRIPURL', 'STYLE_ASSET_URLS_INLINE_FORMAT',
'STYLE_ASSET_URLS_RE', 'STYLE_ASSET_URLS_SUB_FORMAT', 'STYLE_URLS_RE',
'STYLE_URLS_SOURCE', 'SUPPORTED_EXTENSIONS', 'SUPPORTED_TITLES',
'create_app', 'serve', 'clear_cache', 'main', 'render_content',
'render_page', 'export',
]
2 changes: 0 additions & 2 deletions grip/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ def render_content(text, user_content=False, context=None, username=None,
"""
Renders the specified markup and returns the result.
"""
if not render_offline and api_url is None:
ValueError('Argument api_url is required when not rendering offline.')
renderer = (GitHubRenderer(user_content, context, api_url)
if not render_offline else
OfflineRenderer(user_content, context))
Expand Down
5 changes: 5 additions & 0 deletions grip/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
DEFAULT_GRIPURL = '/__/grip'


# The public GitHub API
DEFAULT_API_URL = 'https://api.github.com'


# Style parsing
STYLE_URLS_SOURCE = 'https://github.com/joeyespo/grip'
STYLE_URLS_RE = (
'<link.+href=[\'"]?([^\'" >]+)[\'"]?.+media=[\'"]?(?:screen|all)[\'"]?.'
Expand Down
4 changes: 4 additions & 0 deletions grip/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
markdown = None
UrlizeExtension = None

from .constants import DEFAULT_API_URL


class ReadmeRenderer(object):
"""
Expand Down Expand Up @@ -38,6 +40,8 @@ class GitHubRenderer(ReadmeRenderer):
Renders the specified Readme using the GitHub Markdown API.
"""
def __init__(self, user_content=None, context=None, api_url=None):
if api_url is None:
api_url = DEFAULT_API_URL
super(GitHubRenderer, self).__init__(user_content, context)
self.api_url = api_url

Expand Down
5 changes: 4 additions & 1 deletion grip/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
PORT = 6419
DEBUG = False
DEBUG_GRIP = False
API_URL = 'https://api.github.com'
CACHE_DIRECTORY = 'cache-{version}'
AUTOREFRESH = True
QUIET = False
Expand All @@ -24,5 +23,9 @@
PASSWORD = None


# Custom GitHub API
API_URL = None


# Custom styles
STYLE_URLS = []

0 comments on commit 21e5d1c

Please sign in to comment.