Module: Webgen::Configuration::Helpers

Included in:
Webgen::Configuration
Defined in:
lib/webgen/configuration.rb

Overview

This module provides methods for setting more complex configuration options. It is mixed into Webgen::Configuration so that its methods can be used. Detailed information on the use of the methods can be found in the “User Manual” in the “Configuration File” section.

All public methods defined in this module are available for direct use in the configuration file, e.g. the method named default_meta_info can be used like this:

default_meta_info:
  Webgen::SourceHandler::Page:
    in_menu : true
    :action : replace

All methods have to take exactly one argument, a Hash.

The special key :action should be used for specifying how the configuration option should be set:

replace

Replace the configuration option with the new values.

modify

Replace old values with new values and add missing ones (useful for hashes and normally the default value)

Instance Method Summary collapse

Instance Method Details

#default_meta_info(args) ⇒ Object

Set the default meta information for source handlers.



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/webgen/configuration.rb', line 66

def default_meta_info(args)
  args.each do |sh_name, mi|
    raise ArgumentError, 'Invalid argument for configuration helper default_meta_info' unless mi.kind_of?(Hash)
    action = mi.delete(:action) || 'modify'
    mi_hash = (self['sourcehandler.default_meta_info'][complete_source_handler_name(sh_name)] ||= {})
    case action
    when 'replace' then mi_hash.replace(mi)
    else mi_hash.update(mi)
    end
  end
end

#default_processing_pipeline(args) ⇒ Object

Set the default processing pipeline for a source handler.



96
97
98
99
100
101
102
# File 'lib/webgen/configuration.rb', line 96

def default_processing_pipeline(args)
  args.each do |sh_name, pipeline|
    raise ArgumentError, 'Invalid argument for configuration helper pipeline' unless pipeline.kind_of?(String)
    mi_hash = (self['sourcehandler.default_meta_info'][complete_source_handler_name(sh_name)] ||= {})
    ((mi_hash['blocks'] ||= {})['default'] ||= {})['pipeline'] = pipeline
  end
end

#patterns(args) ⇒ Object

Set the path patterns used by source handlers.



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/webgen/configuration.rb', line 80

def patterns(args)
  args.each do |sh_name, data|
    pattern_arr = (self['sourcehandler.patterns'][complete_source_handler_name(sh_name)] ||= [])
    case data
    when Array then pattern_arr.replace(data)
    when Hash
      (data['del'] || []).each {|pat| pattern_arr.delete(pat)}
      (data['add'] || []).each {|pat| pattern_arr << pat}
    else
      raise ArgumentError, 'Invalid argument for configuration helper patterns'
    end
  end
end