require 'yaml' require 'redcloth' def process_faq_list( faqs ) puts "" end def process_faq_list_item( faq ) question = faq.keys.first answer = faq.values.first print "
  • " question_text = RedCloth.new(question).to_html.gsub( %r{},"" ) if answer.is_a?( Array ) puts question_text process_faq_list answer else print "#{question_text}" end puts "
  • " end def process_faq_descriptions( faqs, path=nil ) faqs.each do |faq| process_faq_description faq, path end end def process_faq_description( faq, path ) question = faq.keys.first path = ( path ? path + " " : "" ) + question answer = faq.values.first if answer.is_a?( Array ) process_faq_descriptions( answer, path ) else title = RedCloth.new( path ).to_html.gsub( %r{}, "" ) answer = RedCloth.new( answer || "" ) puts "" puts "
    #{title}
    " puts "
    #{add_api_links(answer.to_html)}
    " end end API_OBJECTS = [ "Database", "Statement", "ResultSet", "ParsedStatement", "Pragmas", "Translator" ].inject( "(" ) { |acc,name| acc << "|" if acc.length > 1 acc << name acc } + ")" def add_api_links( text ) text.gsub( /#{API_OBJECTS}(#(\w+))?/ ) do disp_obj = obj = $1 case obj when "Pragmas"; disp_obj = "Database" end method = $3 s = "#{disp_obj}" s << "##{method}" if method s << "" s end end faqs = YAML.load( File.read( "faq.yml" ) ) puts <<-EOF SQLite3/Ruby FAQ

    SQLite/Ruby FAQ

    EOF process_faq_list( faqs ) puts "
    " process_faq_descriptions( faqs ) puts ""