--- title: Extending webgen inMenu: true --- h2. Extending webgen h3. General p={font-size: 150%; color: red}. *This part of the homepage is out of date and will be updated soon!* There is a logging mechanism available for informational and debugging purposes. Four different log levels are available: * debug * info * warn * error The methods are named after the log levels and can be invoked by using @logger.{debug|info|warn|error}@. You need to provide a string as argument or a block which returns a string. h3. Normal plugins (new tags, file handlers, etc) As webgen is plugin-based, it can be extended very easily. A simple example is shown in the tutorial. If you want more sophisticated examples of plugins, have a look at webgen itself and the plugins that get shipped with it. They can be found in the directory @lib/webgen/plugins/@! h3. CLI Command Plugins For this you need to write a new command class and put its file into the @plugin@ folder of the website. Have a look at the "cmdparse API reference":http://cmdparse.rubyforge.org/rdoc/index.html for information about how to write a command class. There are basically two ways for a command plugin: * Easiest one You just declare a new class derived from @CmdParse::Command@ and include the @Webgen::CommandPlugin@ module. After you have included this module, you can use all standard plugin directives, like @summary@ or @add_param@. Also, this command gets automatically added to the main @CommandParser@ class. Thus, the @initialize@ method must not take any arguments!
  class SimpleCommand < CmdParse::Command

  include Webgen::CommandPlugin

  summary "Describe simple command"
  add_param 'firstParam', 45, 'Description of firstParam'

  def initialize
    super( 'simple', false )
    self.short_desc = "This is a sample for a simple command."
  end

  def usage; "Usage: #{@options.program_name} [global options] simple"; end

  def execute( args )
    # do something useful
  end

  end
  
* Easy one You only need to go this way when the @initialize@ method of your command class needs to arguments!! Like before, you declare your new command class. This time however, you need include the @Webgen::PluginDefs@ module and set the constant @VIRTUAL@ to true. This prevents the plugin system from automatically instantiating an object. You then need to instantiate an object and add it to the main @CommandParser@ class. This can be done by calling the @add_cmdparser_command@ of the configuration plugin.
  class OtherCommand < CmdParse::Command

  include Webgen::PluginDefs

  VIRTUAL = true

  summary "Describe other simple command"

  def initialize( arg )
    super( 'otherSimple', false )
    @arg = arg
    self.short_desc = "This is a second sample for a simple command."
  end

  def usage; "Usage: #{@options.program_name} [global options] otherSimple"; end

  def execute( args )
    # do something useful
  end

  end

  Webgen::Plugin['Configuration'].add_cmdparser_command( OtherCommand.new( 5 ) )