Skip to content

Commit

Permalink
Add utils.colorize_str (replaces/generalizes section colors)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 2, 2018
1 parent 652e3b4 commit 5209155
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/template-variables.rst
Expand Up @@ -97,6 +97,7 @@ Name Type Descript
``social_buttons_code`` TranslatableSetting<str> ``SOCIAL_BUTTONS_CODE`` setting
``sort_posts`` function ``utils.sort_posts`` function
``smartjoin`` function ``utils.smartjoin`` function
``colorize_str`` function ``utils.colorize_str`` function
``template_hooks`` dict<str, TemplateHookRegistry> Template hooks registered by plugins
``theme_color`` str ``THEME_COLOR`` setting
``timezone`` tzinfo Timezone object (represents the configured timezone)
Expand Down
1 change: 1 addition & 0 deletions nikola/nikola.py
Expand Up @@ -1177,6 +1177,7 @@ def _set_global_context_from_config(self):
self._GLOBAL_CONTEXT['url_replacer'] = self.url_replacer
self._GLOBAL_CONTEXT['sort_posts'] = utils.sort_posts
self._GLOBAL_CONTEXT['smartjoin'] = utils.smartjoin
self._GLOBAL_CONTEXT['colorize_str'] = utils.colorize_str
self._GLOBAL_CONTEXT['meta_generator_tag'] = self.config.get('META_GENERATOR_TAG')

self._GLOBAL_CONTEXT.update(self.config.get('GLOBAL_CONTEXT', {}))
Expand Down
7 changes: 7 additions & 0 deletions nikola/utils.py
Expand Up @@ -1767,6 +1767,13 @@ def degreediff(dega, degb):
return husl.husl_to_hex(h, s, l)


def colorize_str(string: str, base_color: str, presets: dict):
"""Colorize a string by using a presets dict or generate one based on base_color."""
if string in presets:
return presets[string]
return colorize_str_from_base_color(string, base_color)


def color_hsl_adjust_hex(hexstr, adjust_h=None, adjust_s=None, adjust_l=None):
"""Adjust a hex color using HSL arguments, adjustments in percentages 1.0 to -1.0. Returns a hex color."""
h, s, l = husl.hex_to_husl(hexstr)
Expand Down

0 comments on commit 5209155

Please sign in to comment.