$:.unshift '../lib'
require 'yaml'
require 'redcloth'
class String
#
# Flexible HTML escaping
#
def htmlesc!( mode )
gsub!( '&', '&' )
gsub!( '"', '"' ) if mode != :NoQuotes
gsub!( "'", ''' ) if mode == :Quotes
gsub!('<', '<')
gsub!('>', '>')
end
end
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
Textile Quick Reference |
Sections: #{ sections.collect { |s| "#{ s.gsub( /\s/, ' ' ) }" }.join( ' | ' ) } |
HTML
ct = 0
content.each do |section|
section.each do |header, parags|
puts "#{ header } |
" if ct.nonzero?
parags.each do |p|
if p.is_a?( Array ) and p[0] == :example
puts "#{ p[1] } | → | " +
"#{ p[2] } |
"
end
end
end
ct += 1
end
puts "
"
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 "#{ header } |
"
puts "Sections: #{ sections.collect { |s| "#{ s.gsub( /\s/, ' ' ) }" }.join( ' | ' ) } |
"
else
puts "#{ ct }. #{ header } |
"
end
parags.each do |p|
if p.is_a? Array
puts "#{ p[0] } | → | " +
"#{ p[1] } |
| " +
"#{ p[2] } |
"
else
puts ""
puts RedCloth.new( p ).to_html
puts " |
"
end
end
unless ct.zero?
puts " |
"
end
end
ct += 1
end
puts "
"
puts ""
puts ""
end