diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-08-23 22:38:13 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-08-23 22:38:13 -0400 |
commit | 091ba8382e30cbde2bb0a0c2001c0d213fdfd33c (patch) | |
tree | bfb628a3c12fb8402a6d2f24fe836f444604cba6 /lib |
initial commit
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pandoc.rb | 77 | ||||
-rw-r--r-- | lib/template.erb | 51 |
2 files changed, 128 insertions, 0 deletions
diff --git a/lib/pandoc.rb b/lib/pandoc.rb new file mode 100644 index 0000000..9c12351 --- /dev/null +++ b/lib/pandoc.rb @@ -0,0 +1,77 @@ +require 'open3' +require 'json' + +module Pandoc + def self.prog + @prog ||= 'pandoc' + end + def self.prog=(val) + @prog = val + end + def self.load(fmt, input) + cmd = Pandoc::prog + " -t json" + unless fmt.nil? + cmd += " -f " + fmt + end + str = input + if str.respond_to? :read + str = str.read + end + json = '' + errors = '' + Open3::popen3(cmd) do |stdin, stdout, stderr| + stdin.puts(str) + stdin.close + json = stdout.read + errors = stderr.read + end + unless errors.empty? + raise errors + end + return Pandoc::AST::new(json) + end + + class AST + def initialize(json) + @js = JSON::parse(json) + end + + def [](key) + Pandoc::AST::js2sane(@js[0]["unMeta"][key]) + end + + def to(format) + cmd = Pandoc::prog + " -f json -t " + format.to_s + output = '' + errors = '' + Open3::popen3(cmd) do |stdin, stdout, stderr| + stdin.puts @js.to_json + stdin.close + output = stdout.read + errors = stderr.read + end + unless errors.empty? + raise errors + end + return output + end + + def self.js2sane(js) + if js.nil? + return js + end + case js["t"] + when "MetaList" + js["c"].map{|c| js2sane(c)} + when "MetaInlines" + js["c"].map{|c| js2sane(c)}.join() + when "Space" + " " + when "MetaString" + js["c"] + when "Str" + js["c"] + end + end + end +end diff --git a/lib/template.erb b/lib/template.erb new file mode 100644 index 0000000..19f018f --- /dev/null +++ b/lib/template.erb @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <!-- the meta tags must come first --> + + <title><%= @title %></title> + + <link href="/style.css" rel="stylesheet"> + <%= @head %> + </head> + <body> + <header> + <h1> + <img src="/logos/brass-bull.png"/> + <img src="/header-path.svg" alt="4272 Maverick Boiler Robotics"/> + </h1> + <nav> + <ul> + <li><a href="/">Home</a></li> + <li><a href="javascript:">Collaboration Tools</a> + <ul> + <li><a href="https://git.team4272.com/">Git</a></li> + <li><a href="https://owncloud.team4272.com/">ownCloud</a></li> + <li><a href="https://ethercalc.team4272.com/">EtherCalc</a></li> + </ul> + </li> + <li><a href="/safety">Safety App</a></li> + </ul> + </nav> + </header> + <article> + <%= @body %> + </article> + <footer> + <table> + <tr> + <td> + This is where we would put our sponsors. IF WE HAD ANY! + </td> + <td> + <img style="float:right; max-height: 150px" + src="/trophies.jpg"> + </td> + </tr> + </table> + </footer> + </body> +</html> |