forked from github/pelican
Add some more comments.
This commit is contained in:
parent
9a51102f29
commit
56fb4828d8
1 changed files with 20 additions and 9 deletions
|
|
@ -14,10 +14,14 @@ _TEMPLATES = ('index', 'tag', 'tags', 'article', 'category', 'categories',
|
||||||
|
|
||||||
|
|
||||||
class Generator(object):
|
class Generator(object):
|
||||||
"""Base class generator"""
|
"""Handle all generation process: files writes, feed creation, and this
|
||||||
|
kind of basic stuff"""
|
||||||
|
|
||||||
def __init__(self, settings=None, path=None, theme=None, output_path=None,
|
def __init__(self, settings=None, path=None, theme=None, output_path=None,
|
||||||
markup=None):
|
markup=None):
|
||||||
|
"""Read the settings, and performs some checks on the environement
|
||||||
|
before doing anything else.
|
||||||
|
"""
|
||||||
if settings is None:
|
if settings is None:
|
||||||
settings = {}
|
settings = {}
|
||||||
self.settings = read_settings(settings)
|
self.settings = read_settings(settings)
|
||||||
|
|
@ -46,6 +50,7 @@ class Generator(object):
|
||||||
raise Exception('you need to specify a path to search the docs on !')
|
raise Exception('you need to specify a path to search the docs on !')
|
||||||
|
|
||||||
def run(self, processors):
|
def run(self, processors):
|
||||||
|
"""Get the context from each processor, and then process them"""
|
||||||
context = self.settings.copy()
|
context = self.settings.copy()
|
||||||
processors = [p() for p in processors]
|
processors = [p() for p in processors]
|
||||||
|
|
||||||
|
|
@ -117,7 +122,10 @@ class Generator(object):
|
||||||
print u' [ok] writing %s' % filename
|
print u' [ok] writing %s' % filename
|
||||||
|
|
||||||
def get_templates(self):
|
def get_templates(self):
|
||||||
"""Return the templates to use."""
|
"""Return the templates to use.
|
||||||
|
Use self.theme to get the templates to use, and return a list of
|
||||||
|
templates ready to use with Jinja2.
|
||||||
|
"""
|
||||||
path = os.path.expanduser(os.path.join(self.theme, 'templates'))
|
path = os.path.expanduser(os.path.join(self.theme, 'templates'))
|
||||||
env = Environment(loader=FileSystemLoader(path))
|
env = Environment(loader=FileSystemLoader(path))
|
||||||
templates = {}
|
templates = {}
|
||||||
|
|
@ -125,21 +133,24 @@ class Generator(object):
|
||||||
try:
|
try:
|
||||||
templates[template] = env.get_template('%s.html' % template)
|
templates[template] = env.get_template('%s.html' % template)
|
||||||
except TemplateNotFound:
|
except TemplateNotFound:
|
||||||
raise Exception('Unable to load %s.html from %s' % (
|
raise Exception('[templates] unable to load %s.html from %s' % (
|
||||||
template, path))
|
template, path))
|
||||||
return templates
|
return templates
|
||||||
|
|
||||||
def get_files(self, path, exclude=[]):
|
def get_files(self, path, exclude=[], extensions=None):
|
||||||
"""Return the files to use to use in this generator
|
"""Return a list of files to use, based on rules
|
||||||
|
|
||||||
:param path: the path to search the file on
|
:param path: the path to search the file on
|
||||||
:param exclude: the list of path to exclude
|
:param exclude: the list of path to exclude
|
||||||
"""
|
"""
|
||||||
|
if not extensions:
|
||||||
|
extensions = self.markup
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
for root, dirs, temp_files in os.walk(path, followlinks=True):
|
for root, dirs, temp_files in os.walk(path, followlinks=True):
|
||||||
for e in exclude:
|
for e in exclude:
|
||||||
if e in dirs:
|
if e in dirs:
|
||||||
dirs.remove(e)
|
dirs.remove(e)
|
||||||
files.extend([os.sep.join((root, f)) for f in temp_files
|
files.extend([os.sep.join((root, f)) for f in temp_files
|
||||||
if True in [f.endswith(markup) for markup in self.markup]])
|
if True in [f.endswith(ext) for ext in extensions]])
|
||||||
return files
|
return files
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue