Permalink
Browse files

Switched structure for content processor configuration (and the code …

…that reads it) to something more akin to the pre- and post-processor configurations in preparation for reading from a JSON structure.
  • Loading branch information...
1 parent a608734 commit 7c68e0f95c6ebdb14f9c1be756e736455f9d4bb2 @spjwebster committed Nov 24, 2011
Showing with 39 additions and 25 deletions.
  1. +15 −13 lanyon.py
  2. +24 −12 lanyon/__init__.py
View
@@ -1,8 +1,7 @@
#!/usr/bin/env python
-import os, sys
+import os, sys, codecs, json, cherrypy
from optparse import OptionParser
-import cherrypy
from lanyon import Site
#TODO: Load this config from the current working directory
@@ -27,17 +26,20 @@
],
# Content processors
- 'content_processors': {
- ('html','rss','atom'): [
- 'lanyon.content_processors.Jinja2Renderer'
- ],
- ('markdown','mdown','md'): [
- 'lanyon.content_processors.MarkdownRenderer'
- ],
- ('js','css'): [
- 'lanyon.content_processors.IdentityRenderer'
- ]
- },
+ 'content_processors': [
+ {
+ 'class': 'lanyon.content_processors.Jinja2Renderer',
+ 'extensions': ('html','rss','atom'),
+ },
+ {
+ 'class': 'lanyon.content_processors.MarkdownRenderer',
+ 'extensions': ('markdown','mdown','md'),
+ },
+ {
+ 'class': 'lanyon.content_processors.IdentityRenderer',
+ 'extensions': ('js', 'css'),
+ }
+ ],
# Site post-processors
'post_processors': [
View
@@ -29,18 +29,30 @@ def __init__( self, config ):
# Poplate content processors from config
self.content_processors = {}
- try:
- for extensions, processors in self.config['content_processors'].items():
- self.content_processors[ extensions ] = []
- for processor in processors:
- # TODO: Import processor class with try/except to handle import errors
- try:
- processor_class = self._get_class( processor )
- self.content_processors[ extensions ].append( processor_class( config ) )
- except:
- print "### Could not instantiate '" + processor + "' content processor"
- except:
- pass
+ for processor in self.config['content_processors']:
+ processor_class = self._get_class( processor['class'] )
+ try:
+ processor_instance = processor_class( config )
+ for extension in processor['extensions']:
+ if self.content_processors.has_key(extension) == False:
+ self.content_processors[extension] = []
+ self.content_processors[extension].append( processor_instance )
+ except:
+ print "### Could not instantiate '" + processor['class'] + "' content processor"
+
+
+# try:
+# for extensions, processors in self.config['content_processors'].items():
+# self.content_processors[ extensions ] = []
+# for processor in processors:
+# # TODO: Import processor class with try/except to handle import errors
+# try:
+# processor_class = self._get_class( processor )
+# self.content_processors[ extensions ].append( processor_class( config ) )
+# except:
+# print "### Could not instantiate '" + processor + "' content processor"
+# except:
+# pass
# Populate rpost-processors from configuration
self.site_postprocessors = []

0 comments on commit 7c68e0f

Please sign in to comment.