mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
integrate webassets
This commit is contained in:
parent
d97fc8f666
commit
a6788f83c2
3 changed files with 30 additions and 5 deletions
|
|
@ -126,12 +126,15 @@ class Pelican(object):
|
||||||
|
|
||||||
writer = self.get_writer()
|
writer = self.get_writer()
|
||||||
|
|
||||||
|
generators[1].env.assets_environment = generators[0].assets_env
|
||||||
|
generators[2].env.assets_environment = generators[0].assets_env
|
||||||
|
|
||||||
for p in generators:
|
for p in generators:
|
||||||
if hasattr(p, 'generate_output'):
|
if hasattr(p, 'generate_output'):
|
||||||
p.generate_output(writer)
|
p.generate_output(writer)
|
||||||
|
|
||||||
def get_generator_classes(self):
|
def get_generator_classes(self):
|
||||||
generators = [ArticlesGenerator, PagesGenerator, StaticGenerator]
|
generators = [StaticGenerator, ArticlesGenerator, PagesGenerator]
|
||||||
if self.settings['PDF_GENERATOR']:
|
if self.settings['PDF_GENERATOR']:
|
||||||
generators.append(PdfGenerator)
|
generators.append(PdfGenerator)
|
||||||
if self.settings['LESS_GENERATOR']: # can be True or PATH to lessc
|
if self.settings['LESS_GENERATOR']: # can be True or PATH to lessc
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class Generator(object):
|
||||||
|
|
||||||
simple_loader = FileSystemLoader(os.path.join(theme_path,
|
simple_loader = FileSystemLoader(os.path.join(theme_path,
|
||||||
"themes", "simple", "templates"))
|
"themes", "simple", "templates"))
|
||||||
self._env = Environment(
|
self.env = Environment(
|
||||||
loader=ChoiceLoader([
|
loader=ChoiceLoader([
|
||||||
FileSystemLoader(self._templates_path),
|
FileSystemLoader(self._templates_path),
|
||||||
simple_loader, # implicit inheritance
|
simple_loader, # implicit inheritance
|
||||||
|
|
@ -51,11 +51,11 @@ class Generator(object):
|
||||||
extensions=self.settings.get('JINJA_EXTENSIONS', []),
|
extensions=self.settings.get('JINJA_EXTENSIONS', []),
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.debug('template list: {0}'.format(self._env.list_templates()))
|
logger.debug('template list: {0}'.format(self.env.list_templates()))
|
||||||
|
|
||||||
# get custom Jinja filters from user settings
|
# get custom Jinja filters from user settings
|
||||||
custom_filters = self.settings.get('JINJA_FILTERS', {})
|
custom_filters = self.settings.get('JINJA_FILTERS', {})
|
||||||
self._env.filters.update(custom_filters)
|
self.env.filters.update(custom_filters)
|
||||||
|
|
||||||
def get_template(self, name):
|
def get_template(self, name):
|
||||||
"""Return the template by name.
|
"""Return the template by name.
|
||||||
|
|
@ -64,7 +64,7 @@ class Generator(object):
|
||||||
"""
|
"""
|
||||||
if name not in self._templates:
|
if name not in self._templates:
|
||||||
try:
|
try:
|
||||||
self._templates[name] = self._env.get_template(name + '.html')
|
self._templates[name] = self.env.get_template(name + '.html')
|
||||||
except TemplateNotFound:
|
except TemplateNotFound:
|
||||||
raise Exception('[templates] unable to load %s.html from %s' \
|
raise Exception('[templates] unable to load %s.html from %s' \
|
||||||
% (name, self._templates_path))
|
% (name, self._templates_path))
|
||||||
|
|
@ -364,7 +364,20 @@ class StaticGenerator(Generator):
|
||||||
copy(path, source, os.path.join(output_path, destination),
|
copy(path, source, os.path.join(output_path, destination),
|
||||||
final_path, overwrite=True)
|
final_path, overwrite=True)
|
||||||
|
|
||||||
|
def generate_context(self):
|
||||||
|
|
||||||
|
if self.settings['WEBASSETS']:
|
||||||
|
from webassets import Environment as AssetsEnvironment
|
||||||
|
|
||||||
|
assets_url = self.settings['SITEURL'] + '/theme/'
|
||||||
|
assets_src = os.path.join(self.output_path, 'theme')
|
||||||
|
self.assets_env = AssetsEnvironment(assets_src, assets_url)
|
||||||
|
|
||||||
|
if logging.getLevelName(logger.getEffectiveLevel()) == "DEBUG":
|
||||||
|
self.assets_env.debug = True
|
||||||
|
|
||||||
def generate_output(self, writer):
|
def generate_output(self, writer):
|
||||||
|
|
||||||
self._copy_paths(self.settings['STATIC_PATHS'], self.path,
|
self._copy_paths(self.settings['STATIC_PATHS'], self.path,
|
||||||
'static', self.output_path)
|
'static', self.output_path)
|
||||||
self._copy_paths(self.settings['THEME_STATIC_PATHS'], self.theme,
|
self._copy_paths(self.settings['THEME_STATIC_PATHS'], self.theme,
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ _DEFAULT_CONFIG = {'PATH': '.',
|
||||||
'ARTICLE_PERMALINK_STRUCTURE': '',
|
'ARTICLE_PERMALINK_STRUCTURE': '',
|
||||||
'TYPOGRIFY': False,
|
'TYPOGRIFY': False,
|
||||||
'LESS_GENERATOR': False,
|
'LESS_GENERATOR': False,
|
||||||
|
'WEBASSETS': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -150,4 +151,12 @@ def configure_settings(settings, default_settings=None, filename=None):
|
||||||
"http://docs.notmyidea.org/alexis/pelican/settings.html#timezone "
|
"http://docs.notmyidea.org/alexis/pelican/settings.html#timezone "
|
||||||
"for more information")
|
"for more information")
|
||||||
|
|
||||||
|
if settings['WEBASSETS']:
|
||||||
|
try:
|
||||||
|
from webassets.ext.jinja2 import AssetsExtension
|
||||||
|
settings['JINJA_EXTENSIONS'].append(AssetsExtension)
|
||||||
|
except ImportError:
|
||||||
|
logger.warn("You must install the webassets module to use WEBASSETS.")
|
||||||
|
settings['WEBASSETS'] = False
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue