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 /bin/pagerender |
initial commit
Diffstat (limited to 'bin/pagerender')
-rwxr-xr-x | bin/pagerender | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/bin/pagerender b/bin/pagerender new file mode 100755 index 0000000..a4ce6a1 --- /dev/null +++ b/bin/pagerender @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- +require 'erb' +require 'date' + +load 'pandoc.rb' +Pandoc::prog='pandoc' + +def erb(file, context=nil) + _erb = ERB.new(File.read(file)) + _erb.filename = file + if context.nil? + return _erb.result() + else + return _erb.result(context) + end +end + +template = 'lib/template.erb' +infile = ARGV.first +input = File.read(infile) + +@title = 'TITLE GOES HERE' + +case File.extname(infile) +when '.md' + doc = Pandoc::load('markdown', input) + @title = doc['title'] || input.split("\n",2).first + @body = doc.to('html5') +when '.org' + doc = Pandoc::load('org', input) + @title = doc['title'] || input.split("\n",2).first + @body = doc.to('html5') +when '.erb' + erb_body = ERB.new(input) + erb_body.filename = infile + @body = erb_body.result() +else + abort +end + +erb = ERB.new(File.read(template)); +erb.filename = template +erb.run() |