File: clidesc.rb

package info (click to toggle)
webgen 0.3.8-3
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 1,912 kB
  • ctags: 586
  • sloc: ruby: 4,789; makefile: 9
file content (46 lines) | stat: -rw-r--r-- 1,206 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'cgi'

module WebgenDocuPlugins

  class CliDescTag < Tags::DefaultTag

    summary "Describes the CLI interface"

    tag 'clidesc'

    def initialize
      super
      @processOutput = false
    end

    def process_tag( tag, node, refNode )
      wcp = Webgen::WebgenCommandParser.new
      output = ''
      output << "<p><b>Global Options:</b></p>"
      output << "<pre>#{CGI::escapeHTML(wcp.options.summarize.to_s)}</pre>"
      output << "<p><b>Commands:</b></p>"
      output << "<dl>"
      output << show_command( wcp.main_command )
      output << "</dl>"
    end

    def show_command( cmd )
      output = ''
      cmd.commands.sort.each do |name, command|
        output << "<dt>#{name}</dt>"
        output << "<dd>#{CGI::escapeHTML(command.short_desc)}<br />#{CGI::escapeHTML(command.description)+'<br />' if command.description}"
        output << "#{CGI::escapeHTML(command.usage)}"
        output << "<pre>#{CGI::escapeHTML(command.options.summarize.to_s)}</pre>"
        if command.has_commands?
          output << "<dl>"
          output << show_command( command )
          output << "</dl>"
        end
        output << "</dd>"
      end
      output
    end

  end

end