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
-
#backends_url ⇒ Object
The base URL for the file where the backends are documented.
-
#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 the file where the types are documented.
Instance Method Summary collapse
-
#initialize(doc) ⇒ HTML
constructor
A new instance of HTML.
-
#write_backends(opts, out = STDOUT) ⇒ Object
Ouputs HTML code to all backends.
- #write_color_list(colors, opts, out = STDOUT, color_names = nil) ⇒ Object
- #write_color_sets(opts, out = STDOUT) ⇒ Object
-
#write_colors(opts, out = STDOUT) ⇒ Object
Writes out a list.
-
#write_command_line_options(opts, out = STDOUT) ⇒ Object
Write a HTML table documenting all command-line options.
-
#write_commands(opts, out = STDOUT) ⇒ Object
Ouputs HTML code to document all groups and commands.
- #write_functions(opts, out = STDOUT) ⇒ Object
- #write_page(opts, out) ⇒ Object
- #write_page_menu(opts, out) ⇒ Object
-
#write_styles(opts, out = STDOUT) ⇒ Object
Write a summary list of all style items.
-
#write_types(opts, out = STDOUT) ⇒ Object
Ouputs HTML code to document all types.
Constructor Details
#initialize(doc) ⇒ HTML
Returns a new instance of HTML.
44 45 46 47 48 49 50 |
# File 'lib/ctioga2/commands/doc/html.rb', line 44 def initialize(doc) @doc = doc @types_url = "types.html" @commands_url = "commands.html" @backends_url = "backends.html" @functions_url = "functions.html" end |
Instance Attribute Details
#backends_url ⇒ Object
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.
38 39 40 |
# File 'lib/ctioga2/commands/doc/html.rb', line 38 def backends_url @backends_url end |
#commands_url ⇒ Object
The base URL for file where commands and groups are documented.
42 43 44 |
# File 'lib/ctioga2/commands/doc/html.rb', line 42 def commands_url @commands_url end |
#doc ⇒ Object
The Doc object the HTML class should document
28 29 30 |
# File 'lib/ctioga2/commands/doc/html.rb', line 28 def doc @doc end |
#types_url ⇒ Object
The base URL for the file where the types are documented.
31 32 33 |
# File 'lib/ctioga2/commands/doc/html.rb', line 31 def types_url @types_url end |
Instance Method Details
#write_backends(opts, out = STDOUT) ⇒ Object
Ouputs HTML code to all backends
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/ctioga2/commands/doc/html.rb', line 207 def write_backends(opts, out = STDOUT) backends = @doc.backends.sort.map { |d| d[1]} (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 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 |
#write_color_list(colors, opts, out = STDOUT, color_names = nil) ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/ctioga2/commands/doc/html.rb', line 284 def write_color_list(colors, opts, out = STDOUT, color_names = nil) columns = opts["columns"] || 5 cls = opts["class"] || "color-list" div_cls = opts["div-class"] rw = opts["rect-width"] || 80 rh = opts["rect-height"] || 40 div_common = (div_cls ? "class='#{div_cls}' style='" : "style='width:#{rw};height:#{rh};") out.puts "<table class='#{cls}'>" idx = 0 for color in colors if idx % columns == 0 if idx > 0 out.puts "</tr>" end out.puts "<tr>" end if color cls = "##{Utils::color_to_html(color)}" if color_names c = color_names[idx] else c = Utils::color_name_by_value(color) end cb = if c "#{c}<br/>" else "" end out.puts "<td><div #{div_common}background-color: #{cls};color: #{cls};'>#{cb}</div>#{cb}#{cls}</td>" else out.puts "<td>no color</td>" end idx += 1 end out.puts "</tr></table>" end |
#write_color_sets(opts, out = STDOUT) ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/ctioga2/commands/doc/html.rb', line 346 def write_color_sets(opts, out = STDOUT) sets = Graphics::Styles::CurveStyleFactory::parameters['color'].sets set_names = sets.keys.sort if opts['include'] set_names = set_names.select do |x| x =~ opts['include'] end elsif opts['exclude'] set_names = set_names.select do |x| x !~ opts['exclude'] end end set_names = sets.keys.sort for s in set_names out.puts "<h5>Color set: <code>#{s}</code></h5>" colors = sets[s] write_color_list(colors, opts, out) end end |
#write_colors(opts, out = STDOUT) ⇒ Object
Split that to just write an ordered list of colors (get
Writes out a list
their names ?)
334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/ctioga2/commands/doc/html.rb', line 334 def write_colors(opts, out = STDOUT) clrs = Tioga::ColorConstants::constants.sort colors = clrs.map do |c| Tioga::ColorConstants::const_get(c) end color_names = clrs.map do |c| c.to_s end write_color_list(colors, opts, out, color_names) end |
#write_command_line_options(opts, out = STDOUT) ⇒ Object
Write a HTML table documenting all command-line options.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/ctioga2/commands/doc/html.rb', line 156 def (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>" 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(opts, out = STDOUT) ⇒ Object
Ouputs HTML code to document all groups and commands
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/ctioga2/commands/doc/html.rb', line 89 def write_commands(opts, out = STDOUT) cmds, groups = @doc.documented_commands if opts['snippets'] require 'yaml' snippets = begin YAML.load(IO.readlines(opts['snippets']).join()) rescue Exception => e Log::error { "Failed to load snippets file '#{opts['snippets']}'\n => #{e.inspect}" } {} end end (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) if snippets snpts = snippets[cmd.name] if snpts str = "" for k in snpts.keys.sort s = snpts[k] ln = s[:line].chomp # if ln[-1] == '\\' # ln = ln[0..-2] # end # Strip links from the line ln.gsub!(/<a[^>]+>(.*?)<\/a>/) { || $1 } str += "<pre class='#{s[:cls]}'><a href='#{k}'>#{ln}</a></pre>\n" end out.puts "<h5 id='snippets-h5-#{cmd.name}' onclick='toggleExamples(this);'>Examples...</h5>\n<div id='snippets-#{cmd.name}' class='snippets'>#{str}</div>" end end end end end end |
#write_functions(opts, out = STDOUT) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ctioga2/commands/doc/html.rb', line 64 def write_functions(opts, out = STDOUT) funcs = @doc.functions names = funcs.keys.sort (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 |
#write_page(opts, out) ⇒ Object
58 59 60 61 62 |
# File 'lib/ctioga2/commands/doc/html.rb', line 58 def write_page(opts, out) if !opts['page-menu'] or opts['page-menu'] =~ /page|full/i yield out end end |
#write_page_menu(opts, out) ⇒ Object
52 53 54 55 56 |
# File 'lib/ctioga2/commands/doc/html.rb', line 52 def (opts, out) if !opts['page-menu'] or opts['page-menu'] =~ /menu|full/i yield out end end |
#write_styles(opts, out = STDOUT) ⇒ Object
Write a summary list of all style items
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/ctioga2/commands/doc/html.rb', line 238 def write_styles(opts, out = STDOUT) styles = Graphics::Elements::TiogaElement::styled_classes names = styles.keys.sort (opts, out) do |out| out.puts "<div class='quick-jump'>" out.puts "<h3>Quick jump</h3>" out.puts "<ul>\n" for k in names out.puts "<li><a href='#style-#{k}'>#{k}</a></li>\n" end out.puts "</ul>\n" out.puts "</div>" end write_page(opts, out) do |out| for n in names out.puts "<h3 id='style-#{n}' class='style'><code>#{n}</code></h3>\n" cls = styles[n].style_class if cls aliases = cls.defined_aliases out.puts "<ul>\n" opts = cls. op_names = opts.keys.sort for k in op_names type = opts[k].type extra = if aliases.key? k " (alias for <code>#{cls.normalize_out(aliases[k])}</code>)" else "" end puts "<li><code>#{cls.normalize_out(k)}</code>#{extra}: <a href='#{@types_url}#type-#{type.name}'>#{type.name}</a></li>\n" end out.puts "</ul>\n" else out.puts "No specific style information" end end end end |
#write_types(opts, out = STDOUT) ⇒ Object
Ouputs HTML code to document all types
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/ctioga2/commands/doc/html.rb', line 179 def write_types(opts, out = STDOUT) types = @doc.types.sort.map { |d| d[1]} (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 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 |