webgen 0.3.2 → 0.3.3
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.
- data/ChangeLog +224 -0
- data/Rakefile +2 -3
- data/TODO +18 -1
- data/VERSION +1 -1
- data/doc/plugin/clidesc.rb +35 -0
- data/doc/plugin/extension.rb +73 -0
- data/doc/src/about.page +2 -1
- data/doc/src/default.css +5 -1
- data/doc/src/default.template +9 -0
- data/doc/src/documentation/cli.page +12 -0
- data/doc/src/documentation/gettingstarted.page +150 -0
- data/doc/src/documentation/index.page +1 -19
- data/doc/src/documentation/{contenthandler → plugins/contenthandler}/html.page +0 -0
- data/doc/src/documentation/{contenthandler → plugins/contenthandler}/index.page +0 -0
- data/doc/src/documentation/{contenthandler → plugins/contenthandler}/markdown.page +0 -0
- data/doc/src/documentation/{contenthandler → plugins/contenthandler}/rdoc.page +0 -0
- data/doc/src/documentation/{contenthandler → plugins/contenthandler}/textile.page +0 -0
- data/doc/src/documentation/plugins/filehandler/backing.page +33 -0
- data/doc/src/documentation/{filehandler → plugins/filehandler}/copy.page +0 -0
- data/doc/src/documentation/{filehandler → plugins/filehandler}/directory.page +1 -2
- data/doc/src/documentation/{filehandler → plugins/filehandler}/galleryhandler.page +1 -1
- data/doc/src/documentation/{filehandler → plugins/filehandler}/index.page +0 -0
- data/doc/src/documentation/{filehandler → plugins/filehandler}/pagehandler.page +0 -0
- data/doc/src/documentation/{filehandler → plugins/filehandler}/template.page +0 -0
- data/doc/src/documentation/{gallerylayouter → plugins/gallerylayouter}/defaultlayouter.page +0 -0
- data/doc/src/documentation/{gallerylayouter → plugins/gallerylayouter}/index.page +0 -0
- data/doc/src/documentation/{htmlvalidator → plugins/htmlvalidator}/index.page +0 -0
- data/doc/src/documentation/{htmlvalidator → plugins/htmlvalidator}/xmllint.page +0 -0
- data/doc/src/documentation/plugins/index.page +20 -0
- data/doc/src/documentation/plugins/system/configuration.page +12 -0
- data/doc/src/documentation/plugins/system/index.page +7 -0
- data/doc/src/documentation/plugins/system/logging.page +13 -0
- data/doc/src/documentation/{tags → plugins/tags}/date.page +0 -0
- data/doc/src/documentation/{tags → plugins/tags}/executecommand.page +0 -1
- data/doc/src/documentation/{tags → plugins/tags}/includefile.page +0 -0
- data/doc/src/documentation/{tags → plugins/tags}/index.page +2 -2
- data/doc/src/documentation/{tags → plugins/tags}/langbar.de.page +0 -0
- data/doc/src/documentation/{tags → plugins/tags}/langbar.page +1 -1
- data/doc/src/documentation/{tags → plugins/tags}/menu.de.page +1 -0
- data/doc/src/documentation/{tags → plugins/tags}/menu.page +1 -1
- data/doc/src/documentation/{tags → plugins/tags}/meta.page +0 -0
- data/doc/src/documentation/{tags → plugins/tags}/multilang.de.page +0 -0
- data/doc/src/documentation/{tags → plugins/tags}/multilang.fr.page +0 -0
- data/doc/src/documentation/{tags → plugins/tags}/multilang.page +0 -0
- data/doc/src/documentation/{tags → plugins/tags}/navbar.page +0 -0
- data/doc/src/documentation/{tags → plugins/tags}/relocatable.page +0 -0
- data/doc/src/documentation/{tags → plugins/tags}/sitemap.page +0 -0
- data/doc/src/documentation/{tags → plugins/tags}/wikilink.page +0 -0
- data/doc/src/download.page +1 -0
- data/doc/src/index.page +26 -8
- data/doc/src/meta.info +13 -18
- data/install.rb +1 -1
- data/lib/webgen/configuration.rb +6 -153
- data/lib/webgen/logging.rb +38 -10
- data/lib/webgen/node.rb +26 -6
- data/lib/webgen/plugin.rb +168 -0
- data/lib/webgen/plugins/filehandler/backing.rb +11 -56
- data/lib/webgen/plugins/filehandler/directory.rb +8 -8
- data/lib/webgen/plugins/filehandler/filecopy.rb +2 -2
- data/lib/webgen/plugins/filehandler/filehandler.rb +5 -9
- data/lib/webgen/plugins/filehandler/page.rb +40 -79
- data/lib/webgen/plugins/filehandler/picturegallery.rb +3 -3
- data/lib/webgen/plugins/filehandler/template.rb +2 -2
- data/lib/webgen/plugins/tags/langbar.rb +2 -2
- data/lib/webgen/plugins/tags/menu.rb +5 -13
- data/lib/webgen/plugins/tags/relocatable.rb +2 -2
- data/lib/webgen/plugins/tags/sitemap.rb +2 -2
- data/lib/webgen/plugins/tags/wikilink.rb +4 -3
- data/lib/webgen/webgen.rb +262 -57
- data/testsite/src/default.template +1 -1
- data/testsite/src/images/bghack.png +0 -0
- data/testsite/src/meta.info +7 -10
- metadata +65 -44
- data/doc/extension.config +0 -60
- data/doc/src/documentation/extloader.page +0 -20
- data/doc/src/documentation/filehandler/backing.page +0 -16
- data/lib/webgen/plugins/extloader.rb +0 -88
data/doc/src/meta.info
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
index.
|
|
2
|
-
|
|
3
|
-
menuOrder: 1
|
|
1
|
+
index.html:
|
|
2
|
+
menuOrder: 1
|
|
4
3
|
|
|
5
|
-
download.
|
|
6
|
-
|
|
7
|
-
menuOrder: 3
|
|
4
|
+
download.html:
|
|
5
|
+
menuOrder: 3
|
|
8
6
|
|
|
9
|
-
features.
|
|
10
|
-
|
|
11
|
-
menuOrder: 5
|
|
7
|
+
features.html:
|
|
8
|
+
menuOrder: 5
|
|
12
9
|
|
|
13
|
-
api.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
inMenu: true
|
|
10
|
+
api.html:
|
|
11
|
+
dest: rdoc/index.html
|
|
12
|
+
title: API Reference
|
|
13
|
+
menuOrder: 7
|
|
14
|
+
inMenu: true
|
|
19
15
|
|
|
20
|
-
documentation/index.
|
|
21
|
-
|
|
22
|
-
menuOrder: 9
|
|
16
|
+
documentation/index.html:
|
|
17
|
+
menuOrder: 9
|
data/install.rb
CHANGED
data/lib/webgen/configuration.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#
|
|
2
2
|
#--
|
|
3
3
|
#
|
|
4
|
-
# $Id: configuration.rb
|
|
4
|
+
# $Id: configuration.rb 259 2005-04-21 10:37:47Z thomas $
|
|
5
5
|
#
|
|
6
6
|
# webgen: template based static website generator
|
|
7
7
|
# Copyright (C) 2004 Thomas Leitner
|
|
@@ -20,12 +20,10 @@
|
|
|
20
20
|
#++
|
|
21
21
|
#
|
|
22
22
|
|
|
23
|
-
require 'yaml'
|
|
24
|
-
require 'ostruct'
|
|
25
23
|
require 'find'
|
|
26
24
|
require 'tsort'
|
|
27
25
|
require 'webgen/node'
|
|
28
|
-
require 'webgen/
|
|
26
|
+
require 'webgen/plugin'
|
|
29
27
|
|
|
30
28
|
# Helper class for calculating plugin dependencies.
|
|
31
29
|
class Dependency < Hash
|
|
@@ -37,168 +35,28 @@ class Dependency < Hash
|
|
|
37
35
|
end
|
|
38
36
|
end
|
|
39
37
|
|
|
40
|
-
class OpenStruct
|
|
41
|
-
public :table #:nodoc:#
|
|
42
|
-
end
|
|
43
|
-
|
|
44
38
|
module Webgen
|
|
45
39
|
|
|
46
|
-
VERSION = [0, 3,
|
|
40
|
+
VERSION = [0, 3, 3]
|
|
47
41
|
SUMMARY = "Webgen is a templated based static website generator."
|
|
48
42
|
DESCRIPTION = "Webgen is a web page generator implemented in Ruby. " \
|
|
49
43
|
"It is used to generate static web pages from templates and page " \
|
|
50
44
|
"description files."
|
|
51
45
|
|
|
52
|
-
# Base class for all plugins.
|
|
53
|
-
class Plugin
|
|
54
|
-
|
|
55
|
-
# Holds the plugin data from each and every plugin.
|
|
56
|
-
@@config = {}
|
|
57
|
-
|
|
58
|
-
def self.inherited( klass )
|
|
59
|
-
(@@config[klass] = OpenStruct.new).klass = klass
|
|
60
|
-
@@config[klass].plugin = klass.name.split( /::/ ).last
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
['extension', 'summary', 'description'].each do |name|
|
|
64
|
-
self.module_eval "def self.#{name}( obj ); @@config[self].#{name} = obj; end"
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Return plugin data
|
|
68
|
-
def self.config
|
|
69
|
-
@@config
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# Add a dependency to the plugin. Dependencies are instantiated before the plugin gets
|
|
73
|
-
# instantiated.
|
|
74
|
-
def self.depends_on( *dep )
|
|
75
|
-
dep.each {|d| (@@config[self].dependencies ||= []) << d}
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# Shortcut for getting the plugin with the name +name+.
|
|
79
|
-
def self.[]( name )
|
|
80
|
-
pair = @@config.find {|k,v| v.plugin == name }
|
|
81
|
-
self.logger.warn { "Could not retrieve plugin '#{name}' as such a plugin does not exist!" } if pair.nil?
|
|
82
|
-
pair[1].obj unless pair.nil?
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# Add a parameter for the current class. Has to be used by subclasses to define their parameters!
|
|
86
|
-
#
|
|
87
|
-
# Arguments:
|
|
88
|
-
# +name+:: the name of the parameter
|
|
89
|
-
# +default+:: the default value of the parameter
|
|
90
|
-
# +description+:: a small description of the parameter
|
|
91
|
-
def self.add_param( name, default, description )
|
|
92
|
-
self.logger.debug { "Adding parameter '#{name}' for plugin class '#{self.name}'" }
|
|
93
|
-
data = OpenStruct.new( :name => name, :value => default, :default => default, :description => description )
|
|
94
|
-
(@@config[self].params ||= {})[name] = data
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# Set parameter +name+ for +plugin+ to +value+.
|
|
98
|
-
def self.set_param( plugin, name, value )
|
|
99
|
-
found = catch( :found ) do
|
|
100
|
-
item = @@config.find {|k,v| v.plugin == plugin }[1]
|
|
101
|
-
item.klass.ancestor_classes.each do |k|
|
|
102
|
-
item = @@config[k]
|
|
103
|
-
if !item.nil? && !item.params.nil? && item.params.has_key?( name )
|
|
104
|
-
item.params[name].value = value
|
|
105
|
-
logger.debug { "Setting parameter '#{name}' for plugin '#{plugin}' to #{value.inspect}" }
|
|
106
|
-
throw :found, true
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
logger.error { "Cannot set undefined parameter '#{name}' for plugin '#{plugin}'" } unless found
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
# Return parameter +name+.
|
|
114
|
-
def []( name )
|
|
115
|
-
self.class.ancestor_classes.each do |klass|
|
|
116
|
-
data = @@config[klass]
|
|
117
|
-
return data.params[name].value unless data.params.nil? || data.params[name].nil?
|
|
118
|
-
end
|
|
119
|
-
logger.error { "Referencing invalid configuration value '#{name}' in class #{self.class.name}" }
|
|
120
|
-
return nil
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# Set parameter +name+.
|
|
124
|
-
def []=( name, value )
|
|
125
|
-
self.class.set_param( @@config[self.class].plugin, name, value )
|
|
126
|
-
end
|
|
127
|
-
alias get_param []
|
|
128
|
-
|
|
129
|
-
# Checks if the plugin has a parameter +name+.
|
|
130
|
-
def has_param?( name )
|
|
131
|
-
self.class.ancestor_classes.any? do |klass|
|
|
132
|
-
!@@config[klass].params.nil? && @@config[klass].params.has_key?( name )
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
# Defines a new *handler class. The methods creates two methods based on the parameter +name+:
|
|
137
|
-
# - klass.register_[name]
|
|
138
|
-
# - object.get_[name]
|
|
139
|
-
def self.define_handler( name )
|
|
140
|
-
s = "def self.register_#{name}( param )
|
|
141
|
-
self.logger.info { \"Registering class \#{self.name} for handling '\#{param}'\" }
|
|
142
|
-
(Webgen::Plugin.config[#{self.name}].#{name}s ||= {})[param] = self
|
|
143
|
-
Webgen::Plugin.config[self].registered_#{name} = param
|
|
144
|
-
end\n"
|
|
145
|
-
s += "def get_#{name}( param )
|
|
146
|
-
if Webgen::Plugin.config[#{self.name}].#{name}s.has_key?( param )
|
|
147
|
-
Webgen::Plugin.config[Webgen::Plugin.config[#{self.name}].#{name}s[param]].obj
|
|
148
|
-
else
|
|
149
|
-
self.logger.error { \"Invalid #{name} specified: \#{param}! Using #{self.name}!\" }
|
|
150
|
-
Webgen::Plugin.config[#{self.name}].obj
|
|
151
|
-
end
|
|
152
|
-
end"
|
|
153
|
-
module_eval s
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
#######
|
|
157
|
-
private
|
|
158
|
-
#######
|
|
159
|
-
|
|
160
|
-
# Return the ancestor classes for the object's class which are sub classes from Plugin.
|
|
161
|
-
def self.ancestor_classes
|
|
162
|
-
self.ancestors.delete_if {|c| c.instance_of?( Module ) }[0..-3]
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
|
|
168
46
|
# Responsible for loading the other plugin files and holds the basic configuration options.
|
|
169
47
|
class Configuration < Plugin
|
|
170
48
|
|
|
171
|
-
summary "Responsible for loading
|
|
49
|
+
summary "Responsible for loading plugins and holding general parameters"
|
|
172
50
|
|
|
173
51
|
add_param 'srcDirectory', 'src', 'The directory from which the source files are read.'
|
|
174
52
|
add_param 'outDirectory', 'output', 'The directory to which the output files are written.'
|
|
175
|
-
add_param 'verbosityLevel', 2, 'The level of verbosity for the output of messages on the standard output.'
|
|
176
53
|
add_param 'lang', 'en', 'The default language.'
|
|
177
|
-
add_param 'configfile', 'config.yaml', 'The file from which extra configuration data is taken.'
|
|
178
|
-
add_param 'logfile', 'webgen.log', 'The name of the log file if the log should be written to a file.'
|
|
179
54
|
|
|
180
55
|
# Does all the initialisation stuff
|
|
181
|
-
def init_all
|
|
182
|
-
data.each {|k,v| Plugin['Configuration'][k] = v}
|
|
183
|
-
logger.level = get_param( 'verbosityLevel' )
|
|
184
|
-
|
|
56
|
+
def init_all
|
|
185
57
|
load_plugins( File.dirname( __FILE__) + '/plugins', File.dirname( __FILE__).sub(/webgen$/, '') )
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
data.each {|k,v| Plugin['Configuration'][k] = v}
|
|
189
|
-
logger.level = get_param( 'verbosityLevel' )
|
|
58
|
+
load_plugins( 'plugin', '' )
|
|
190
59
|
init_plugins
|
|
191
|
-
Plugin['ExtensionLoader'].parse_config_file
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
# Parse config file and load the configuration values.
|
|
195
|
-
def parse_config_file
|
|
196
|
-
if File.exists?( get_param( 'configfile' ) )
|
|
197
|
-
@pluginData = YAML::load( File.new( get_param( 'configfile' ) ) )
|
|
198
|
-
@pluginData.each {|plugin, params| params.each {|name,value| Plugin.set_param( plugin, name, value ) } }
|
|
199
|
-
else
|
|
200
|
-
logger.info { "Config file <#{get_param( 'configfile' )}> does not exist, not extra configuration data read." }
|
|
201
|
-
end
|
|
202
60
|
end
|
|
203
61
|
|
|
204
62
|
# Load all plugins in the given +path+. Before +require+ is actually called the path is
|
|
@@ -224,11 +82,6 @@ module Webgen
|
|
|
224
82
|
end
|
|
225
83
|
end
|
|
226
84
|
|
|
227
|
-
# Set the log device to the logfile.
|
|
228
|
-
def set_log_dev_to_logfile
|
|
229
|
-
logger.set_log_dev( File.open( get_param( 'logfile' ), 'a' ) )
|
|
230
|
-
end
|
|
231
|
-
|
|
232
85
|
end
|
|
233
86
|
|
|
234
87
|
# Initialize single configuration instance
|
data/lib/webgen/logging.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#
|
|
2
2
|
#--
|
|
3
3
|
#
|
|
4
|
-
# $Id: logging.rb
|
|
4
|
+
# $Id: logging.rb 259 2005-04-21 10:37:47Z thomas $
|
|
5
5
|
#
|
|
6
6
|
# webgen: template based static website generator
|
|
7
7
|
# Copyright (C) 2004 Thomas Leitner
|
|
@@ -21,19 +21,16 @@
|
|
|
21
21
|
#
|
|
22
22
|
|
|
23
23
|
require 'logger'
|
|
24
|
+
require 'webgen/plugin'
|
|
24
25
|
|
|
25
26
|
module Webgen
|
|
26
27
|
|
|
27
28
|
class Logger < ::Logger
|
|
28
29
|
|
|
29
|
-
def initialize( dev )
|
|
30
|
-
super( dev )
|
|
30
|
+
def initialize( dev, files, size, level )
|
|
31
|
+
super( dev, files, size )
|
|
31
32
|
self.datetime_format = "%Y-%m-%d %H:%M:%S"
|
|
32
|
-
self.level =
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def set_log_dev( dev )
|
|
36
|
-
@logdev = LogDevice.new( dev )
|
|
33
|
+
self.level = level
|
|
37
34
|
end
|
|
38
35
|
|
|
39
36
|
def format_message( severity, timestamp, msg, progname )
|
|
@@ -56,10 +53,14 @@ end
|
|
|
56
53
|
|
|
57
54
|
class Object
|
|
58
55
|
|
|
59
|
-
|
|
56
|
+
@@logger = Webgen::Logger.new( STDERR, 0, 0, Logger::ERROR )
|
|
57
|
+
|
|
58
|
+
def self.set_logger( logger )
|
|
59
|
+
@@logger = logger
|
|
60
|
+
end
|
|
60
61
|
|
|
61
62
|
def logger
|
|
62
|
-
|
|
63
|
+
@@logger
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
end
|
|
@@ -71,3 +72,30 @@ class Module
|
|
|
71
72
|
end
|
|
72
73
|
|
|
73
74
|
end
|
|
75
|
+
|
|
76
|
+
module Webgen
|
|
77
|
+
|
|
78
|
+
class Logging < Plugin
|
|
79
|
+
|
|
80
|
+
summary "Plugin for configuring the logger"
|
|
81
|
+
|
|
82
|
+
add_param 'maxLogFiles', 10, 'The maximum number of log files'
|
|
83
|
+
add_param 'maxLogSize', 1024*1024, 'The maximum size of the log files'
|
|
84
|
+
add_param 'verbosityLevel', 2, 'The level of verbosity for the output of logging messages (0=DEBUG, 1=INFO, 2=WARNING 3=ERROR).',
|
|
85
|
+
lambda {|p,o,n| logger.level = n }
|
|
86
|
+
add_param 'logToFile', false, 'Specifies if the log messages should be put to the logfile',
|
|
87
|
+
(lambda do |p, o, n|
|
|
88
|
+
dev = STDERR
|
|
89
|
+
if n
|
|
90
|
+
Dir.mkdir( 'log' ) unless File.exists?( 'log' )
|
|
91
|
+
dev = 'log/webgen.log'
|
|
92
|
+
end
|
|
93
|
+
Object.set_logger( Webgen::Logger.new( dev, get_param( 'maxLogFiles' ), get_param( 'maxLogSize' ), get_param( 'verbosityLevel') ) )
|
|
94
|
+
end)
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Initialize single logging instance
|
|
99
|
+
Plugin.config[Logging].obj = Logging.new
|
|
100
|
+
|
|
101
|
+
end
|
data/lib/webgen/node.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#
|
|
2
2
|
#--
|
|
3
3
|
#
|
|
4
|
-
# $Id: node.rb
|
|
4
|
+
# $Id: node.rb 258 2005-04-21 10:35:28Z thomas $
|
|
5
5
|
#
|
|
6
6
|
# webgen: template based static website generator
|
|
7
7
|
# Copyright (C) 2004 Thomas Leitner
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
#++
|
|
21
21
|
#
|
|
22
22
|
|
|
23
|
-
require 'webgen/logging'
|
|
24
23
|
require 'util/composite'
|
|
25
24
|
|
|
26
25
|
class Node
|
|
@@ -86,7 +85,7 @@ class Node
|
|
|
86
85
|
def node_for_string( destString )
|
|
87
86
|
node = get_node_for_string( destString )
|
|
88
87
|
if node.nil?
|
|
89
|
-
self.logger.warn { "Could not get destination node '#{destString}' for <#{
|
|
88
|
+
self.logger.warn { "Could not get destination node '#{destString}' for <#{recursive_value( 'src' )}>" }
|
|
90
89
|
end
|
|
91
90
|
node
|
|
92
91
|
end
|
|
@@ -139,11 +138,32 @@ class Node
|
|
|
139
138
|
node = self.parent_dir || self
|
|
140
139
|
end
|
|
141
140
|
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
startElement = node
|
|
142
|
+
elements = destString.split( '/' )
|
|
143
|
+
|
|
144
|
+
elements.each do |element|
|
|
145
|
+
break if node.nil?
|
|
144
146
|
case element
|
|
145
147
|
when '..' then node = node.parent
|
|
146
|
-
else node = node.find
|
|
148
|
+
else node = node.find {|child| /^#{element}\/?$/ =~ child['dest'] }
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# try extended search where child['dest'] can have slashes
|
|
153
|
+
if node.nil?
|
|
154
|
+
node = startElement
|
|
155
|
+
elements.each_with_index do |element, index|
|
|
156
|
+
break if node.nil?
|
|
157
|
+
temp = node.find {|child| /^#{elements[index..-1].join( '/' )}\/?$/ =~ child['dest']}
|
|
158
|
+
if temp.nil?
|
|
159
|
+
case element
|
|
160
|
+
when '..' then node = node.parent
|
|
161
|
+
else node = node.find {|child| /^#{element}\/?$/ =~ child['dest'] }
|
|
162
|
+
end
|
|
163
|
+
else
|
|
164
|
+
node = temp
|
|
165
|
+
break
|
|
166
|
+
end
|
|
147
167
|
end
|
|
148
168
|
end
|
|
149
169
|
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#
|
|
2
|
+
#--
|
|
3
|
+
#
|
|
4
|
+
# $Id: plugin.rb 259 2005-04-21 10:37:47Z thomas $
|
|
5
|
+
#
|
|
6
|
+
# webgen: template based static website generator
|
|
7
|
+
# Copyright (C) 2004 Thomas Leitner
|
|
8
|
+
#
|
|
9
|
+
# This program is free software; you can redistribute it and/or modify it under the terms of the GNU
|
|
10
|
+
# General Public License as published by the Free Software Foundation; either version 2 of the
|
|
11
|
+
# License, or (at your option) any later version.
|
|
12
|
+
#
|
|
13
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
|
14
|
+
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15
|
+
# General Public License for more details.
|
|
16
|
+
#
|
|
17
|
+
# You should have received a copy of the GNU General Public License along with this program; if not,
|
|
18
|
+
# write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19
|
+
#
|
|
20
|
+
#++
|
|
21
|
+
#
|
|
22
|
+
|
|
23
|
+
require 'yaml'
|
|
24
|
+
require 'ostruct'
|
|
25
|
+
|
|
26
|
+
class OpenStruct
|
|
27
|
+
public :table #:nodoc:#
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
module Webgen
|
|
31
|
+
|
|
32
|
+
# Base class for all plugins.
|
|
33
|
+
class Plugin
|
|
34
|
+
|
|
35
|
+
# Holds the plugin data from each and every plugin.
|
|
36
|
+
@@config = {}
|
|
37
|
+
@@configFileData = ( File.exists?( 'config.yaml' ) ? YAML::load( File.new( 'config.yaml' ) ) : {} )
|
|
38
|
+
|
|
39
|
+
def self.inherited( klass )
|
|
40
|
+
(@@config[klass] = OpenStruct.new).klass = klass
|
|
41
|
+
@@config[klass].plugin = klass.name.split( /::/ ).last
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
['summary', 'description'].each do |name|
|
|
45
|
+
self.module_eval "def self.#{name}( obj ); @@config[self].#{name} = obj; end"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Return plugin data
|
|
49
|
+
def self.config
|
|
50
|
+
@@config
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Add a dependency to the plugin. Dependencies are instantiated before the plugin gets
|
|
54
|
+
# instantiated.
|
|
55
|
+
def self.depends_on( *dep )
|
|
56
|
+
dep.each {|d| (@@config[self].dependencies ||= []) << d}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Shortcut for getting the plugin with the name +name+.
|
|
60
|
+
def self.[]( name )
|
|
61
|
+
pair = @@config.find {|k,v| v.plugin == name }
|
|
62
|
+
self.logger.warn { "Could not retrieve plugin '#{name}' as such a plugin does not exist!" } if pair.nil?
|
|
63
|
+
pair[1].obj unless pair.nil?
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Add a parameter for the current class. Has to be used by subclasses to define their parameters!
|
|
67
|
+
#
|
|
68
|
+
# Arguments:
|
|
69
|
+
# +name+:: the name of the parameter
|
|
70
|
+
# +default+:: the default value of the parameter
|
|
71
|
+
# +description+:: a small description of the parameter
|
|
72
|
+
# +changeHandler+:: optional, method/proc which is invoked every time the parameter is changed.
|
|
73
|
+
# Handler signature: changeHandler( paramName, oldValue, newValue )
|
|
74
|
+
def self.add_param( name, default, description, changeHandler = nil )
|
|
75
|
+
self.logger.debug { "Adding parameter '#{name}' for plugin class '#{self.name}'" }
|
|
76
|
+
if @@configFileData.kind_of?( Hash ) && @@configFileData.has_key?( @@config[self].plugin ) \
|
|
77
|
+
&& @@configFileData[@@config[self].plugin].has_key?( name )
|
|
78
|
+
curval = @@configFileData[@@config[self].plugin][name]
|
|
79
|
+
else
|
|
80
|
+
curval = default
|
|
81
|
+
end
|
|
82
|
+
data = OpenStruct.new( :name => name, :value => curval, :default => default, :description => description, :changeHandler => changeHandler )
|
|
83
|
+
(@@config[self].params ||= {})[name] = data
|
|
84
|
+
changeHandler.call( name, default, curval ) if changeHandler
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Set parameter +name+ for +plugin+ to +value+.
|
|
88
|
+
def self.set_param( plugin, name, value )
|
|
89
|
+
found = catch( :found ) do
|
|
90
|
+
item = @@config.find {|k,v| v.plugin == plugin }[1]
|
|
91
|
+
item.klass.ancestor_classes.each do |k|
|
|
92
|
+
item = @@config[k]
|
|
93
|
+
if !item.nil? && !item.params.nil? && item.params.has_key?( name )
|
|
94
|
+
oldvalue = item.params[name].value
|
|
95
|
+
item.params[name].value = value
|
|
96
|
+
item.params[name].changeHandler.call( name, oldvalue, value ) if item.params[name].changeHandler
|
|
97
|
+
logger.debug { "Set parameter '#{name}' for plugin '#{plugin}' to #{value.inspect}" }
|
|
98
|
+
throw :found, true
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
logger.error { "Cannot set undefined parameter '#{name}' for plugin '#{plugin}'" } unless found
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.get_param( name )
|
|
106
|
+
ancestor_classes.each do |klass|
|
|
107
|
+
data = @@config[klass]
|
|
108
|
+
return data.params[name].value unless data.params.nil? || data.params[name].nil?
|
|
109
|
+
end
|
|
110
|
+
logger.error { "Referencing invalid configuration value '#{name}' in class #{self.class.name}" }
|
|
111
|
+
return nil
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Return parameter +name+.
|
|
115
|
+
def []( name )
|
|
116
|
+
self.class.get_param( name )
|
|
117
|
+
end
|
|
118
|
+
alias get_param []
|
|
119
|
+
|
|
120
|
+
# Set parameter +name+.
|
|
121
|
+
def []=( name, value )
|
|
122
|
+
self.class.set_param( @@config[self.class].plugin, name, value )
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Checks if the plugin has a parameter +name+.
|
|
126
|
+
def has_param?( name )
|
|
127
|
+
self.class.ancestor_classes.any? do |klass|
|
|
128
|
+
!@@config[klass].params.nil? && @@config[klass].params.has_key?( name )
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Defines a new *handler class. The methods creates two methods based on the parameter +name+:
|
|
133
|
+
# - klass.register_[name]
|
|
134
|
+
# - object.get_[name]
|
|
135
|
+
def self.define_handler( name )
|
|
136
|
+
s = "def self.register_#{name}( param )
|
|
137
|
+
self.logger.info { \"Registering class \#{self.name} for handling '\#{param}'\" }
|
|
138
|
+
(Webgen::Plugin.config[#{self.name}].#{name}s ||= {})[param] = self
|
|
139
|
+
Webgen::Plugin.config[self].registered_#{name} = param
|
|
140
|
+
end\n"
|
|
141
|
+
s += "def get_#{name}( param )
|
|
142
|
+
if Webgen::Plugin.config[#{self.name}].#{name}s.has_key?( param )
|
|
143
|
+
Webgen::Plugin.config[Webgen::Plugin.config[#{self.name}].#{name}s[param]].obj
|
|
144
|
+
else
|
|
145
|
+
self.logger.error { \"Invalid #{name} specified: \#{param}! Using #{self.name}!\" }
|
|
146
|
+
Webgen::Plugin.config[#{self.name}].obj
|
|
147
|
+
end
|
|
148
|
+
end"
|
|
149
|
+
module_eval s
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
#######
|
|
153
|
+
private
|
|
154
|
+
#######
|
|
155
|
+
|
|
156
|
+
# Return the ancestor classes for the object's class which are sub classes from Plugin.
|
|
157
|
+
def self.ancestor_classes
|
|
158
|
+
self.ancestors.delete_if {|c| c.instance_of?( Module ) }[0..-3]
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
require 'webgen/logging'
|
|
164
|
+
require 'webgen/configuration'
|
|
165
|
+
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
|