Class: CTioga2::Commands::Documentation::HTML
- Inherits:
-
Object
- Object
- CTioga2::Commands::Documentation::HTML
- Defined in:
- lib/ctioga2/commands/doc/html.rb
Overview
Generation of XHTML snippets (not full pages) that document the commands/groups and types known to CTioga2.
Instance Attribute Summary collapse
-
#commands_url ⇒ Object
The base URL for file where commands and groups are documented.
-
#doc ⇒ Object
The Doc object the HTML class should document.
-
#types_url ⇒ Object
The base URL for file where types are documented.
Instance Method Summary collapse
-
#initialize(doc) ⇒ HTML
constructor
A new instance of HTML.
-
#write_command_line_options(out = STDOUT) ⇒ Object
Write a HTML table documenting all command-line options.
-
#write_commands(out = STDOUT) ⇒ Object
Ouputs HTML code to document all groups and commands.
-
#write_types(out = STDOUT) ⇒ Object
Ouputs HTML code to document all types.
Constructor Details
#initialize(doc) ⇒ HTML
Returns a new instance of HTML.
39 40 41 42 43 |
# File 'lib/ctioga2/commands/doc/html.rb', line 39 def initialize(doc) @doc = doc @types_url = "types.html" @commands_url = "commands.html" end |
Instance Attribute Details
#commands_url ⇒ Object
The base URL for file where commands and groups are documented.
37 38 39 |
# File 'lib/ctioga2/commands/doc/html.rb', line 37 def commands_url @commands_url end |
#doc ⇒ Object
The Doc object the HTML class should document
30 31 32 |
# File 'lib/ctioga2/commands/doc/html.rb', line 30 def doc @doc end |
#types_url ⇒ Object
The base URL for file where types are documented.
33 34 35 |
# File 'lib/ctioga2/commands/doc/html.rb', line 33 def types_url @types_url end |
Instance Method Details
#write_command_line_options(out = STDOUT) ⇒ Object
Write a HTML table documenting all command-line options.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ctioga2/commands/doc/html.rb', line 82 def (out = STDOUT) cmds, groups = @doc.documented_commands out.puts "<table>" for g in groups out.puts "<tr><th colspan='3'>#{g.name}</th></tr>" commands = cmds[g].sort {|a,b| a.long_option <=> b.long_option } for cmd in commands opts = cmd.option_strings link = "<a href='#{@commands_url}#command-#{cmd.name}'>" out.puts "<tr><td><code>#{link}#{opts[0]}</a></code></td>" out.puts "<td><code>#{link}#{opts[1]}</a></code></td>" out.puts "<td>#{opts[2]}</td></tr>" end end out.puts "</table>" end |
#write_commands(out = STDOUT) ⇒ Object
Ouputs HTML code to document all groups and commands
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ctioga2/commands/doc/html.rb', line 46 def write_commands(out = STDOUT) cmds, groups = @doc.documented_commands 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" end out.puts "</ul>\n" out.puts "</div>" 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 |
#write_types(out = STDOUT) ⇒ Object
Ouputs HTML code to document all types
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ctioga2/commands/doc/html.rb', line 105 def write_types(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" 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. end end |