# 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 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 the file where the types are documented. attr_accessor :types_url # The base URL for the file where the backends are documented. # # \todo maybe this should be turned into a directory, and each # file would document a backend on its own ? That would make # sense, but that would be rather difficult, I have to admit. attr_accessor :backends_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" @backends_url = "backends.html" @functions_url = "functions.html" end def write_page_menu(opts, out) if !opts['page-menu'] or opts['page-menu'] =~ /menu|full/i yield out end end def write_page(opts, out) if !opts['page-menu'] or opts['page-menu'] =~ /page|full/i yield out end end def write_functions(opts, out = STDOUT) funcs = @doc.functions names = funcs.keys.sort write_page_menu(opts, out) do |out| 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]} |
#{b.name}
: #{b.long_name}/#{param.name}=#{param.type.name}
#{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}" }.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|
"#{cmd.normalize_option_name(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