webgen 0.3.4 → 0.3.5
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 +201 -0
- data/Rakefile +3 -2
- data/TODO +31 -4
- data/VERSION +1 -1
- data/data/webgen/example/config.yaml +2 -0
- data/data/webgen/example/src/default.css +84 -0
- data/data/webgen/example/src/default.template +32 -0
- data/data/webgen/example/src/index.page +8 -0
- data/{doc/src → data/webgen/images}/generated_by_webgen.png +0 -0
- data/data/webgen/images/valid-css.gif +0 -0
- data/data/webgen/images/valid-xhtml11.png +0 -0
- data/data/webgen/images/webgen_logo.png +0 -0
- data/doc/config.yaml +2 -0
- data/doc/plugin/extension.rb +8 -4
- data/doc/plugin/resources.rb +30 -0
- data/doc/src/default.css +251 -149
- data/doc/src/default.template +8 -8
- data/doc/src/documentation/gettingstarted.page +1 -1
- data/doc/src/documentation/index.page +6 -2
- data/doc/src/documentation/plugins/filehandler/backing.page +22 -9
- data/doc/src/documentation/plugins/filehandler/galleryhandler.page +1 -1
- data/doc/src/documentation/plugins/filehandler/index.page +9 -4
- data/doc/src/documentation/plugins/filehandler/pagehandler.page +33 -10
- data/doc/src/documentation/plugins/index.page +9 -1
- data/doc/src/documentation/plugins/menustyles/horizontal-dropdown.page +42 -0
- data/doc/src/documentation/plugins/menustyles/horizontal.page +21 -0
- data/doc/src/documentation/plugins/menustyles/index.page +12 -0
- data/doc/src/documentation/plugins/menustyles/partial.page +27 -0
- data/doc/src/documentation/plugins/menustyles/vertical-dropdown.page +23 -0
- data/doc/src/documentation/plugins/menustyles/vertical.page +32 -0
- data/doc/src/documentation/plugins/resourcemanager.page +30 -0
- data/doc/src/documentation/plugins/tags/index.page +2 -2
- data/doc/src/documentation/plugins/tags/langbar.page +4 -4
- data/doc/src/documentation/plugins/tags/menu.page +6 -17
- data/doc/src/documentation/plugins/tags/navbar.page +2 -1
- data/doc/src/documentation/plugins/tags/resource.page +22 -0
- data/doc/src/download.page +1 -1
- data/doc/src/features.page +32 -9
- data/doc/src/index.page +24 -10
- data/doc/src/meta.info +16 -6
- data/install.rb +1 -1
- data/lib/webgen/configuration.rb +24 -2
- data/lib/webgen/node.rb +29 -5
- data/lib/webgen/plugin.rb +1 -5
- data/lib/webgen/plugins/contenthandler/textile.rb +3 -3
- data/lib/webgen/plugins/filehandler/backing.rb +5 -4
- data/lib/webgen/plugins/filehandler/directory.rb +3 -3
- data/lib/webgen/plugins/filehandler/filehandler.rb +8 -4
- data/lib/webgen/plugins/filehandler/page.rb +33 -18
- data/lib/webgen/plugins/filehandler/picturegallery.rb +10 -8
- data/lib/webgen/plugins/menustyles/defaultmenustyle.rb +73 -0
- data/lib/webgen/plugins/menustyles/horizontal.rb +93 -0
- data/lib/webgen/plugins/menustyles/horizontal_dropdown.rb +113 -0
- data/lib/webgen/plugins/menustyles/partial.rb +95 -0
- data/lib/webgen/plugins/menustyles/vertical.rb +107 -0
- data/lib/webgen/plugins/menustyles/vertical_dropdown.rb +107 -0
- data/lib/webgen/plugins/resourcemanager.rb +264 -0
- data/lib/webgen/plugins/tags/langbar.rb +9 -5
- data/lib/webgen/plugins/tags/menu.rb +4 -66
- data/lib/webgen/plugins/treewalker.rb +7 -6
- data/lib/webgen/webgen.rb +72 -161
- metadata +37 -6
- data/doc/src/logo.png +0 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
#
|
4
|
+
# $Id: vertical.rb 293 2005-06-11 08:37:51Z 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 'webgen/plugins/menustyles/defaultmenustyle'
|
24
|
+
|
25
|
+
module MenuStyles
|
26
|
+
|
27
|
+
class VerticalMenuStyle < MenuStyles::DefaultMenuStyle
|
28
|
+
|
29
|
+
summary "Builds a vertical menu"
|
30
|
+
|
31
|
+
register_menu_style 'vertical'
|
32
|
+
|
33
|
+
add_param 'level', 1, \
|
34
|
+
'Specifies how many levels the menu should have by default, ie. how deep it is. ' \
|
35
|
+
'For example, if level = 3, then three levels are always shown at least.'
|
36
|
+
add_param 'subtreeLevel', 3, \
|
37
|
+
'Specifies how many levels should be shown for subtrees. The number specifies ' \
|
38
|
+
'the maximum depth the menu will have.'
|
39
|
+
add_param 'showCurrentSubtreeOnly', true, \
|
40
|
+
'True if only the current subtree should be shown in the menu. If set to false, ' \
|
41
|
+
'each subtree will be shown.'
|
42
|
+
|
43
|
+
CSS = "
|
44
|
+
/* START Webgen vertical menu style */
|
45
|
+
.webgen-menu-vert li > ul {
|
46
|
+
font-size: 95%;
|
47
|
+
}
|
48
|
+
|
49
|
+
.webgen-menu-vert ul {
|
50
|
+
padding: 0px;
|
51
|
+
margin-left: 10px;
|
52
|
+
}
|
53
|
+
|
54
|
+
.webgen-menu-vert li {
|
55
|
+
padding-left: 5px;
|
56
|
+
}
|
57
|
+
|
58
|
+
.webgen-menu-vert .webgen-menu-submenu-inhierarchy > a {
|
59
|
+
font-weight: bold;
|
60
|
+
}
|
61
|
+
|
62
|
+
.webgen-menu-vert .webgen-menu-item-selected > a {
|
63
|
+
font-weight: bold;
|
64
|
+
}
|
65
|
+
/* STOP Webgen vertical menu style */
|
66
|
+
"
|
67
|
+
|
68
|
+
def internal_build_menu( srcNode, menuTree )
|
69
|
+
unless defined?( @css_added )
|
70
|
+
Webgen::Plugin['ResourceManager'].append_data( 'webgen-css', CSS )
|
71
|
+
@css_added = true
|
72
|
+
end
|
73
|
+
"<div class=\"webgen-menu-vert #{get_param('divClass')}\">#{submenu( srcNode, menuTree, 1 )}</div>"
|
74
|
+
end
|
75
|
+
|
76
|
+
#######
|
77
|
+
private
|
78
|
+
#######
|
79
|
+
|
80
|
+
def submenu( srcNode, node, level )
|
81
|
+
if node.nil? \
|
82
|
+
|| level > get_param( 'subtreeLevel' ) \
|
83
|
+
|| ( level > get_param( 'level' ) \
|
84
|
+
&& ( node['node'].level > srcNode.level \
|
85
|
+
|| ( get_param( 'showCurrentSubtreeOnly' ) && !srcNode.in_subtree?( node['node'] ) )
|
86
|
+
)
|
87
|
+
)
|
88
|
+
return ''
|
89
|
+
end
|
90
|
+
|
91
|
+
out = "<ul>"
|
92
|
+
node.each do |child|
|
93
|
+
menu = child['node']['int:directory?'] ? submenu( srcNode, child, level + 1 ) : ''
|
94
|
+
style, link = menu_item_details( srcNode, child['node'] )
|
95
|
+
|
96
|
+
out << "<li #{style}>#{link}"
|
97
|
+
out << menu
|
98
|
+
out << "</li>"
|
99
|
+
end
|
100
|
+
out << "</ul>"
|
101
|
+
|
102
|
+
return out
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
#
|
4
|
+
# $Id: vertical_dropdown.rb 300 2005-06-14 10:04:17Z 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 'webgen/plugins/menustyles/defaultmenustyle'
|
24
|
+
|
25
|
+
module MenuStyles
|
26
|
+
|
27
|
+
class VerticalDropdownMenuStyle < MenuStyles::DefaultMenuStyle
|
28
|
+
|
29
|
+
summary "Builds a vertical menu with CSS drop down submenus"
|
30
|
+
|
31
|
+
register_menu_style 'vertical-dropdown'
|
32
|
+
|
33
|
+
CSS = "
|
34
|
+
/* START Webgen vertical dropdown menu style */
|
35
|
+
.webgen-menu-vert-dd ul {
|
36
|
+
list-style-type: none;
|
37
|
+
margin: 0;
|
38
|
+
padding: 0;
|
39
|
+
width: 15em;
|
40
|
+
}
|
41
|
+
|
42
|
+
.webgen-menu-vert-dd ul ul {
|
43
|
+
border: 1px solid black;
|
44
|
+
position: absolute;
|
45
|
+
z-index: 500;
|
46
|
+
left: 100%;
|
47
|
+
top: 0;
|
48
|
+
}
|
49
|
+
|
50
|
+
.webgen-menu-vert-dd a {
|
51
|
+
display: block;
|
52
|
+
margin: 0px;
|
53
|
+
padding: 3px 3px;
|
54
|
+
background-color: white;
|
55
|
+
}
|
56
|
+
|
57
|
+
.webgen-menu-vert-dd li {
|
58
|
+
position: relative;
|
59
|
+
}
|
60
|
+
|
61
|
+
.webgen-menu-vert-dd ul ul {
|
62
|
+
display: none;
|
63
|
+
}
|
64
|
+
|
65
|
+
.webgen-menu-vert-dd ul li:hover > ul > ul {
|
66
|
+
display: none;
|
67
|
+
}
|
68
|
+
|
69
|
+
.webgen-menu-vert-dd ul li:hover > ul {
|
70
|
+
display: block;
|
71
|
+
}
|
72
|
+
/* STOP Webgen vertical dropdown menu style */
|
73
|
+
"
|
74
|
+
|
75
|
+
def internal_build_menu( srcNode, menuTree )
|
76
|
+
unless defined?( @css_added )
|
77
|
+
Webgen::Plugin['ResourceManager'].append_data( 'webgen-css', CSS )
|
78
|
+
@css_added = true
|
79
|
+
end
|
80
|
+
"<div class=\"webgen-menu-vert-dd #{get_param('divClass')}\">#{submenu( srcNode, menuTree, 1 )}</div>"
|
81
|
+
end
|
82
|
+
|
83
|
+
#######
|
84
|
+
private
|
85
|
+
#######
|
86
|
+
|
87
|
+
def submenu( srcNode, node, level )
|
88
|
+
out = ''
|
89
|
+
out = "<ul>" if level > 1
|
90
|
+
node.each do |child|
|
91
|
+
menu = child['node']['int:directory?'] ? submenu( srcNode, child, level + 1 ) : ''
|
92
|
+
style, link = menu_item_details( srcNode, child['node'] )
|
93
|
+
|
94
|
+
out << "<ul>" if level == 1
|
95
|
+
out << "<li #{style}>#{link}"
|
96
|
+
out << menu
|
97
|
+
out << "</li>"
|
98
|
+
out << "</ul>" if level == 1
|
99
|
+
end
|
100
|
+
out << "</ul>" if level > 1
|
101
|
+
|
102
|
+
return out
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,264 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
#
|
4
|
+
# $Id: resourcemanager.rb 300 2005-06-14 10:04:17Z 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 'rbconfig'
|
24
|
+
require 'fileutils'
|
25
|
+
require 'webgen/plugins/tags/tags'
|
26
|
+
require 'webgen/plugins/filehandler/filehandler'
|
27
|
+
|
28
|
+
module Webgen
|
29
|
+
|
30
|
+
class ResourceManager < Plugin
|
31
|
+
|
32
|
+
class Resource
|
33
|
+
|
34
|
+
attr_reader :name
|
35
|
+
attr_reader :output_path
|
36
|
+
attr_accessor :predefined
|
37
|
+
attr_accessor :type
|
38
|
+
|
39
|
+
def initialize( name, type, output_path )
|
40
|
+
@name = name
|
41
|
+
@type = type
|
42
|
+
@output_path = output_path.sub( /^\//, '' )
|
43
|
+
@used = false
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns the relative path from the node to the resource.
|
47
|
+
def relpath_from_node( node )
|
48
|
+
node.relpath_to_string( '/' + @output_path )
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the complete destination path.
|
52
|
+
def dest_path
|
53
|
+
File.join( Webgen::Plugin['Configuration']['outDirectory'], @output_path )
|
54
|
+
end
|
55
|
+
|
56
|
+
# Mark the resource as referenced. Only referenced resources are written to the output directory.
|
57
|
+
def referenced!
|
58
|
+
@referenced = true
|
59
|
+
end
|
60
|
+
|
61
|
+
# Has the resource been used somewhere?
|
62
|
+
def referenced?
|
63
|
+
@referenced
|
64
|
+
end
|
65
|
+
|
66
|
+
# Can the resource be written to the output directory?
|
67
|
+
def write_resource?
|
68
|
+
@referenced
|
69
|
+
end
|
70
|
+
|
71
|
+
# Write the resource to the output directory.
|
72
|
+
def write_resource
|
73
|
+
raise NotImplementedError
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
class FileResource < Resource
|
79
|
+
|
80
|
+
attr_reader :res_path
|
81
|
+
|
82
|
+
def initialize( name, output_path, res_path )
|
83
|
+
super( name, :file, output_path )
|
84
|
+
@res_path = res_path
|
85
|
+
end
|
86
|
+
|
87
|
+
def data
|
88
|
+
File.read( @res_path )
|
89
|
+
end
|
90
|
+
|
91
|
+
def write_resource?
|
92
|
+
referenced? && Webgen::Plugin['FileHandler'].file_modified?( @res_path, dest_path )
|
93
|
+
end
|
94
|
+
|
95
|
+
def write_resource
|
96
|
+
FileUtils.cp( res_path, dest_path ) if write_resource?
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
class MemoryResource < Resource
|
102
|
+
|
103
|
+
def initialize( name, output_path )
|
104
|
+
super( name, :memory, output_path )
|
105
|
+
@data = ''
|
106
|
+
end
|
107
|
+
|
108
|
+
def data
|
109
|
+
@data
|
110
|
+
end
|
111
|
+
|
112
|
+
def append_data( data )
|
113
|
+
@data << data
|
114
|
+
end
|
115
|
+
|
116
|
+
def write_resource
|
117
|
+
File.open( dest_path, 'w' ) {|file| file.write( data )} if write_resource?
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
summary "Provides access to pre- and userdefined resources"
|
124
|
+
description "The resource manager manages a list of predefined and " \
|
125
|
+
"userdefined resources. These resources can be used in page files."
|
126
|
+
add_param 'resources', [], 'User defined file resources. Value has to be an array of arrays with three strings defining '\
|
127
|
+
'name, resource path and output path'
|
128
|
+
|
129
|
+
depends_on 'FileHandler'
|
130
|
+
|
131
|
+
attr_reader :data_dir
|
132
|
+
|
133
|
+
def initialize
|
134
|
+
Plugin.config[self.class].resources = {}
|
135
|
+
Plugin['FileHandler'].add_msg_listener( :AFTER_ALL_WRITTEN, method( :write_resources ) )
|
136
|
+
define_webgen_resources unless Webgen::Configuration.data_dir.empty?
|
137
|
+
define_user_resources
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
# Adds an exisiting file resource which can be referenced later by using +name+. The +output_path+
|
142
|
+
# should be an absolute path, like +/images/logo.png+. If not, it will be relative to the output
|
143
|
+
# directory.
|
144
|
+
def define_file_resource( name, resource_path, output_path )
|
145
|
+
if !File.exists?( resource_path )
|
146
|
+
logger.error { "Path <#{resource_path}> for resource #{name} is invalid!" }
|
147
|
+
else
|
148
|
+
define_resource( name, FileResource.new( name, output_path, resource_path ) )
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
# Adds a new resource which can be referenced later by using +name+. The +output_path+
|
154
|
+
# should be an absolute path, like +/images/logo.png+. If not, it will be relative to the output
|
155
|
+
# directory.
|
156
|
+
def define_memory_resource( name, output_path )
|
157
|
+
define_resource( name, MemoryResource.new( name, output_path ) )
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
# Returns the requested resource.
|
162
|
+
def get_resource( name )
|
163
|
+
Plugin.config[self.class].resources[name]
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
# Appends given +data+ to the resource +name+. Data can only be appended to memory resources!
|
168
|
+
def append_data( name, data )
|
169
|
+
if (res = get_resource( name )) && res.type == :memory
|
170
|
+
res.append_data( data )
|
171
|
+
else
|
172
|
+
logger.error {"Resource #{name} does not exist or data cannot be appended to it!" }
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
#######
|
177
|
+
private
|
178
|
+
#######
|
179
|
+
|
180
|
+
def define_resource( name, res )
|
181
|
+
if Plugin.config[self.class].resources.has_key?( name )
|
182
|
+
logger.error { "Resource #{name} already defined, not using new definition (#{res.inspect})" }
|
183
|
+
else
|
184
|
+
logger.info { "Adding resource #{name} to pool (#{res.inspect})" }
|
185
|
+
Plugin.config[self.class].resources[name] = res
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def define_webgen_resources
|
190
|
+
define_file_resource( 'webgen-logo', File.join( Webgen::Configuration.data_dir, 'images', 'webgen_logo.png' ),
|
191
|
+
'/images/webgen-logo.png' ).predefined = "The logo of webgen as seen on the homepage."
|
192
|
+
define_file_resource( 'webgen-generated', File.join( Webgen::Configuration.data_dir, 'images', 'generated_by_webgen.png' ),
|
193
|
+
'/images/webgen-generated-by.png' ).predefined = "A 88x31 image for use on web sites that were generated by webgen."
|
194
|
+
define_file_resource( 'w3c-valid-css', File.join( Webgen::Configuration.data_dir, 'images', 'valid-css.gif' ),
|
195
|
+
'/images/w3c-valid-css.gif' ).predefined = 'The W3C image for valid css.'
|
196
|
+
define_file_resource( 'w3c-valid-xhtml11', File.join( Webgen::Configuration.data_dir, 'images', 'valid-xhtml11.png' ),
|
197
|
+
'/images/w3c-valid-xhtml11.png' ).predefined = "The W3C image for valid XHTML1.1"
|
198
|
+
|
199
|
+
define_memory_resource( 'webgen-css', '/css/webgen.css' ).predefined = "Plugins use this resource for their CSS styles."
|
200
|
+
define_memory_resource( 'webgen-javascript', '/css/webgen.js' ).predefined = "Plugins use this resource for their Javascript fragments."
|
201
|
+
end
|
202
|
+
|
203
|
+
def define_user_resources
|
204
|
+
p = get_param( 'resources' )
|
205
|
+
if !p.kind_of?( Array ) || p.find {|h| !h.kind_of?( Array ) || h.length != 3}
|
206
|
+
logger.error { "Parameter resources not correctly structured!" }
|
207
|
+
return
|
208
|
+
end
|
209
|
+
p.each {|name, res_path, out_path| define_file_resource( name, res_path, out_path ) }
|
210
|
+
end
|
211
|
+
|
212
|
+
|
213
|
+
def write_resources
|
214
|
+
Plugin.config[self.class].resources.each do |name, res|
|
215
|
+
if res.write_resource?
|
216
|
+
begin
|
217
|
+
FileUtils.makedirs( File.dirname( res.dest_path ) )
|
218
|
+
res.write_resource
|
219
|
+
logger.info { "Resource #{name} written to <#{res.dest_path}>" }
|
220
|
+
rescue Exception => e
|
221
|
+
logger.error { "Error while writing resource #{name}: #{e.message}" }
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
module Tags
|
233
|
+
|
234
|
+
class ResourceTag < DefaultTag
|
235
|
+
|
236
|
+
summary "Used for referencing resources"
|
237
|
+
description "This tag should be used output the path to a resource or the resource itself."
|
238
|
+
|
239
|
+
add_param 'name', nil, 'The name of the resource'
|
240
|
+
add_param 'insert', :path, 'What should be returned by the tag: the path to the resource (value :path) ' \
|
241
|
+
'or the data (value :data)'
|
242
|
+
|
243
|
+
set_mandatory 'name', true
|
244
|
+
|
245
|
+
depends_on 'Tags'
|
246
|
+
|
247
|
+
def initialize
|
248
|
+
super
|
249
|
+
register_tag( 'resource' )
|
250
|
+
end
|
251
|
+
|
252
|
+
def process_tag( tag, node, refNode )
|
253
|
+
result = ''
|
254
|
+
if res = Webgen::Plugin['ResourceManager'].get_resource( get_param( 'name' ) )
|
255
|
+
result = (get_param( 'insert' ) == :path ? res.referenced! && res.relpath_from_node( node ) : res.data )
|
256
|
+
else
|
257
|
+
logger.error { "Could not retrieve resource #{get_param( 'name' )} as it does not exist!" }
|
258
|
+
end
|
259
|
+
result
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|