Permalink
Browse files

Added automatic module import, renamed Processor

  • Loading branch information...
1 parent 6eab21f commit a168ee5890e24add07e23a9b181d81f77f44cf4f @jreese committed May 19, 2010
Showing with 30 additions and 7 deletions.
  1. +22 −0 MarkdownPP/Modules/__init__.py
  2. +2 −3 MarkdownPP/{Process.py → Processor.py}
  3. +2 −1 MarkdownPP/__init__.py
  4. +4 −3 mdpp.py
@@ -0,0 +1,22 @@
+# Copyright (C) 2010 John Reese
+# Licensed under the MIT license
+
+import os
+from os import path
+
+modules = {}
+
+def load_modules():
+ dirname = path.dirname(path.abspath(__file__))
+ filenames = os.listdir(dirname)
+
+ for filename in os.listdir(dirname):
+ (modulename, extension) = path.splitext(filename)
+ if extension.lower() == ".py" and modulename.lower() != "__init__":
+ module = __import__("MarkdownPP.Modules.%s" % modulename, fromlist=[modulename])
+ if modulename in dir(module):
+ nickname = modulename.lower()
+ modules[nickname] = module.__dict__[modulename]
+
+load_modules()
+
@@ -1,8 +1,7 @@
# Copyright (C) 2010 John Reese
# Licensed under the MIT license
-
-class Process:
+class Processor:
"""
Framework for allowing modules to modify the input data as a set of transforms.
Once the original input data is loaded, the preprocessor iteratively allows
@@ -11,7 +10,7 @@ class Process:
data is used for the next pass. Once all modules have transformed the data, it
is ready for writing out to a file.
"""
-
+
data = []
transforms = {}
modules = []
View
@@ -1,7 +1,8 @@
# Copyright (C) 2010 John Reese
# Licensed under the MIT license
-from Process import Process
+from Processor import Processor
from Module import Module
from Transform import Transform
+from Modules import modules
View
@@ -4,10 +4,11 @@
mdpp = open("readme.mdpp","r")
md = open("readme","w")
-module = MarkdownPP.Module()
+classdef = MarkdownPP.modules["include"]
+module = classdef()
-pp = MarkdownPP.Process()
-pp.register(module)
+pp = MarkdownPP.Processor()
+#pp.register(module)
pp.input(mdpp)
pp.process()

0 comments on commit a168ee5

Please sign in to comment.