Ronny Pfannschmidt avatar Ronny Pfannschmidt committed cdb0b63

add a load-all function for loading all rst files in directory tree

Comments (0)

Files changed (2)

articledump/restructuredtext.py

 from datetime import datetime
 from logbook import Logger
 
+from . import rst_directive
+
 log = Logger('archivedump rst loader')
 
 def get_docinfo(docinfo, name, astext=True):
         self.document = document
         self.source = source
         self.root = root
+        self.name = root.bestrelpath(source)
         self.docinfo = next(c for c in document.children if c.__class__ is docinfo)
-        print list(self.docinfo)
 
     @property
     def title(self):
 
 
 
-def load_rst(file, root):
-    document = publish_doctree(file.read(), source_path=root.bestrelpath(file))
-    return Info(document, file, root)
+def load_rst(source, root):
+    document = publish_doctree(source.read(), source_path=root.bestrelpath(file))
+    return Info(document, source, root)
+
+
+def load_all(root):
+    for source in root.visit('*.rst'):
+        yield load_rst(source, root)

testing/test_load_rst.py

-from articledump import load_rst
+from articledump.restructuredtext import load_rst, load_all
 import datetime
 import pprint
 
     assert info.slug == 'shortone'
     assert info.date == datetime.date(2011, 10, 10)
     pprint.pprint(info.build_html_parts())
-    
+
+
+def test_load_all(tmpdir):
+    for name in ['ab', 'ac', 'ad']:
+        tmpdir.join(name + '.rst').write('test')
+
+    all_info = list(load_all(tmpdir))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.