File: extension.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 (84 lines) | stat: -rw-r--r-- 2,878 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
47
48
49
50
51
52
53
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
module WebgenDocuPlugins

  class VersionTag < Tags::DefaultTag

    summary "Shows the version number of webgen"

    tag 'version'

    def process_tag( tag, node, refNode )
      Webgen::VERSION.join( '.' )
    end

  end

  class DescribeTag < Tags::DefaultTag

    summary "Shows options for the specified file handler"
    add_param 'plugin', nil, 'The plugin which should be described'
    set_mandatory 'plugin', true

    tag 'describe'

    def initialize
      super
      @processOutput = false
    end

    def process_tag( tag, node, refNode )
      filehandler = get_param( 'plugin' )
      self.logger.debug { "Describing tag #{filehandler}" }
      plugin = Webgen::Plugin.config.find {|k,v| v.plugin == filehandler }
      self.logger.warn { "Could not describe plugin '#{filehandler}' as it does not exist" } if plugin.nil?
      ( plugin.nil? ? '' : format_data( plugin[1] ) )
    end

    def format_data( data )
      s = "<table>"
      row = lambda {|desc, value| "<tr style='vertical-align: top'><td style='font-weight:bold'>#{CGI::escapeHTML( desc )}:</td><td>#{value}</td></tr>" }

      # Plugin and ancestors
      ancestors = data.klass.ancestor_classes[1..-1].collect {|k| Webgen::Plugin.config[k].plugin}.join(', ')
      s += row['Plugin name', CGI::escapeHTML( data.plugin + (ancestors.empty? ? '' : " (#{ancestors})" ) )]

      # summary, description
      [['Summary', 'summary'], ['Description', 'description']].each do |desc, name|
        s += row[desc, CGI::escapeHTML( data.send( name ) )] if eval( "data.#{name}" )
      end

      # dependencies
      s += row['Dependencies', CGI::escapeHTML( data.dependencies.join( ', ') )] if data.dependencies

      # parameters
      unless data.params.nil?
        s += row['Parameters', format_params( data.params )]
      end

      # used meta info
      s += row['Used meta information', CGI::escapeHTML( data.used_meta_info.join( ', ') )] if data.used_meta_info

      # tag name, file ext
      s += row['Name of tag', (data.tag == :default ? "Default tag" : data.tag)] if data.tag
      s += row['Handled paths', data.path.collect {|p| CGI::escapeHTML( p )}.join('<br />')] if data.path

      # Show all registered handlers
      data.table.keys.find_all {|k| /^registered_/ =~ k.to_s }.each do |k|
        s += row[k.to_s.sub( /^registered_/, '' ).tr('_', ' ').capitalize + " name", data.send( k )]
      end

      s += "</table>"
    end

    def format_params( params )
      params.sort.collect do |k,v|
        "<span style='color: red'>#{v.name}</span>" + \
        ( v.mandatory.nil? \
          ? "&nbsp;=&nbsp;<span style='color: blue'>#{CGI::escapeHTML( v.default.inspect )}</span>" \
          : " (=" + ( v.mandatoryDefault ? "default " : "" ) + "mandatory parameter)" ) + \
        ": #{CGI::escapeHTML( v.description )}"
      end.join( "<br />\n" )
    end

  end

end