lib/ctioga2/commands/doc/html.rb in ctioga2-0.0 vs lib/ctioga2/commands/doc/html.rb in ctioga2-0.1

- old
+ new

@@ -14,11 +14,11 @@ 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) $') + Version::register_svn_info('$Revision: 216 $', '$Date: 2010-12-31 16:18:17 +0100 (Fri, 31 Dec 2010) $') module Commands module Documentation @@ -27,21 +27,29 @@ class HTML # The Doc object the HTML class should document attr_accessor :doc - # The base URL for file where types are documented. + # 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" end # Ouputs HTML code to document all groups and commands def write_commands(out = STDOUT) cmds, groups = @doc.documented_commands @@ -123,10 +131,38 @@ # in a paragraph. end end + # Ouputs HTML code to all backends + def write_backends(out = STDOUT) + backends = @doc.backends.sort.map { |d| d[1]} + + + out.puts "<div class='quick-jump'>" + out.puts "Quick jump to a specific backend:\n" + out.puts "<ul>\n" + for b in backends + out.puts "<li><a href='#backend-#{b.name}'>#{b.name}</a></li>\n" + end + out.puts "</ul>\n" + out.puts "</div>" + + for b in backends + out.puts + out.puts "<h3 id='backend-#{b.name}' class='backend'><code>#{b.name}</code>: #{b.long_name}</h3>\n" + out.puts markup_to_html(b.description) + out.puts + for param in b.param_list + out.puts "<h4 id='backend-#{b.name}-#{param.name}'>Parameter: #{param.name}</h4>" + out.puts "<p><code>/#{param.name}=<a href='#{@types_url}#type-#{param.type.name}'>#{param.type.name}</a></p>" + out.puts markup_to_html(param.description) + end + end + end + + protected # The string that represents a full command def command_documentation(cmd) str = "<h4 class='command' id='command-#{cmd.name}'>Command: <code>#{cmd.name}</code></h4>\n" @@ -180,28 +216,44 @@ # Takes up an array of MarkupItem objects and returns its # equivalent in HTML format. Alternativelely, it can take a # String and feed it to MarkedUpText. # - # TODO: escape correctly the produced HTML code... + # \todo escape correctly the produced HTML code... def markup_to_html(items) if items.is_a? String mup = MarkedUpText.new(@doc, items) return markup_to_html(mup.elements) end str = "" for it in items case it when MarkedUpText::MarkupText - str << it.to_s + el = nil + case it.kind + when :code + el = "code" + end + if el + prefix = "<#{el}>" + suffix = "</#{el}>" + else + prefix = "" + suffix = "" + end + str << "#{prefix}#{it.to_s}#{suffix}" when MarkedUpText::MarkupLink case it.target when Command link = "#{@commands_url}#command-#{it.target.name}" when CommandGroup link = "#{@commands_url}#group-#{it.target.id}" when CommandType link = "#{@types_url}#type-#{it.target.name}" + when Data::Backends::BackendDescription + link = "#{@backends_url}#backend-#{it.target.name}" + when String # plain URL target + link = "#{it.target}" else raise "The link target should be either a group, a command or a type, but is a #{it.target.class}" end str << "<a href='#{link}'>#{it.to_s}</a>" when MarkedUpText::MarkupItemize