ctioga2 0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. data/COPYING +339 -0
  2. data/Changelog +6 -0
  3. data/bin/ctioga2 +26 -0
  4. data/lib/ctioga2/commands/arguments.rb +58 -0
  5. data/lib/ctioga2/commands/commands.rb +258 -0
  6. data/lib/ctioga2/commands/doc/doc.rb +118 -0
  7. data/lib/ctioga2/commands/doc/documentation-commands.rb +119 -0
  8. data/lib/ctioga2/commands/doc/help.rb +95 -0
  9. data/lib/ctioga2/commands/doc/html.rb +230 -0
  10. data/lib/ctioga2/commands/doc/introspection.rb +211 -0
  11. data/lib/ctioga2/commands/doc/man.rb +279 -0
  12. data/lib/ctioga2/commands/doc/markup.rb +359 -0
  13. data/lib/ctioga2/commands/general-commands.rb +119 -0
  14. data/lib/ctioga2/commands/general-types.rb +118 -0
  15. data/lib/ctioga2/commands/groups.rb +73 -0
  16. data/lib/ctioga2/commands/interpreter.rb +257 -0
  17. data/lib/ctioga2/commands/parsers/command-line.rb +187 -0
  18. data/lib/ctioga2/commands/parsers/file.rb +186 -0
  19. data/lib/ctioga2/commands/strings.rb +303 -0
  20. data/lib/ctioga2/commands/type.rb +100 -0
  21. data/lib/ctioga2/commands/variables.rb +101 -0
  22. data/lib/ctioga2/data/backends/backend.rb +260 -0
  23. data/lib/ctioga2/data/backends/backends.rb +39 -0
  24. data/lib/ctioga2/data/backends/backends/gnuplot.rb +140 -0
  25. data/lib/ctioga2/data/backends/backends/math.rb +121 -0
  26. data/lib/ctioga2/data/backends/backends/text.rb +335 -0
  27. data/lib/ctioga2/data/backends/description.rb +405 -0
  28. data/lib/ctioga2/data/backends/factory.rb +73 -0
  29. data/lib/ctioga2/data/backends/parameter.rb +109 -0
  30. data/lib/ctioga2/data/datacolumn.rb +245 -0
  31. data/lib/ctioga2/data/dataset.rb +233 -0
  32. data/lib/ctioga2/data/filters.rb +131 -0
  33. data/lib/ctioga2/data/merge.rb +43 -0
  34. data/lib/ctioga2/data/point.rb +72 -0
  35. data/lib/ctioga2/data/stack.rb +294 -0
  36. data/lib/ctioga2/graphics/coordinates.rb +73 -0
  37. data/lib/ctioga2/graphics/elements.rb +111 -0
  38. data/lib/ctioga2/graphics/elements/containers.rb +111 -0
  39. data/lib/ctioga2/graphics/elements/curve2d.rb +155 -0
  40. data/lib/ctioga2/graphics/elements/element.rb +90 -0
  41. data/lib/ctioga2/graphics/elements/primitive.rb +256 -0
  42. data/lib/ctioga2/graphics/elements/subplot.rb +140 -0
  43. data/lib/ctioga2/graphics/generator.rb +68 -0
  44. data/lib/ctioga2/graphics/legends.rb +108 -0
  45. data/lib/ctioga2/graphics/legends/area.rb +199 -0
  46. data/lib/ctioga2/graphics/legends/items.rb +183 -0
  47. data/lib/ctioga2/graphics/legends/provider.rb +58 -0
  48. data/lib/ctioga2/graphics/legends/storage.rb +65 -0
  49. data/lib/ctioga2/graphics/root.rb +209 -0
  50. data/lib/ctioga2/graphics/styles.rb +30 -0
  51. data/lib/ctioga2/graphics/styles/axes.rb +247 -0
  52. data/lib/ctioga2/graphics/styles/background.rb +122 -0
  53. data/lib/ctioga2/graphics/styles/base.rb +115 -0
  54. data/lib/ctioga2/graphics/styles/carrays.rb +53 -0
  55. data/lib/ctioga2/graphics/styles/curve.rb +101 -0
  56. data/lib/ctioga2/graphics/styles/drawable.rb +87 -0
  57. data/lib/ctioga2/graphics/styles/factory.rb +351 -0
  58. data/lib/ctioga2/graphics/styles/legend.rb +63 -0
  59. data/lib/ctioga2/graphics/styles/plot.rb +410 -0
  60. data/lib/ctioga2/graphics/styles/sets.rb +64 -0
  61. data/lib/ctioga2/graphics/styles/texts.rb +277 -0
  62. data/lib/ctioga2/graphics/subplot-commands.rb +141 -0
  63. data/lib/ctioga2/graphics/types.rb +188 -0
  64. data/lib/ctioga2/graphics/types/bijection.rb +79 -0
  65. data/lib/ctioga2/graphics/types/boundaries.rb +170 -0
  66. data/lib/ctioga2/graphics/types/boxes.rb +157 -0
  67. data/lib/ctioga2/graphics/types/dimensions.rb +157 -0
  68. data/lib/ctioga2/graphics/types/point.rb +247 -0
  69. data/lib/ctioga2/log.rb +97 -0
  70. data/lib/ctioga2/metabuilder/type.rb +316 -0
  71. data/lib/ctioga2/metabuilder/types.rb +39 -0
  72. data/lib/ctioga2/metabuilder/types/coordinates.rb +124 -0
  73. data/lib/ctioga2/metabuilder/types/dates.rb +43 -0
  74. data/lib/ctioga2/metabuilder/types/lists.rb +188 -0
  75. data/lib/ctioga2/metabuilder/types/numbers.rb +97 -0
  76. data/lib/ctioga2/metabuilder/types/strings.rb +93 -0
  77. data/lib/ctioga2/metabuilder/types/styles.rb +178 -0
  78. data/lib/ctioga2/plotmaker.rb +677 -0
  79. data/lib/ctioga2/postprocess.rb +115 -0
  80. data/lib/ctioga2/utils.rb +120 -0
  81. data/setup.rb +1586 -0
  82. metadata +144 -0
@@ -0,0 +1,118 @@
1
+ # doc.rb: a class holding all informations
2
+ # copyright (c) 2009 by Vincent Fourmond
3
+
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details (in the COPYING file).
13
+
14
+ require 'ctioga2/utils'
15
+ require 'ctioga2/commands/commands'
16
+ require 'ctioga2/commands/doc/markup'
17
+
18
+ module CTioga2
19
+
20
+ Version::register_svn_info('$Revision: 61 $', '$Date: 2009-05-29 01:00:56 +0200 (Fri, 29 May 2009) $')
21
+
22
+ module Commands
23
+
24
+ # The base of the 'self-documentation' of CTioga2
25
+ module Documentation
26
+
27
+ # The base class for all documentation.
28
+ #
29
+ # TODO: create a class that would parse a description from a
30
+ # group/command/type and understand some 'markup': lists, links
31
+ # to other commands/groups/types, and maybe bold or things of
32
+ # this kind. Then the various outputs should have a means to
33
+ # parse this.
34
+ class Doc
35
+
36
+ # The hash containing all the commands, as returned
37
+ # by Interpreter::commands.
38
+ attr_accessor :commands
39
+
40
+ # The hash containing all the groups, as returned
41
+ # by Interpreter::commands.
42
+ attr_accessor :groups
43
+
44
+ # The hash containing all the types, as returned
45
+ # by Interpreter::commands.
46
+ attr_accessor :types
47
+
48
+ # Wether or not to ignore blacklisted commands
49
+ attr_accessor :ignore_blacklisted
50
+
51
+ # The CommandLineHelp object in charge of displaying
52
+ # information about command-line
53
+ attr_accessor :command_line_help
54
+
55
+
56
+ # Create a Doc object caring about the current state of
57
+ # registered commands and such.
58
+ def initialize
59
+ @commands = Interpreter::commands
60
+ @groups = Interpreter::groups
61
+ @types = Interpreter::types
62
+
63
+ @ignore_blacklisted = ! (ENV.key?("CT2_DEV") &&
64
+ ! ENV["CT2_DEV"].empty?)
65
+
66
+ @command_line_help = CommandLineHelp.new
67
+ end
68
+
69
+ # Returns a [ cmds, groups ] hash containing the list of
70
+ # commands, and the groups to be documented.
71
+ def documented_commands
72
+ cmds = group_commands
73
+
74
+ groups = cmds.keys.sort do |a,b|
75
+ if ! a
76
+ 1
77
+ elsif ! b
78
+ -1
79
+ else
80
+ a.priority <=> b.priority
81
+ end
82
+ end
83
+ if @ignore_blacklisted
84
+ groups.delete_if {|g| g && g.blacklisted }
85
+ end
86
+ return [cmds, groups]
87
+ end
88
+
89
+ # Display command-line help.
90
+ def display_command_line_help
91
+ @command_line_help.
92
+ print_commandline_options(*self.documented_commands)
93
+ end
94
+
95
+ protected
96
+
97
+
98
+ # Groups Command by CommandGroup, _nil_ being a proper value,
99
+ # and return the corresponding hash.
100
+ def group_commands
101
+ ret_val = {}
102
+ for name, cmd in @commands
103
+ group = cmd.group
104
+ if ret_val.key?(group)
105
+ ret_val[group] << cmd
106
+ else
107
+ ret_val[group] = [cmd]
108
+ end
109
+ end
110
+
111
+ return ret_val
112
+ end
113
+
114
+ end
115
+ end
116
+ end
117
+ end
118
+
@@ -0,0 +1,119 @@
1
+ # doc.rb: a class holding all informations
2
+ # copyright (c) 2009 by Vincent Fourmond
3
+
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details (in the COPYING file).
13
+
14
+ require 'ctioga2/utils'
15
+ require 'ctioga2/commands/commands'
16
+ require 'ctioga2/commands/doc/help'
17
+ require 'ctioga2/commands/doc/man'
18
+ require 'ctioga2/commands/doc/html'
19
+ require 'ctioga2/commands/doc/markup'
20
+
21
+ module CTioga2
22
+
23
+ Version::register_svn_info('$Revision: 77 $', '$Date: 2009-06-05 00:20:49 +0200 (Fri, 05 Jun 2009) $')
24
+
25
+ module Commands
26
+
27
+ # The base of the 'self-documentation' of CTioga2
28
+ module Documentation
29
+
30
+
31
+ # Documentation generation
32
+ DocumentationGenerationGroup =
33
+ CmdGroup.new('doc', "Documentation generation",
34
+ "Automatic documentation generation.",
35
+ 1000, true)
36
+
37
+
38
+ # Display help on the command-line
39
+ WriteManualPage =
40
+ Cmd.new("write-manual-page", nil, "--write-man",
41
+ [
42
+ CmdArg.new('text', 'version'),
43
+ CmdArg.new('file'),
44
+ ]) do |plotmaker, version, file|
45
+ m = Man.new(plotmaker.interpreter.doc)
46
+ m.write_manual_page(version, file)
47
+ end
48
+
49
+ WriteManualPage.describe("Writes a manual page based on a template",
50
+ <<EOH, DocumentationGenerationGroup)
51
+ Writes a manual page based on a template
52
+ EOH
53
+
54
+
55
+ WriteHTMLCommands =
56
+ Cmd.new("write-html-commands", nil, "--write-html-commands",
57
+ []) do |plotmaker|
58
+ html = HTML.new(plotmaker.interpreter.doc)
59
+ html.write_commands()
60
+ end
61
+
62
+ WriteHTMLCommands.describe("HTML documentation for group and commands",
63
+ <<EOH, DocumentationGenerationGroup)
64
+ Prints the HTML documentation for group and commands to standard output.
65
+ EOH
66
+
67
+ WriteHTMLTypes =
68
+ Cmd.new("write-html-types", nil, "--write-html-types",
69
+ []) do |plotmaker|
70
+ html = HTML.new(plotmaker.interpreter.doc)
71
+ html.write_types()
72
+ end
73
+
74
+ WriteHTMLTypes.describe("HTML documentation for types",
75
+ <<EOH, DocumentationGenerationGroup)
76
+ Prints the HTML documentation for all types.
77
+ EOH
78
+
79
+ WriteHTMLCommandLineOptions =
80
+ Cmd.new("write-html-commandline", nil, "--write-html-commandline",
81
+ []) do |plotmaker|
82
+ html = HTML.new(plotmaker.interpreter.doc)
83
+ html.write_command_line_options()
84
+ end
85
+
86
+ WriteHTMLCommandLineOptions.describe("HTML documentation for types",
87
+ <<EOH, DocumentationGenerationGroup)
88
+ Prints a table summary of command-line options.
89
+ EOH
90
+
91
+ DumpCommandMarkup =
92
+ Cmd.new("dump-command-markup", nil, "--dump-command-markup",
93
+ []) do |plotmaker|
94
+ markup = Markup.new(plotmaker.interpreter.doc)
95
+ markup.write_commands()
96
+ end
97
+
98
+ DumpCommandMarkup.describe("Dump markup for commands and groups",
99
+ <<EOH, DocumentationGenerationGroup)
100
+ Dumps the parsed markup for commands and groups. Used for debugging
101
+ purposes.
102
+ EOH
103
+
104
+ DumpTypesMarkup =
105
+ Cmd.new("dump-types-markup", nil, "--dump-types-markup",
106
+ []) do |plotmaker|
107
+ markup = Markup.new(plotmaker.interpreter.doc)
108
+ markup.write_types()
109
+ end
110
+
111
+ DumpTypesMarkup.describe("Dump markup for types and groups",
112
+ <<EOH, DocumentationGenerationGroup)
113
+ Dumps the parsed markup for types and groups. Used for debugging
114
+ purposes.
115
+ EOH
116
+
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,95 @@
1
+ # help.rb: displaying the documentation of commands
2
+ # copyright (c) 2009 by Vincent Fourmond
3
+
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details (in the COPYING file).
13
+
14
+ require 'ctioga2/utils'
15
+ require 'ctioga2/commands/commands'
16
+ require 'ctioga2/commands/parsers/command-line'
17
+
18
+ module CTioga2
19
+
20
+ Version::register_svn_info('$Revision: 34 $', '$Date: 2009-05-03 20:22:29 +0200 (Sun, 03 May 2009) $')
21
+
22
+ module Commands
23
+
24
+ module Documentation
25
+
26
+ # Displays help about command-line options and such.
27
+ class CommandLineHelp
28
+
29
+ # How much space to leave for the options ?
30
+ attr_accessor :options_column_width
31
+
32
+ def initialize
33
+ @options_column_width = 20
34
+ end
35
+
36
+ # Prints short help text suitable for a --help option about
37
+ # available commands, by groups (ungrouped last). It takes a
38
+ # list of all commands (_cmds_) and the list of _groups_ to
39
+ # display.
40
+ #
41
+ # TODO: word splitting.
42
+ #
43
+ # TODO: why not try color, too ;-) ???
44
+ def print_commandline_options(cmds, groups)
45
+ for group in groups
46
+ puts unless group == groups[0]
47
+ name = (group && group.name) || "Ungrouped commands"
48
+ if group && group.blacklisted
49
+ name << " (blacklisted)"
50
+ end
51
+ puts name
52
+ for cmd in cmds[group].sort {|a,b|
53
+ a.long_option <=> b.long_option
54
+ }
55
+
56
+ strings = cmd.option_strings
57
+ puts "#{leading_spaces}%2s%1s %-#{@options_column_width}s%s" %
58
+ [
59
+ strings[0], (strings[0] ? "," : " "),
60
+ strings[1],
61
+ if strings[1].size >= @options_column_width
62
+ "\n#{total_leading_spaces}#{strings[2]}"
63
+ else
64
+ strings[2]
65
+ end
66
+ ]
67
+ if cmd.has_options?
68
+ puts "#{total_leading_spaces} options: %s" %
69
+ cmd.optional_arguments.keys.sort.map {|x| "/#{x}"}.join(' ')
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ protected
77
+
78
+ # Leading spaces to align a string with the other option texts
79
+ def total_leading_spaces
80
+ return "#{leading_spaces}#{" " *(@options_column_width + 4)}"
81
+ # 4: '-o, '
82
+ end
83
+
84
+ # Spaces before any 'short' option appears
85
+ def leading_spaces
86
+ return " "
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -0,0 +1,230 @@
1
+ # html.rb: html output for internal documentation
2
+ # copyright (c) 2009 by Vincent Fourmond
3
+
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful, but
10
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details (in the COPYING file).
13
+
14
+ require 'ctioga2/utils'
15
+ require 'ctioga2/commands/commands'
16
+
17
+ module CTioga2
18
+
19
+ Version::register_svn_info('$Revision: 77 $', '$Date: 2009-06-05 00:20:49 +0200 (Fri, 05 Jun 2009) $')
20
+
21
+ module Commands
22
+
23
+ module Documentation
24
+
25
+ # Generation of XHTML snippets (not full pages) that document
26
+ # the commands/groups and types known to CTioga2.
27
+ class HTML
28
+
29
+ # The Doc object the HTML class should document
30
+ attr_accessor :doc
31
+
32
+ # The base URL for file where types are documented.
33
+ attr_accessor :types_url
34
+
35
+ # The base URL for file where commands and groups are
36
+ # documented.
37
+ attr_accessor :commands_url
38
+
39
+ def initialize(doc)
40
+ @doc = doc
41
+ @types_url = "types.html"
42
+ @commands_url = "commands.html"
43
+ end
44
+
45
+ # Ouputs HTML code to document all groups and commands
46
+ def write_commands(out = STDOUT)
47
+ cmds, groups = @doc.documented_commands
48
+
49
+ out.puts "<div class='quick-jump'>"
50
+ out.puts "Quick jump to a specific group of commands:\n"
51
+ out.puts "<ul>\n"
52
+ for g in groups
53
+ out.puts "<li><a href='#group-#{g.id}'>#{g.name}</a></li>\n"
54
+ end
55
+ out.puts "</ul>\n"
56
+ out.puts "</div>"
57
+
58
+ for g in groups
59
+ out.puts
60
+ out.puts "<h3 class='group' id='group-#{g.id}'>#{g.name}</h3>"
61
+ out.puts markup_to_html(g.description)
62
+
63
+ commands = cmds[g].sort {|a,b|
64
+ a.name <=> b.name
65
+ }
66
+
67
+ out.puts "<p>"
68
+ out.puts "<span class='bold'>Available commands:</span>\n"
69
+ out.puts commands.map {|c|
70
+ "<a href='#command-#{c.name}'><code>#{c.name}</code></a>"
71
+ }.join(' ')
72
+ out.puts "</p>"
73
+
74
+ for cmd in commands
75
+ out.puts
76
+ out.puts command_documentation(cmd)
77
+ end
78
+ end
79
+ end
80
+
81
+ # Write a HTML table documenting all command-line options.
82
+ def write_command_line_options(out = STDOUT)
83
+ cmds, groups = @doc.documented_commands
84
+
85
+ out.puts "<table>"
86
+ for g in groups
87
+ out.puts "<tr><th colspan='3'>#{g.name}</th></tr>"
88
+ commands = cmds[g].sort {|a,b|
89
+ a.long_option <=> b.long_option
90
+ }
91
+ for cmd in commands
92
+ opts = cmd.option_strings
93
+ link = "<a href='#{@commands_url}#command-#{cmd.name}'>"
94
+ out.puts "<tr><td><code>#{link}#{opts[0]}</a></code></td>"
95
+ out.puts "<td><code>#{link}#{opts[1]}</a></code></td>"
96
+ out.puts "<td>#{opts[2]}</td></tr>"
97
+ end
98
+ end
99
+ out.puts "</table>"
100
+
101
+ end
102
+
103
+
104
+ # Ouputs HTML code to document all types
105
+ def write_types(out = STDOUT)
106
+ types = @doc.types.sort.map { |d| d[1]}
107
+
108
+
109
+ out.puts "<div class='quick-jump'>"
110
+ out.puts "Quick jump to a specific type:\n"
111
+ out.puts "<ul>\n"
112
+ for t in types
113
+ out.puts "<li><a href='#type-#{t.name}'>#{t.name}</a></li>\n"
114
+ end
115
+ out.puts "</ul>\n"
116
+ out.puts "</div>"
117
+
118
+ for t in types
119
+ out.puts
120
+ out.puts "<h4 id='type-#{t.name}' class='type'>#{t.name}</h4>\n"
121
+ out.puts markup_to_html(t.description)
122
+ out.puts # There is no need to wrap the markup
123
+ # in a paragraph.
124
+ end
125
+ end
126
+
127
+
128
+ protected
129
+
130
+ # The string that represents a full command
131
+ def command_documentation(cmd)
132
+ str = "<h4 class='command' id='command-#{cmd.name}'>Command: <code>#{cmd.name}</code></h4>\n"
133
+ str << "<p class='synopsis'>\n<span class='bold'>Synopsis (file)</span>\n"
134
+
135
+ str << "</p>\n<pre class='examples-cmdfile'>"
136
+ str << "<span class='cmd'>#{cmd.name}("
137
+ str << cmd.arguments.map { |arg|
138
+ "<a class='argument' href='#{@types_url}#type-#{arg.type.name}'>#{arg.displayed_name}</a>"
139
+ }.join(',')
140
+ if cmd.has_options?
141
+ if(cmd.arguments.size > 0)
142
+ str << ", "
143
+ end
144
+ str << "option=..."
145
+ end
146
+ str << ")</span>\n"
147
+ str << "</pre>\n"
148
+
149
+ # Command-line file synopsis
150
+ str << "<p class='synopsis'>\n<span class='bold'>Synopsis (command-line)</span>\n"
151
+ args = cmd.arguments.map { |arg|
152
+ "<a class='argument' href='#{@types_url}#type-#{arg.type.name}'>#{arg.displayed_name.upcase}</a>"
153
+ }.join(' ')
154
+ if cmd.has_options?
155
+ args << " /option=..."
156
+ end
157
+ str << "</p>\n<pre class='examples-cmdline'>"
158
+ if cmd.short_option
159
+ str << "<span class='cmdline'>-#{cmd.short_option} "
160
+ str << args
161
+ str << "</span>\n"
162
+ end
163
+ str << "<span class='cmdline'>--#{cmd.long_option} "
164
+ str << args
165
+ str << "</span>\n"
166
+ str << "</pre>"
167
+
168
+ if cmd.has_options?
169
+ str << "<p class='synopsis'><span class='bold'>Available options</span>:\n"
170
+ opts = cmd.optional_arguments.sort.map do |k,arg|
171
+ "<a href='#{@types_url}#type-#{arg.type.name}'><code>#{k}</code></a>\n"
172
+ end
173
+ str << opts.join(' ')
174
+ str << "</p>"
175
+ end
176
+ # Now, the description:
177
+ str << markup_to_html(cmd.long_description)
178
+ return str
179
+ end
180
+
181
+ # Takes up an array of MarkupItem objects and returns its
182
+ # equivalent in HTML format. Alternativelely, it can take a
183
+ # String and feed it to MarkedUpText.
184
+ #
185
+ # TODO: escape correctly the produced HTML code...
186
+ def markup_to_html(items)
187
+ if items.is_a? String
188
+ mup = MarkedUpText.new(@doc, items)
189
+ return markup_to_html(mup.elements)
190
+ end
191
+ str = ""
192
+ for it in items
193
+ case it
194
+ when MarkedUpText::MarkupText
195
+ str << it.to_s
196
+ when MarkedUpText::MarkupLink
197
+ case it.target
198
+ when Command
199
+ link = "#{@commands_url}#command-#{it.target.name}"
200
+ when CommandGroup
201
+ link = "#{@commands_url}#group-#{it.target.id}"
202
+ when CommandType
203
+ link = "#{@types_url}#type-#{it.target.name}"
204
+ else
205
+ raise "The link target should be either a group, a command or a type, but is a #{it.target.class}"
206
+ end
207
+ str << "<a href='#{link}'>#{it.to_s}</a>"
208
+ when MarkedUpText::MarkupItemize
209
+ str << "<ul>\n"
210
+ for x in it.items
211
+ str << "<li>#{markup_to_html(x)}</li>\n"
212
+ end
213
+ str << "</ul>\n"
214
+ when MarkedUpText::MarkupParagraph
215
+ str << "<p>\n#{markup_to_html(it.elements)}\n</p>\n"
216
+ when MarkedUpText::MarkupVerbatim
217
+ str << "<pre class='#{it.cls}'>#{it.text}</pre>\n"
218
+ else
219
+ raise "Markup #{it.class} isn't implemented yet for HTML"
220
+ end
221
+ end
222
+ return str
223
+ end
224
+
225
+
226
+ end
227
+
228
+ end
229
+ end
230
+ end