diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-10-12 13:47:42 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-10-12 13:47:42 -0400 |
commit | 6a42c8de66e3b2dc7293ddeadaa3ee396db2624d (patch) | |
tree | 67a027b892d3122662526504dd6d11e8dea02ca1 /pagerender.rb |
initial commit
Diffstat (limited to 'pagerender.rb')
-rwxr-xr-x | pagerender.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pagerender.rb b/pagerender.rb new file mode 100755 index 0000000..4e6f887 --- /dev/null +++ b/pagerender.rb @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby +require 'rdiscount' +require 'erb' + +license_urls = { + "CC BY-SA-3.0" => 'https://creativecommons.org/licenses/by-sa/3.0/', + 'WTFPL-2' => "http://www.wtfpl.net/txt/copying/", +} + +template = 'template.erb' +input = ARGV.first + +lines = File.read(input).split("\n") + +markdown = '' +tags = {} +for line in lines do + if (line =~ /^:/) + (key, val) = line.sub(/^:/, '').split(/\s+/, 2) + tags[key] = val + else + markdown += "\n"+line + end +end + +@title = tags['title'] || lines.first +@copyright = tags['copyright'] || "Luke Shumaker" +@license = tags['license'] || "CC BY-SA-3.0" +unless license_urls[@license].nil? + @license="<a href=\"#{license_urls[@license]}\">#{@license}</a>" +end + +@content = RDiscount.new(markdown).to_html + +erb = ERB.new(File.read(template)); +erb.filename = template +erb.run() |