Commits

dirkbaechle committed 90c5863

- imported original version by JDMarble from the SCons wiki at http://www.scons.org/wiki/ReStructuredTextBuilder

Comments (0)

Files changed (2)

+import os
+
+env = Environment()
+
+db_site = os.path.join(os.path.expanduser('~'),'.scons','site_scons','site_tools','rest')
+
+env.Install(db_site, '__init__.py')
+
+env.Alias('install', db_site)
+
+import SCons.Builder
+
+from docutils.core import publish_file
+from docutils.frontend import Values
+
+def rst2something(target, source, env, validOptions, writer):
+    # Find variables that can be passed to docutils.
+    settings = dict([item for item in env.items() if item[0] in validOptions])
+
+    # stylesheet and stylesheet_path are mutually exclusive
+    if 'stylesheet' in settings:
+        settings['stylesheet_path'] = None
+
+    for i in range(len(source)):
+        publish_file(source_path=source[i].path,
+                     destination_path=target[i].path,
+                     writer_name=writer,
+                     settings_overrides=settings)
+
+
+def rst2latex(target, source, env):
+    options = ['stylesheet', 'embed_stylesheet']
+    rst2something(target, source, env, options, 'latex')
+    return None
+
+rst2latexBldr = SCons.Builder.Builder(
+    action = rst2latex,
+    suffix = '.tex',
+    src_suffix = '.rst'
+)
+
+def rst2html(target, source, env):
+    options = ['stylesheet', 'embed_stylesheet']
+    rst2something(target, source, env, options, 'html4css1')
+    return None
+
+rst2htmlBldr = SCons.Builder.Builder(
+    action = rst2html,
+    suffix = '.html',
+    src_suffix = '.rst'
+)
+
+def generate(env):
+    env['BUILDERS']['Rst2Latex'] = rst2latexBldr
+    env['BUILDERS']['Rst2Html'] = rst2htmlBldr
+
+
+def exists(env):
+    return env.Detect('rst2latex') or env.Detect('rst2html')
+