Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support for hackerthemes
  • Loading branch information
Roberto Alsina committed Apr 19, 2018
1 parent d426ddf commit ebcdb2d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,7 @@ New in master
Features
--------

* Support hackerthemes.com themes and renamed bootswatch_theme command sub_theme (Issue #3049)
* Support captioned images and image ordering in galleries (Issue #3017)
* New ``ATOM_PATH`` setting (Issue #2971)
* Make ``crumbs`` available to all pages
Expand Down
@@ -1,12 +1,12 @@
[Core]
name = bootswatch_theme
module = bootswatch_theme
name = sub_theme
module = sub_theme

[Documentation]
author = Roberto Alsina
version = 1.0
version = 1.1
website = https://getnikola.com/
description = Given a swatch name and a parent theme, creates a custom theme.
description = Given a swatch name and a parent theme, creates a custom subtheme.

[Nikola]
PluginCategory = Command
Expand Down
Expand Up @@ -24,15 +24,16 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Given a swatch name from bootswatch.com and a parent theme, creates a custom theme."""
"""Given a swatch name from bootswatch.com or hackerthemes.com and a parent
theme, creates a custom theme."""

import os
import requests

from nikola.plugin_categories import Command
from nikola import utils

LOGGER = utils.get_logger('bootswatch_theme')
LOGGER = utils.get_logger('sub_theme')


def _check_for_theme(theme, themes):
Expand All @@ -42,12 +43,12 @@ def _check_for_theme(theme, themes):
return False


class CommandBootswatchTheme(Command):
class CommandSubTheme(Command):
"""Given a swatch name from bootswatch.com and a parent theme, creates a custom theme."""

name = "bootswatch_theme"
name = "sub_theme"
doc_usage = "[options]"
doc_purpose = "given a swatch name from bootswatch.com and a parent theme, creates a custom"\
doc_purpose = "given a swatch name from bootswatch.com or hackerthemes.com and a parent theme, creates a custom"\
" theme"
cmd_options = [
{
Expand Down Expand Up @@ -93,27 +94,43 @@ def _execute(self, options, args):
elif _check_for_theme('bootstrap4', themes) or _check_for_theme('bootstrap4-jinja', themes):
version = '4'
elif not _check_for_theme('bootstrap4', themes) and not _check_for_theme('bootstrap4-jinja', themes):
LOGGER.warn('"bootswatch_theme" only makes sense for themes that use bootstrap')
LOGGER.warn(
'"sub_theme" only makes sense for themes that use bootstrap')
elif _check_for_theme('bootstrap3-gradients', themes) or _check_for_theme('bootstrap3-gradients-jinja', themes):
LOGGER.warn('"bootswatch_theme" doesn\'t work well with the bootstrap3-gradients family')
LOGGER.warn(
'"sub_theme" doesn\'t work well with the bootstrap3-gradients family')

LOGGER.info("Creating '{0}' theme from '{1}' and '{2}'".format(name, swatch, parent))
LOGGER.info("Creating '{0}' theme from '{1}' and '{2}'".format(
name, swatch, parent))
utils.makedirs(os.path.join('themes', name, 'assets', 'css'))
for fname in ('bootstrap.min.css', 'bootstrap.css'):
url = 'https://bootswatch.com'
if version:
url += '/' + version
url = '/'.join((url, swatch, fname))
if swatch in [
'bubblegum', 'business-tycoon', 'charming', 'daydream',
'executive-suite', 'good-news', 'growth', 'harbor', 'hello-world',
'neon-glow', 'pleasant', 'retro', 'vibrant-sea', 'wizardry']: # Hackerthemes
if version != '4':
LOGGER.error('The hackertheme subthemes are only available for Bootstrap 4.')
return 1
if fname == 'bootstrap.css':
url = 'https://raw.githubusercontent.com/HackerThemes/theme-machine/master/dist/{swatch}/css/bootstrap4-{swatch}.css'.format(swatch=swatch)
else:
url = 'https://raw.githubusercontent.com/HackerThemes/theme-machine/master/dist/{swatch}/css/bootstrap4-{swatch}.min.css'.format(swatch=swatch)
else: # Bootswatch
url = 'https://bootswatch.com'
if version:
url += '/' + version
url = '/'.join((url, swatch, fname))
LOGGER.info("Downloading: " + url)
r = requests.get(url)
if r.status_code > 299:
LOGGER.error('Error {} getting {}', r.status_code, url)
exit(1)
return 1
data = r.text
with open(os.path.join('themes', name, 'assets', 'css', fname),
'wb+') as output:
output.write(data.encode('utf-8'))

with open(os.path.join('themes', name, 'parent'), 'wb+') as output:
output.write(parent.encode('utf-8'))
LOGGER.notice('Theme created. Change the THEME setting to "{0}" to use it.'.format(name))
LOGGER.notice(
'Theme created. Change the THEME setting to "{0}" to use it.'.format(name))

0 comments on commit ebcdb2d

Please sign in to comment.