Class: CTioga2::Commands::Documentation::HTML

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ HTML

Returns a new instance of HTML.



46
47
48
49
50
51
# File 'lib/ctioga2/commands/doc/html.rb', line 46

def initialize(doc)
  @doc = doc
  @types_url = "types.html"
  @commands_url = "commands.html"
  @backends_url = "backends.html"
end

Instance Attribute Details

#backends_urlObject

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.



40
41
42
# File 'lib/ctioga2/commands/doc/html.rb', line 40

def backends_url
  @backends_url
end

#commands_urlObject

The base URL for file where commands and groups are documented.



44
45
46
# File 'lib/ctioga2/commands/doc/html.rb', line 44

def commands_url
  @commands_url
end

#docObject

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_urlObject

The base URL for the file where the 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_backends(out = STDOUT) ⇒ Object

Ouputs HTML code to all backends



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/ctioga2/commands/doc/html.rb', line 137

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

#write_command_line_options(out = STDOUT) ⇒ Object

Write a HTML table documenting all command-line options.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/ctioga2/commands/doc/html.rb', line 90

def write_command_line_options(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



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
80
81
82
83
84
85
86
87
# File 'lib/ctioga2/commands/doc/html.rb', line 54

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



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/ctioga2/commands/doc/html.rb', line 113

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