1
0
Fork 0
forked from github/pelican

plugins initial support

This commit is contained in:
Nicolas Duhamel 2011-04-27 13:08:36 +02:00
commit 1085e0b2f1
8 changed files with 104 additions and 3 deletions

View file

@ -1,5 +1,8 @@
import argparse
import os
import pkgutil
from blinker import signal
from pelican.generators import (ArticlesGenerator, PagesGenerator,
StaticGenerator, PdfGenerator)
@ -13,7 +16,7 @@ VERSION = "2.6.0"
class Pelican(object):
def __init__(self, settings=None, path=None, theme=None, output_path=None,
markup=None, keep=False):
markup=None, keep=False, plugins_path=None):
"""Read the settings, and performs some checks on the environment
before doing anything else.
"""
@ -41,6 +44,15 @@ class Pelican(object):
self.theme = theme_path
else:
raise Exception("Impossible to find the theme %s" % theme)
plugins_path = plugins_path or settings['PLUGINS_PATH']
if plugins_path:
plugins_path = os.path.abspath(plugins_path)
self.load_plugins(plugins_path)
else:
self.plugins = None
signal('pelican_initialized').send(self)
def run(self):
"""Run the generators and return"""
@ -81,6 +93,13 @@ class Pelican(object):
def get_writer(self):
return Writer(self.output_path, settings=self.settings)
def load_plugins(self,path):
loaded = []
for module_loader, name, ispkg in pkgutil.walk_packages(path=[path,]):
loaded.append( module_loader.find_module(name).load_module(name) )
self.plugins = loaded
@ -116,6 +135,8 @@ def main():
parser.add_argument('-r', '--autoreload', dest='autoreload', action='store_true',
help="Relaunch pelican each time a modification occurs on the content"
"files")
parser.add_argument('-p', '--plugins', default=None, dest='plugins_path',
help='the path of plugins to use')
args = parser.parse_args()
log.init(args.verbosity)
@ -134,7 +155,7 @@ def main():
cls = getattr(module, cls_name)
try:
pelican = cls(settings, args.path, args.theme, args.output, markup, args.keep)
pelican = cls(settings, args.path, args.theme, args.output, markup, args.keep, args.plugins_path)
if args.autoreload:
while True:
try:

View file

@ -8,6 +8,8 @@ import os
import math
import random
from blinker import signal
from jinja2 import Environment, FileSystemLoader
from jinja2.exceptions import TemplateNotFound
@ -92,6 +94,7 @@ class ArticlesGenerator(Generator):
self.dates = {}
self.tags = defaultdict(list)
self.categories = defaultdict(list)
self.signal = {'pelican_article_generate_context' : signal('pelican_article_generate_context')}
super(ArticlesGenerator, self).__init__(*args, **kwargs)
def generate_feeds(self, writer):
@ -200,6 +203,8 @@ class ArticlesGenerator(Generator):
and self.settings['FALLBACK_ON_FS_DATE']:
metadatas['date'] = datetime.fromtimestamp(os.stat(f).st_ctime)
self.signal['pelican_article_generate_context'].send(self, metadatas=metadatas)
article = Article(content, metadatas, settings=self.settings,
filename=f)
if not is_valid_content(article, f):

View file

@ -49,9 +49,14 @@ class RstReader(Reader):
rendered_content = core.publish_parts(text, writer_name='html',
settings_overrides=extra_params)
title = rendered_content.get('title')
subtitle = rendered_content.get('subtitle') or ''
content = rendered_content.get('body')
if not metadatas.has_key('title'):
metadatas['title'] = title
if not metadatas.has_key('subtitle'):
metadatas['subtitle'] = subtitle
return content, metadatas
class MarkdownReader(Reader):

View file

@ -37,6 +37,7 @@ _DEFAULT_CONFIG = {'PATH': None,
'WITH_PAGINATION': False,
'DEFAULT_PAGINATION': 5,
'DEFAULT_ORPHANS': 0,
'PLUGINS_PATH': None,
}
def read_settings(filename):