Skip to content

Commit

Permalink
Fix style issues in plugins
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Nov 19, 2016
1 parent f17f98f commit 56d7165
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions v6/book_figure/book_figure.py
Expand Up @@ -39,6 +39,7 @@ def set_site(self, site):
directives.register_directive('book_figure', BookFigure)
return super(Plugin, self).set_site(site)


CODE_IMAGE = (u"""<div class="book-figure-media">
<a class="book-figure-image" href="{url}" target="_blank">
<img src="{image_url}" alt="{title}" />
Expand Down
1 change: 1 addition & 0 deletions v6/import_tumblr/import_tumblr.py
Expand Up @@ -255,6 +255,7 @@ def import_link(self, post):
'hidetitle': not post['title']
})


LINK_POST_TEMPLATE = '''
<div class="link"><a href="${url}">${title}</a></div>
<div class="description">
Expand Down
1 change: 1 addition & 0 deletions v6/link_figure/link_figure.py
Expand Up @@ -39,6 +39,7 @@ def set_site(self, site):
directives.register_directive('link_figure', LinkFigure)
return super(Plugin, self).set_site(site)


CODE_URL_BASIC = (u"""<a class="{classes}"
href="{url}"
title="{description}">
Expand Down
29 changes: 15 additions & 14 deletions v7/navstories/navstories.py
Expand Up @@ -31,6 +31,7 @@

import re


class NavStories(ConfigPlugin):
"""Add all stories to the navigation bar."""

Expand All @@ -57,7 +58,6 @@ def __init__(self, navpath, permalink, title):
self.permalink = permalink
self.title = title


def map_to_menu(self, entries):
"""
Map form list of pages going into menu to tuple of format as NAVIGATION_LINKS and NAVIGATION_LINKS_POST_NAVSTORIES
Expand All @@ -67,7 +67,7 @@ def map_to_menu(self, entries):
- Top level Menu text, or None if auto-mapped, i.e. not in NAVSTORIES_MAPPING
- List of pages in the top menu entry
- List of:
- navpath: List containing navigation hieracy (permalink without langinfo (initial /en/) and without the NAVSTORIES_PATHS (e.g. /pages/))
- navpath: List containing navigation hierarchy (permalink without langinfo (initial /en/) and without the NAVSTORIES_PATHS (e.g. /pages/))
- Permalink
- Page title
Example:
Expand Down Expand Up @@ -98,23 +98,22 @@ def map_to_menu(self, entries):
# Search for toplevel page (navpath length = 1)
for n in navnodes:
if len(n.navpath) == 1:
title = n.title # Page Title
title = n.title # Page Title
if len(navnodes) == 1 and len(navnodes[0].navpath) == 1:
# Only one menu item and it is not a subpage, let the item go direct to top level menu
ret.append(tuple([navnodes[0].permalink, title]))
else:
sub = []
# Find min/max depth in actual submenu
# Find min depth in actual submenu
min_depth = min(len(n.navpath) for n in navnodes)
max_depth = max(len(n.navpath) for n in navnodes)
# Map pages to submenu
for n in sorted(navnodes, key=lambda n: n.permalink): # Sort by permalink in page list
for n in sorted(navnodes, key=lambda n: n.permalink):
# Sort by permalink in page list
prefix = self.navstories_submenu_indention * (len(n.navpath) - min_depth)
sub.append(tuple([n.permalink, prefix + n.title]))
ret.append(tuple([tuple(sub), title]))
return tuple(ret)


def set_site(self, site):
"""
Map navstories config to nav_config[*] as TranslatableSettings
Expand All @@ -126,11 +125,11 @@ def set_site(self, site):

nav_config = {}
for i in self.conf_vars:
# Read config variables in a try...except in case a varible is missing
# Read config variables in a try...except in case a variable is missing
try:
nav_config[i] = utils.TranslatableSetting(i, site.config[i], site.config['TRANSLATIONS'])
except KeyError:
# Initialize to "empty" in case config variable i is missng
# Initialize to "empty" in case config variable i is missing
nav_config[i] = utils.TranslatableSetting(i, {}, site.config['TRANSLATIONS'])

site.scan_posts()
Expand All @@ -139,16 +138,18 @@ def set_site(self, site):
# navstories config for lang
nav_conf_lang = {}
for i in self.conf_vars:
nav_conf_lang[i] = nav_config[i](lang)
nav_conf_lang[i] = nav_config[i](lang)

# Which paths are navstories active for current lang? - Must start and end with /
paths = tuple(('/' + s.strip('/') + '/') for s in nav_conf_lang['NAVSTORIES_PATHS'])

new_raw = {} # Unusorted (raw) new entries, deleted as mapped to new
new = [] # Sorted entries as a list of top-level menu entries, later
# Unsorted (raw) new entries, deleted as mapped to new
new_raw = {}
# Sorted entries as a list of top-level menu entries, later
new = []
# Map site pages to new_raw structure
for p in site.pages:
# Generate mavpath (menu) based on permalink without language prefix
# Generate navpath (menu) based on permalink without language prefix
# If TRANSLATION[DEFAULT_LANG] = '', then "permalink_nolang = p.permalink()" is ok
permalink_nolang = re.sub(r'^/' + nav_conf_lang['TRANSLATIONS'].lstrip('./') + '/?', '/', p.permalink(lang))
s_candidates = [s for s in paths if permalink_nolang.startswith(s)]
Expand All @@ -160,7 +161,7 @@ def set_site(self, site):
navpath = permalink_nolang[len(s):].strip('/').split('/')
if len(navpath) == 0:
# Should not happen that navpath is empty, but to prevent errors, and inform via a warning
LOGGER.warn("Page with permalink: '%s', title: '%s', not added to menu by navstories.\033[0m" % (p.permalink(lang), p.title(lang)))
LOGGER.warn("Page with permalink: '%s', title: '%s', not added to menu by navstories." % (p.permalink(lang), p.title(lang)))
continue
if lang in p.translated_to and not p.meta('hidefromnav'):
# Add entry
Expand Down
1 change: 1 addition & 0 deletions v7/pyplots/pyplots.py
Expand Up @@ -56,6 +56,7 @@ def set_site(self, site):
PyPlot.out_dir = os.path.join(site.config['OUTPUT_FOLDER'], 'pyplots')
return super(Plugin, self).set_site(site)


pyplot_spec = images.Image.option_spec
pyplot_spec['include-source'] = directives.flag

Expand Down
1 change: 0 additions & 1 deletion v7/speechsynthesizednetcast/speechsynthesizednetcast.py
Expand Up @@ -69,7 +69,6 @@ def gen_tasks(self):
"blog_title": self.site.config['BLOG_TITLE'],
"blog_description": self.site.config['BLOG_DESCRIPTION'],
"site_url": self.site.config['SITE_URL'],
"blog_description": self.site.config['BLOG_DESCRIPTION'],
"output_folder": self.site.config['OUTPUT_FOLDER'],
"cache_folder": self.site.config['CACHE_FOLDER'],
"feed_length": self.site.config['FEED_LENGTH'],
Expand Down
5 changes: 5 additions & 0 deletions v7/sphinx_roles/sphinx_roles.py
Expand Up @@ -122,6 +122,7 @@ def pep_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
rn += sn
return [rn], []


explicit_title_re = re.compile(r'^(.+?)\s*(?<!\x00)<(.*?)>$', re.DOTALL)


Expand Down Expand Up @@ -180,6 +181,7 @@ def rfc_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


_litvar_re = re.compile('{([^}]+)}')


Expand All @@ -198,6 +200,7 @@ def emph_literal_role(typ, rawtext, text, lineno, inliner,
retnode += nodes.Text(text[pos:], text[pos:])
return [retnode], []


_amp_re = re.compile(r'(?<!&)&(?![&\s])')


Expand Down Expand Up @@ -253,6 +256,7 @@ def set_source_info(directive, node):
node.source, node.line = \
directive.state_machine.get_source_and_line(directive.lineno)


# FIXME: needs translations
versionlabels = {
'versionadded': 'New in version %s',
Expand Down Expand Up @@ -494,6 +498,7 @@ def unknown_visit(self, node):
pnode['classes'] = ['reference']
return [pnode], msg_list


_abbr_re = re.compile('\((.*)\)$', re.S)


Expand Down

0 comments on commit 56d7165

Please sign in to comment.