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.



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_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.



38
39
40
# File 'lib/ctioga2/commands/doc/html.rb', line 38

def backends_url
  @backends_url
end

#commands_urlObject

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

#docObject

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_urlObject

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



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/ctioga2/commands/doc/html.rb', line 180

def write_backends(opts, out = STDOUT)
  backends = @doc.backends.sort.map { |d| d[1]}


  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
  
  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_command_line_options(opts, out = STDOUT) ⇒ Object

Write a HTML table documenting all command-line options.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/ctioga2/commands/doc/html.rb', line 129

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>"
    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
# File 'lib/ctioga2/commands/doc/html.rb', line 89

def write_commands(opts, out = STDOUT)
  cmds, groups = @doc.documented_commands

  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_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
  
  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

#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 write_page_menu(opts, out)
  if !opts['page-menu'] or opts['page-menu'] =~ /menu|full/i
    yield out
  end
end

#write_types(opts, out = STDOUT) ⇒ Object

Ouputs HTML code to document all types



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/ctioga2/commands/doc/html.rb', line 152

def write_types(opts, out = STDOUT)
  types = @doc.types.sort.map { |d| d[1]}


  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
 
  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