require 'yaml' require 'redcloth' def a_name( phrase ) phrase.downcase. gsub( /\W+/, '-' ) end file_name = ARGV.shift case file_name when 'README' puts <<-HTML RedCloth [Textile Humane Web Text for Ruby] HTML puts RedCloth.new( File.open( file_name ).read ).to_html puts "" puts "" when 'QUICK-REFERENCE' YAML::add_private_type( "example" ) do |type, val| esc = val.dup esc.htmlesc!( :NoQuotes ) [ :example, esc.gsub( /\n/, '
' ), RedCloth.new( val ).to_html ] end content = YAML::load( File.open( 'REFERENCE' ) ) sections = content.collect { |c| c.keys.first } sections.shift puts <<-HTML Textile Quick Reference HTML ct = 0 content.each do |section| section.each do |header, parags| puts "" if ct.nonzero? parags.each do |p| if p.is_a?( Array ) and p[0] == :example puts "" + "" end end end ct += 1 end puts "

Textile Quick Reference

Sections: #{ sections.collect { |s| "#{ s.gsub( /\s/, ' ' ) }" }.join( ' | ' ) }
#{ header }
#{ p[1] }
#{ p[2] }
" puts "" puts "" when 'REFERENCE' YAML::add_private_type( "example" ) do |type, val| esc = val.dup esc.htmlesc!( :NoQuotes ) [ esc.gsub( /\n/, '
' ), RedCloth.new( val ).to_html. gsub( /;(\w)/, '; \1' ). htmlesc!( :NoQuotes ). gsub( /\n/, '
' ), RedCloth.new( val ).to_html ] end content = YAML::load( File.open( file_name ) ) sections = content.collect { |c| c.keys.first } sections.shift puts <<-HTML Textile Reference HTML ct = 0 content.each do |section| section.each do |header, parags| if ct.zero? puts "" puts "" else puts "" end parags.each do |p| if p.is_a? Array puts "" + "" + "" else puts "" end end unless ct.zero? puts "" end end ct += 1 end puts "

#{ header }

Sections: #{ sections.collect { |s| "#{ s.gsub( /\s/, ' ' ) }" }.join( ' | ' ) }
#{ ct }.
#{ header }
#{ p[0] }

#{ p[1] }

#{ p[2] }
" puts RedCloth.new( p ).to_html puts "
" puts "" puts "" end