lib/ctioga2/commands/doc/html.rb in ctioga2-0.8 vs lib/ctioga2/commands/doc/html.rb in ctioga2-0.9

- old
+ new

@@ -44,50 +44,91 @@ def initialize(doc) @doc = doc @types_url = "types.html" @commands_url = "commands.html" @backends_url = "backends.html" + @functions_url = "functions.html" end - # Ouputs HTML code to document all groups and commands - def write_commands(out = STDOUT) - cmds, groups = @doc.documented_commands + def write_page_menu(opts, out) + if !opts['page-menu'] or opts['page-menu'] =~ /menu|full/i + yield out + end + end - out.puts "<div class='quick-jump'>" - out.puts "Quick jump to a specific group of commands:\n" - out.puts "<ul>\n" - for g in groups - out.puts "<li><a href='#group-#{g.id}'>#{g.name}</a></li>\n" + def write_page(opts, out) + if !opts['page-menu'] or opts['page-menu'] =~ /page|full/i + yield out end - out.puts "</ul>\n" - out.puts "</div>" + end + + def write_functions(opts, out = STDOUT) + funcs = @doc.functions + names = funcs.keys.sort - for g in groups - out.puts - out.puts "<h3 class='group' id='group-#{g.id}'>#{g.name}</h3>" - out.puts markup_to_html(g.description) + write_page_menu(opts, out) do |out| + out.puts "<div class='quick-jump'>" + out.puts "<h3>Quick jump</h3>" + out.puts "<ul>\n" + for n in names + out.puts "<li><a href='#func-#{n}'>#{n}</a></li>\n" + end + out.puts "</ul>\n" + out.puts "</div>" + end + write_page(opts, out) do |out| + for n in names + f = funcs[n] + out.puts + out.puts "<h3 class='function' id='func-#{n}'>#{n} - #{f.short_description}</h3>" + out.puts markup_to_html(f.description) + end + end + end - commands = cmds[g].sort {|a,b| - a.name <=> b.name - } - - out.puts "<p>" - out.puts "<span class='bold'>Available commands:</span>\n" - out.puts commands.map {|c| - "<a href='#command-#{c.name}'><code>#{c.name}</code></a>" - }.join(' ') - out.puts "</p>" + # Ouputs HTML code to document all groups and commands + def write_commands(opts, out = STDOUT) + cmds, groups = @doc.documented_commands - for cmd in commands - out.puts - out.puts command_documentation(cmd) + write_page_menu(opts, out) do |out| + out.puts "<div class='quick-jump'>" + out.puts "<h3>Quick jump</h3>" + out.puts "<ul>\n" + for g in groups + out.puts "<li><a href='#group-#{g.id}'>#{g.name}</a></li>\n" end + out.puts "</ul>\n" + out.puts "</div>" end + + write_page(opts, out) do |out| + for g in groups + out.puts + out.puts "<h3 class='group' id='group-#{g.id}'>#{g.name}</h3>" + out.puts markup_to_html(g.description) + + commands = cmds[g].sort {|a,b| + a.name <=> b.name + } + + out.puts "<p>" + out.puts "<span class='bold'>Available commands:</span>\n" + out.puts commands.map {|c| + "<a href='#command-#{c.name}'><code>#{c.name}</code></a>" + }.join(' ') + out.puts "</p>" + + for cmd in commands + out.puts + out.puts command_documentation(cmd) + end + end + end end # Write a HTML table documenting all command-line options. - def write_command_line_options(out = STDOUT) + def write_command_line_options(opts, out = STDOUT) cmds, groups = @doc.documented_commands out.puts "<table>" for g in groups out.puts "<tr><th colspan='3'>#{g.name}</th></tr>" @@ -106,56 +147,64 @@ end # Ouputs HTML code to document all types - def write_types(out = STDOUT) + def write_types(opts, out = STDOUT) types = @doc.types.sort.map { |d| d[1]} - out.puts "<div class='quick-jump'>" - out.puts "Quick jump to a specific type:\n" - out.puts "<ul>\n" - for t in types - out.puts "<li><a href='#type-#{t.name}'>#{t.name}</a></li>\n" + write_page_menu(opts, out) do |out| + out.puts "<div class='quick-jump'>" + out.puts "<h3>Quick jump</h3>" + out.puts "<ul>\n" + for t in types + out.puts "<li><a href='#type-#{t.name}'>#{t.name}</a></li>\n" + end + out.puts "</ul>\n" + out.puts "</div>" end - out.puts "</ul>\n" - out.puts "</div>" - for t in types - out.puts - out.puts "<h4 id='type-#{t.name}' class='type'>#{t.name}</h4>\n" - out.puts markup_to_html(t.description) - out.puts # There is no need to wrap the markup - # in a paragraph. + write_page(opts, out) do |out| + for t in types + out.puts + out.puts "<h4 id='type-#{t.name}' class='type'>#{t.name}</h4>\n" + out.puts markup_to_html(t.description) + out.puts # There is no need to wrap the markup + # in a paragraph. + end end end # Ouputs HTML code to all backends - def write_backends(out = STDOUT) + def write_backends(opts, 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" + write_page_menu(opts, out) do |out| + out.puts "<div class='quick-jump'>" + out.puts "<h3>Quick jump</h3>" + 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>" 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) + + write_page(opts, out) do |out| + 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></code></p>" + out.puts markup_to_html(param.description) + end end end end @@ -241,9 +290,11 @@ str << "#{prefix}#{it.to_s}#{suffix}" when MarkedUpText::MarkupLink case it.target when Command link = "#{@commands_url}#command-#{it.target.name}" + when Function + link = "#{@functions_url}#func-#{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