Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Start to support bundles in plugins
  • Loading branch information
ralsina committed May 3, 2015
1 parent 0b93441 commit c217059
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,7 @@ New in master
Features
--------

* Plugins can declare JS and CSS assets to be bundled (Issue #656)
* Compatibility with doit v0.28.0 (Issue #1655)
* AddThis is no longer added by default to users’ sites
* New translations (az, fil, tl, uk, zh_TW)
Expand Down
1 change: 0 additions & 1 deletion nikola/plugin_categories.py
Expand Up @@ -75,7 +75,6 @@ def inject_templates(self):
# so let’s just ignore it and be done with it.
pass


class Command(BasePlugin, DoitCommand):
"""These plugins are exposed via the command line.
They implement the doit Command interface."""
Expand Down
33 changes: 28 additions & 5 deletions nikola/plugins/task/bundles.py
Expand Up @@ -118,13 +118,19 @@ def build_bundle(output, inputs):
yield utils.apply_filters(task, kw['filters'])


def get_theme_bundles(themes):
def get_all_bundles(site):
"""Given a theme chain, return the bundle definitions."""
bundles = {}
for theme_name in themes:
bundles_path = os.path.join(
utils.get_theme_path(theme_name), 'bundles')
if os.path.isfile(bundles_path):
themes = filter(
os.path.isfile,
[os.path.join(utils.get_theme_path(theme_name), 'bundles') for theme_name in site.THEMES]
)
plugins = filter(
os.path.isfile,
[os.path.join(p.path, 'bundles') for p in site.plugin_manager.getAllPlugins()]
)

for bundles_path in themes:
with open(bundles_path) as fd:
for line in fd:
try:
Expand All @@ -136,3 +142,20 @@ def get_theme_bundles(themes):
pass
break
return bundles

def get_plugin_bundles(site):
"""Get all the bundles declared by all the plugins in the site."""
bundles = {}

bundles_paths = filter(os.path.isfile, bundles_paths)
for p in bundles_paths:
with open(p) as fd:
for line in fd:
try:
name, files = line.split('=')
files = [f.strip() for f in files.split(',')]
bundles[name.strip().replace('/', os.sep)] = files
except ValueError:
# for empty lines
pass
return bundles

0 comments on commit c217059

Please sign in to comment.