summaryrefslogtreecommitdiffstats
path: root/cloudmasterd/script/txt2html
diff options
context:
space:
mode:
authorroot <root@hackathon1-repo.usersys.redhat.com>2008-06-19 15:36:54 -0400
committerroot <root@hackathon1-repo.usersys.redhat.com>2008-06-19 15:36:54 -0400
commitcf796141ac01c866e81663f20699ccd56ce2d50b (patch)
tree9061bb3c95d638bfed4d880db21e49f9f36cf1ec /cloudmasterd/script/txt2html
parent4f244d65c5c2e4ffb4b38e00baa5f83de89c20d8 (diff)
downloadtools-cf796141ac01c866e81663f20699ccd56ce2d50b.tar.gz
tools-cf796141ac01c866e81663f20699ccd56ce2d50b.tar.xz
tools-cf796141ac01c866e81663f20699ccd56ce2d50b.zip
Moved the cloud daemon to cloudmasterd to give it a better name
Diffstat (limited to 'cloudmasterd/script/txt2html')
-rwxr-xr-xcloudmasterd/script/txt2html74
1 files changed, 74 insertions, 0 deletions
diff --git a/cloudmasterd/script/txt2html b/cloudmasterd/script/txt2html
new file mode 100755
index 0000000..1682173
--- /dev/null
+++ b/cloudmasterd/script/txt2html
@@ -0,0 +1,74 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+begin
+ require 'newgem'
+rescue LoadError
+ puts "\n\nGenerating the website requires the newgem RubyGem"
+ puts "Install: gem install newgem\n\n"
+ exit(1)
+end
+require 'redcloth'
+require 'syntax/convertors/html'
+require 'erb'
+require File.dirname(__FILE__) + '/../lib/cloudmasterd/version.rb'
+
+version = Everestd::VERSION::STRING
+download = 'http://rubyforge.org/projects/cloudmasterd'
+
+class Fixnum
+ def ordinal
+ # teens
+ return 'th' if (10..19).include?(self % 100)
+ # others
+ case self % 10
+ when 1: return 'st'
+ when 2: return 'nd'
+ when 3: return 'rd'
+ else return 'th'
+ end
+ end
+end
+
+class Time
+ def pretty
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
+ end
+end
+
+def convert_syntax(syntax, source)
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
+end
+
+if ARGV.length >= 1
+ src, template = ARGV
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
+
+else
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
+ exit!
+end
+
+template = ERB.new(File.open(template).read)
+
+title = nil
+body = nil
+File.open(src) do |fsrc|
+ title_text = fsrc.readline
+ body_text = fsrc.read
+ syntax_items = []
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
+ ident = syntax_items.length
+ element, syntax, source = $1, $2, $3
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
+ "syntax-temp-#{ident}"
+ }
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
+ body = RedCloth.new(body_text).to_html
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
+end
+stat = File.stat(src)
+created = stat.ctime
+modified = stat.mtime
+
+$stdout << template.result(binding)