From 091ba8382e30cbde2bb0a0c2001c0d213fdfd33c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 23 Aug 2016 22:38:13 -0400 Subject: initial commit --- lib/pandoc.rb | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/template.erb | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 lib/pandoc.rb create mode 100644 lib/template.erb (limited to 'lib') 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 @@ + + + + + + + + + <%= @title %> + + + <%= @head %> + + +
+

+ + 4272 Maverick Boiler Robotics +

+ +
+
+ <%= @body %> +
+ + + -- cgit v1.2.3-54-g00ecf