# html.rb: html output for internal documentation # copyright (c) 2009 by Vincent Fourmond # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details (in the COPYING file). require 'ctioga2/utils' require 'ctioga2/commands/commands' module CTioga2 Version::register_svn_info('$Revision: 77 $', '$Date: 2009-06-05 00:20:49 +0200 (Fri, 05 Jun 2009) $') module Commands module Documentation # Generation of XHTML snippets (not full pages) that document # the commands/groups and types known to CTioga2. class HTML # The Doc object the HTML class should document attr_accessor :doc # The base URL for file where types are documented. attr_accessor :types_url # The base URL for file where commands and groups are # documented. attr_accessor :commands_url def initialize(doc) @doc = doc @types_url = "types.html" @commands_url = "commands.html" end # Ouputs HTML code to document all groups and commands def write_commands(out = STDOUT) cmds, groups = @doc.documented_commands out.puts "
"
out.puts "Available commands:\n"
out.puts commands.map {|c|
"#{c.name}
"
}.join(' ')
out.puts "
#{g.name} | ||
---|---|---|
#{link}#{opts[0]} | "
out.puts "#{link}#{opts[1]} | "
out.puts "#{opts[2]} |
#{cmd.name}
\nSynopsis (file)\n" str << "
\n"
str << "#{cmd.name}("
str << cmd.arguments.map { |arg|
"#{arg.displayed_name}"
}.join(',')
if cmd.has_options?
if(cmd.arguments.size > 0)
str << ", "
end
str << "option=..."
end
str << ")\n"
str << "
\n"
# Command-line file synopsis
str << "\nSynopsis (command-line)\n" args = cmd.arguments.map { |arg| "#{arg.displayed_name.upcase}" }.join(' ') if cmd.has_options? args << " /option=..." end str << "
\n" if cmd.short_option str << "-#{cmd.short_option} " str << args str << "\n" end str << "--#{cmd.long_option} " str << args str << "\n" str << "" if cmd.has_options? str << "
Available options:\n"
opts = cmd.optional_arguments.sort.map do |k,arg|
"#{k}
\n"
end
str << opts.join(' ')
str << "
\n#{markup_to_html(it.elements)}\n
\n" when MarkedUpText::MarkupVerbatim str << "#{it.text}\n" else raise "Markup #{it.class} isn't implemented yet for HTML" end end return str end end end end end