[meld] Add script for generating web-embeddable help



commit 5aa136741ddcecb8834db99f48831773ed53c06e
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Mon Jun 11 18:46:06 2012 +1000

    Add script for generating web-embeddable help
    
    Mallard's generated HTML help looks great on its own, but it's not
    really directly embeddable into another website without some
    modifications. Rather than write a new XSLT transformation (...) this
    commit adds a simple script that pulls out the requisite bits of HTML,
    and perform some CSS munging to get the rules to fit into Meld's
    existing web site without too much weirdness.
    
    In order to run, this script requires Python's BeautifulSoup 4 module,
    and a command-line executable copy of Sass.
    
    There's a reason I used Sass for this at the time, but now I can't for
    the life of me remember why.

 help/C/buildwebhelp.py |  122 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 122 insertions(+), 0 deletions(-)
---
diff --git a/help/C/buildwebhelp.py b/help/C/buildwebhelp.py
new file mode 100755
index 0000000..3af1914
--- /dev/null
+++ b/help/C/buildwebhelp.py
@@ -0,0 +1,122 @@
+#! /usr/bin/python
+
+import glob
+import os
+import subprocess
+import sys
+
+from bs4 import BeautifulSoup as bs
+
+
+JEKYLL_HEADER = """---
+layout: help
+title: Meld - Help
+---
+"""
+
+SCSS_HEADER = """
+#help-content {
+  border-left: solid 1px #e0e0df;
+  border-right: solid 1px #e0e0df;
+  background-color: #ffffff;
+}
+
+#help-content div.body {
+  border: none !important; }
+
+#help-content div.headbar {
+  margin: 10px !important;
+}
+
+#help-content div.footbar {
+  margin: 10px !important;
+}
+
+#help-content {
+
+.title {
+  line-height: 1em;
+}
+
+h1 {
+  font-family: sans-serif;
+  font-weight: bold;
+  text-shadow: none;
+  color: black;
+}
+
+h2 {
+  font-family: sans-serif;
+  text-shadow: none;
+  color: black;
+}
+"""
+
+SCSS_FOOTER = """
+}
+"""
+
+
+def munge_html(filename):
+    if not os.path.exists(filename):
+        print >> sys.stderr, "File not found: " + filename
+        sys.exit(1)
+
+    with open(filename) as f:
+        contents = f.read()
+
+    soup = bs(contents)
+    body = "".join([str(tag) for tag in soup.body])
+    body = JEKYLL_HEADER + body
+
+    print "Rewriting " + filename
+    with open(filename, "w") as f:
+        f.write(body)
+
+
+def munge_css(filename):
+
+    if not os.path.exists(filename):
+        print >> sys.stderr, "File not found: " + filename
+        sys.exit(1)
+
+    with open(filename) as f:
+        contents = f.read()
+
+    contents = SCSS_HEADER + contents + SCSS_FOOTER
+    new_css = sassify(contents)
+
+    print "Rewriting " + filename
+    with open(filename, 'w') as f:
+        f.write(new_css)
+
+
+def sassify(scss_string):
+    scss = subprocess.Popen(['scss', '-s'],
+                            stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+    stdout, stderr = scss.communicate(scss_string)
+    return stdout
+
+
+if __name__ == "__main__":
+
+    if os.path.exists('html'):
+        print >> sys.stderr, "Refusing to overwrite existing html/ folder"
+        sys.exit(1)
+
+    print >> sys.stderr, "Generating CSS with gnome-doc-tool..."
+    subprocess.check_call(['gnome-doc-tool', 'css'])
+
+    print >> sys.stderr, "Generating HTML with gnome-doc-tool..."
+    subprocess.check_call(['gnome-doc-tool', 'html', '-c', 'index.css',
+                           '--copy-graphics', '*.page'])
+
+    os.mkdir('html')
+    for filename in glob.glob('*.html'):
+        munge_html(filename)
+        os.rename(filename, os.path.join('html', filename))
+
+    munge_css('index.css')
+    os.rename('index.css', os.path.join('html', 'index.css'))
+
+    print >> sys.stderr, "Embeddable documentation written to html/"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]