webgen 0.3.0 → 0.3.1
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 +280 -0
- data/Rakefile +3 -1
- data/TODO +29 -12
- data/VERSION +1 -1
- data/doc/extension.config +11 -6
- data/doc/src/about.page +21 -0
- data/doc/src/default.css +17 -0
- data/doc/src/default.template +3 -5
- data/doc/src/design.gallery +1 -1
- data/doc/src/designs/curdesign.png +0 -0
- data/doc/src/designs/nostyle.png +0 -0
- data/doc/src/designs/old.png +0 -0
- data/doc/src/documentation/contenthandler/html.page +11 -0
- data/doc/src/documentation/contenthandler/index.page +7 -0
- data/doc/src/documentation/contenthandler/markdown.page +11 -0
- data/doc/src/documentation/contenthandler/rdoc.page +11 -0
- data/doc/src/documentation/contenthandler/textile.page +11 -0
- data/doc/src/documentation/extloader.page +1 -1
- data/doc/src/documentation/filehandler/backing.page +1 -1
- data/doc/src/documentation/filehandler/galleryhandler.page +79 -0
- data/doc/src/documentation/filehandler/{page.page → pagehandler.page} +2 -7
- data/doc/src/documentation/gallerylayouter/defaultlayouter.page +12 -0
- data/doc/src/documentation/gallerylayouter/index.page +14 -0
- data/doc/src/documentation/htmlvalidator/index.page +6 -0
- data/doc/src/documentation/htmlvalidator/xmllint.page +14 -0
- data/doc/src/documentation/index.page +33 -6
- data/doc/src/documentation/tags/index.page +2 -2
- data/doc/src/documentation/tags/{lang.de.page → langbar.de.page} +0 -0
- data/doc/src/documentation/tags/{lang.page → langbar.page} +6 -6
- data/doc/src/documentation/tags/menu.page +1 -1
- data/doc/src/documentation/tags/sitemap.page +18 -0
- data/doc/src/download.page +2 -0
- data/doc/src/features.page +4 -4
- data/doc/src/index.page +18 -20
- data/doc/src/meta.info +5 -5
- data/install.rb +1 -1
- data/lib/webgen/configuration.rb +35 -12
- data/lib/webgen/node.rb +9 -3
- data/lib/webgen/plugins/contenthandler/defaultcontenthandler.rb +39 -0
- data/lib/webgen/plugins/{filehandler/pagehandler → contenthandler}/html.rb +4 -7
- data/lib/webgen/plugins/{filehandler/pagehandler → contenthandler}/markdown.rb +4 -7
- data/lib/webgen/plugins/{filehandler/pagehandler → contenthandler}/rdoc.rb +5 -5
- data/lib/webgen/plugins/{filehandler/pagehandler → contenthandler}/textile.rb +4 -7
- data/lib/webgen/plugins/filehandler/backing.rb +4 -4
- data/lib/webgen/plugins/filehandler/directory.rb +25 -3
- data/lib/webgen/plugins/filehandler/filecopy.rb +4 -2
- data/lib/webgen/plugins/filehandler/filehandler.rb +5 -8
- data/lib/webgen/plugins/filehandler/{pagehandler/page.rb → page.rb} +48 -32
- data/lib/webgen/plugins/filehandler/picturegallery.rb +70 -51
- data/lib/webgen/plugins/gallerylayouter/defaultgallerylayouter.rb +152 -0
- data/lib/webgen/plugins/htmlvalidator/defaulthtmlvalidator.rb +37 -0
- data/lib/webgen/plugins/htmlvalidator/xmllint.rb +70 -0
- data/lib/webgen/plugins/tags/{lang.rb → langbar.rb} +3 -3
- data/lib/webgen/plugins/tags/menu.rb +9 -13
- data/lib/webgen/plugins/tags/relocatable.rb +2 -2
- data/lib/webgen/plugins/tags/sitemap.rb +73 -0
- data/lib/webgen/plugins/tags/tags.rb +9 -9
- data/lib/webgen/plugins/treewalker.rb +2 -2
- data/testsite/src/{images/bghack.png → bghack.png} +0 -0
- metadata +33 -20
- data/doc/src/designs/default.png +0 -0
- data/doc/src/documentation/filehandler/picturegallery.page +0 -25
- data/testsite/src/images/o.png +0 -0
- data/testsite/src/images/smagacor.png +0 -0
- data/testsite/src/images/tictactoe.png +0 -0
- data/testsite/src/images/x.png +0 -0
- data/testsite/src/test.gallery +0 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#
|
|
2
2
|
#--
|
|
3
3
|
#
|
|
4
|
-
# $Id: filecopy.rb
|
|
4
|
+
# $Id: filecopy.rb 210 2005-02-26 13:42:55Z thomas $
|
|
5
5
|
#
|
|
6
6
|
# webgen: template based static website generator
|
|
7
7
|
# Copyright (C) 2004 Thomas Leitner
|
|
@@ -51,7 +51,9 @@ module FileHandlers
|
|
|
51
51
|
|
|
52
52
|
# Copy the file to the destination directory if it has been modified.
|
|
53
53
|
def write_node( node )
|
|
54
|
-
|
|
54
|
+
if Webgen::Plugin['FileHandler'].file_modified?( node.recursive_value( 'src' ), node.recursive_value( 'dest' ) )
|
|
55
|
+
FileUtils.cp( node.recursive_value( 'src' ), node.recursive_value( 'dest' ) )
|
|
56
|
+
end
|
|
55
57
|
end
|
|
56
58
|
|
|
57
59
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#
|
|
2
2
|
#--
|
|
3
3
|
#
|
|
4
|
-
# $Id: filehandler.rb
|
|
4
|
+
# $Id: filehandler.rb 222 2005-03-13 16:30:40Z thomas $
|
|
5
5
|
#
|
|
6
6
|
# webgen: template based static website generator
|
|
7
7
|
# Copyright (C) 2004 Thomas Leitner
|
|
@@ -76,11 +76,9 @@ module FileHandlers
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
# Returns true if the
|
|
79
|
+
# Returns true if the file +src+ is newer than +dest+ and therefore has been modified since the last execution
|
|
80
80
|
# of webgen. The +mtime+ values for the source and destination files are used to find this out.
|
|
81
|
-
def file_modified?(
|
|
82
|
-
src = node.recursive_value( 'src' )
|
|
83
|
-
dest = node.recursive_value( 'dest' )
|
|
81
|
+
def file_modified?( src, dest )
|
|
84
82
|
if File.exists?( dest ) && ( File.mtime( src ) < File.mtime( dest ) )
|
|
85
83
|
self.logger.info { "File is up to date: <#{dest}>" }
|
|
86
84
|
return false
|
|
@@ -130,12 +128,11 @@ module FileHandlers
|
|
|
130
128
|
|
|
131
129
|
if @extensions.has_key?( :dir )
|
|
132
130
|
node = @extensions[:dir].create_node( path, parent )
|
|
133
|
-
node['processor'] = @extensions[:dir]
|
|
134
131
|
|
|
135
132
|
dispatch_msg( :DIR_NODE_CREATED, node )
|
|
136
133
|
|
|
137
134
|
Dir[path + File::SEPARATOR + '{.*,*}'].delete_if do |name|
|
|
138
|
-
name =~ /#{File::SEPARATOR}
|
|
135
|
+
name =~ /#{File::SEPARATOR}\.{1,2}$/ || \
|
|
139
136
|
File.basename( name ) =~ Regexp.new( get_param( 'ignored' ).join( '|' ) )
|
|
140
137
|
end.sort! do |a, b|
|
|
141
138
|
if File.file?( a ) && File.directory?( b )
|
|
@@ -166,7 +163,7 @@ module FileHandlers
|
|
|
166
163
|
summary "Base class of all file handler plugins"
|
|
167
164
|
|
|
168
165
|
def initialize
|
|
169
|
-
extension( Webgen::Plugin.config[self.class
|
|
166
|
+
extension( Webgen::Plugin.config[self.class].extension ) if Webgen::Plugin.config[self.class].extension
|
|
170
167
|
end
|
|
171
168
|
|
|
172
169
|
# Register the file extension specified by a subclass.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#
|
|
2
2
|
#--
|
|
3
3
|
#
|
|
4
|
-
# $Id: page.rb
|
|
4
|
+
# $Id: page.rb 224 2005-03-16 15:26:33Z thomas $
|
|
5
5
|
#
|
|
6
6
|
# webgen: template based static website generator
|
|
7
7
|
# Copyright (C) 2004 Thomas Leitner
|
|
@@ -48,15 +48,12 @@ module FileHandlers
|
|
|
48
48
|
add_param 'defaultLangInFilename', false, \
|
|
49
49
|
'If true, the output files for the default language will have the ' \
|
|
50
50
|
'language in the file name like all other page files. If false, they won''t.'
|
|
51
|
-
add_param 'defaultContentFormat', 'textile', 'The default content format used in page files'
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
super
|
|
58
|
-
@formats = Hash.new( ContentHandlers::ContentHandler.new )
|
|
59
|
-
end
|
|
51
|
+
add_param 'defaultContentFormat', 'textile', 'The default content format used in page files.'
|
|
52
|
+
add_param 'outputNameStyle', [:name, ['.', :lang], '.html'], 'Defines how the output name should be built. The correct name will be used for ' \
|
|
53
|
+
'the :name part and the file language will be used for the :lang part. If <defaultLangInFilename> is true, the :lang part or the subarray in which '\
|
|
54
|
+
'the :lang part was defined, will be omitted.'
|
|
55
|
+
add_param 'validator', 'xmllint', 'The validator for checking HTML files on their validness. Set to "" or nil to prevent checking.'
|
|
56
|
+
depends_on 'FileHandler', 'DefaultContentHandler'
|
|
60
57
|
|
|
61
58
|
def create_node( srcName, parent )
|
|
62
59
|
create_node_internally( parse_data( File.read( srcName ), srcName ), analyse_file_name( File.basename( srcName ) ), parent )
|
|
@@ -78,6 +75,11 @@ module FileHandlers
|
|
|
78
75
|
File.open( node.recursive_value( 'dest' ), File::CREAT|File::TRUNC|File::RDWR ) do |file|
|
|
79
76
|
file.write( outstring )
|
|
80
77
|
end
|
|
78
|
+
|
|
79
|
+
validator = get_param( 'validator' )
|
|
80
|
+
unless validator.nil? || validator == ''
|
|
81
|
+
Webgen::Plugin['DefaultHTMLValidator'].get_validator( validator ).validate_file( node.recursive_value( 'dest' ) )
|
|
82
|
+
end
|
|
81
83
|
end
|
|
82
84
|
|
|
83
85
|
def page_node_exists?( basename, dirNode )
|
|
@@ -124,11 +126,12 @@ module FileHandlers
|
|
|
124
126
|
else
|
|
125
127
|
node = Node.new( pageNode )
|
|
126
128
|
node.metainfo = data
|
|
127
|
-
node['
|
|
128
|
-
node['dest'] = analysed.urlName
|
|
129
|
+
node['node:isLangNode'] = true
|
|
129
130
|
node['lang'] ||= analysed.lang
|
|
130
131
|
node['title'] ||= analysed.title
|
|
131
132
|
node['menuOrder'] ||= analysed.menuOrder
|
|
133
|
+
node['src'] = analysed.srcName
|
|
134
|
+
node['dest'] = create_output_name( analysed, node.metainfo )
|
|
132
135
|
node['processor'] = self
|
|
133
136
|
pageNode.add_child( node )
|
|
134
137
|
end
|
|
@@ -150,8 +153,12 @@ module FileHandlers
|
|
|
150
153
|
end
|
|
151
154
|
blocks.each {|b| b.gsub!( /^(\\+)(---\s*)$/ ) {|m| "\\" * ($1.length / 2) + $2 } }
|
|
152
155
|
(options['blocks'] ||= [{'name'=>'content', 'format'=>get_param( 'defaultContentFormat' )}]).each do |blockdata|
|
|
156
|
+
if !blockdata.kind_of?( Hash ) || !blockdata['name'] || !blockdata['format']
|
|
157
|
+
self.logger.error { "Block meta information in <#{srcName}> invalid (#{blockdata.inspect})" }
|
|
158
|
+
next
|
|
159
|
+
end
|
|
153
160
|
self.logger.debug { "Block '#{blockdata['name']}' formatted using '#{blockdata['format']}'" }
|
|
154
|
-
options[blockdata['name']] =
|
|
161
|
+
options[blockdata['name']] = Webgen::Plugin['DefaultContentHandler'].get_format( blockdata['format'] ).format_content( blocks.shift || '' )
|
|
155
162
|
end
|
|
156
163
|
end
|
|
157
164
|
options
|
|
@@ -163,10 +170,10 @@ module FileHandlers
|
|
|
163
170
|
|
|
164
171
|
self.logger.info { "Using default language for file <#{srcName}>" } if matchData[3].nil?
|
|
165
172
|
analysed.lang = matchData[3] || Webgen::Plugin['Configuration']['lang']
|
|
166
|
-
analysed.baseName = matchData[2] + '.
|
|
173
|
+
analysed.baseName = matchData[2] + '.page'
|
|
167
174
|
analysed.srcName = srcName
|
|
168
|
-
|
|
169
|
-
analysed.
|
|
175
|
+
analysed.useLangPart = ( !get_param( 'defaultLangInFilename' ) && Webgen::Plugin['Configuration']['lang'] == analysed.lang ? false : true )
|
|
176
|
+
analysed.name = matchData[2]
|
|
170
177
|
analysed.menuOrder = matchData[1].to_i
|
|
171
178
|
analysed.title = matchData[2].tr('_-', ' ').capitalize
|
|
172
179
|
|
|
@@ -175,29 +182,38 @@ module FileHandlers
|
|
|
175
182
|
analysed
|
|
176
183
|
end
|
|
177
184
|
|
|
185
|
+
def create_output_name( analysed, data )
|
|
186
|
+
def process_array( array, analysed )
|
|
187
|
+
array.collect do |part|
|
|
188
|
+
case part
|
|
189
|
+
when String
|
|
190
|
+
part
|
|
191
|
+
when :name
|
|
192
|
+
analysed.name
|
|
193
|
+
when :lang
|
|
194
|
+
analysed.useLangPart ? analysed.lang : ''
|
|
195
|
+
when Array
|
|
196
|
+
part.include?( :lang ) && !analysed.useLangPart ? '' : process_array( part, analysed )
|
|
197
|
+
else
|
|
198
|
+
''
|
|
199
|
+
end
|
|
200
|
+
end.join( '' )
|
|
201
|
+
end
|
|
202
|
+
process_array( data['outputNameStyle'] || get_param( 'outputNameStyle' ), analysed )
|
|
203
|
+
end
|
|
204
|
+
|
|
178
205
|
end
|
|
179
206
|
|
|
180
207
|
end
|
|
181
208
|
|
|
209
|
+
module HTMLValidators
|
|
182
210
|
|
|
183
|
-
|
|
211
|
+
class HTMLValidator < Webgen::Plugin
|
|
184
212
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
VIRTUAL = true
|
|
188
|
-
|
|
189
|
-
summary "Base class for all page file content handlers"
|
|
190
|
-
|
|
191
|
-
# Register the format specified by a subclass.
|
|
192
|
-
def register_format( fmt )
|
|
193
|
-
self.logger.info { "Registering class #{self.class.name} for formatting '#{fmt}'" }
|
|
194
|
-
Webgen::Plugin['PageHandler'].formats[fmt] = self
|
|
195
|
-
end
|
|
213
|
+
summary "Base class for all HTML validators"
|
|
196
214
|
|
|
197
|
-
#
|
|
198
|
-
def
|
|
199
|
-
self.logger.error { "Invalid content format specified, copying source verbatim!" }
|
|
200
|
-
content
|
|
215
|
+
# Should be overridden in subclass!
|
|
216
|
+
def validate_file( filename )
|
|
201
217
|
end
|
|
202
218
|
|
|
203
219
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#
|
|
2
2
|
#--
|
|
3
3
|
#
|
|
4
|
-
# $Id: picturegallery.rb
|
|
4
|
+
# $Id: picturegallery.rb 221 2005-03-12 17:14:11Z thomas $
|
|
5
5
|
#
|
|
6
6
|
# webgen: template based static website generator
|
|
7
7
|
# Copyright (C) 2004 Thomas Leitner
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
require 'webgen/plugins/filehandler/filehandler'
|
|
24
24
|
require 'webgen/plugins/filehandler/directory'
|
|
25
|
-
require 'webgen/plugins/filehandler/
|
|
25
|
+
require 'webgen/plugins/filehandler/page'
|
|
26
26
|
|
|
27
27
|
module FileHandlers
|
|
28
28
|
|
|
@@ -33,6 +33,7 @@ module FileHandlers
|
|
|
33
33
|
add_param "picturesPerPage", 20, 'Number of picture per gallery page'
|
|
34
34
|
add_param "picturePageInMenu", false, 'True if the picture pages should be in the menu'
|
|
35
35
|
add_param "galleryPageInMenu", false, 'True if the gallery pages should be in the menu'
|
|
36
|
+
add_param "galleryMenuOrder", 50, 'The <menuOrder> metainfo for the first gallery page. The second gallery page gets this value plus one, and so on.'
|
|
36
37
|
add_param "mainPageInMenu", true, 'True if the main page of the picture gallery should be in the menu'
|
|
37
38
|
add_param "galleryPageTemplate", nil, 'The template for gallery pages. If nil or a not existing file is specified, the default template is used.'
|
|
38
39
|
add_param "picturePageTemplate", nil, 'The template for picture pages. If nil or a not existing file is specified, the default template is used.'
|
|
@@ -50,8 +51,8 @@ module FileHandlers
|
|
|
50
51
|
self.logger.error { "Could not parse gallery file <#{file}>, not creating gallery pages" }
|
|
51
52
|
return
|
|
52
53
|
end
|
|
53
|
-
path = File.dirname( file )
|
|
54
|
-
images = Dir[File.join( path, get_param( 'files' ))].collect {|i| i.sub( /#{path + File::SEPARATOR}/, '' ) }
|
|
54
|
+
@path = File.dirname( file )
|
|
55
|
+
images = Dir[File.join( @path, get_param( 'files' ))].collect {|i| i.sub( /#{@path + File::SEPARATOR}/, '' ) }
|
|
55
56
|
self.logger.info { "Creating gallery for file <#{file}> with #{images.length} pictures" }
|
|
56
57
|
|
|
57
58
|
create_gallery( images, parent )
|
|
@@ -72,64 +73,60 @@ module FileHandlers
|
|
|
72
73
|
( @filedata.has_key?( name ) ? @filedata[name] : super )
|
|
73
74
|
end
|
|
74
75
|
|
|
75
|
-
def call_layouter( type,
|
|
76
|
-
content =
|
|
77
|
-
"#{
|
|
76
|
+
def call_layouter( type, metainfo, *args )
|
|
77
|
+
content = Webgen::Plugin['DefaultGalleryLayouter'].get_layout( get_param( 'layout' ) ).send( type.to_s, *args )
|
|
78
|
+
"#{metainfo.to_yaml}\n---\n#{content}"
|
|
78
79
|
end
|
|
79
80
|
|
|
80
81
|
def create_gallery( images, parent )
|
|
81
|
-
|
|
82
|
-
main =
|
|
83
|
-
main['galleries'] = create_gallery_pages( images )
|
|
82
|
+
main = create_main_page( images, parent )
|
|
83
|
+
main['galleries'] = create_gallery_pages( images, parent )
|
|
84
84
|
|
|
85
|
-
if
|
|
86
|
-
mainNode = Webgen::Plugin['PageHandler'].create_node_from_data( call_layouter( :main, main ), main['srcName'], parent )
|
|
85
|
+
if main['galleries'].length != 1
|
|
86
|
+
mainNode = Webgen::Plugin['PageHandler'].create_node_from_data( call_layouter( :main, main, main ), main['srcName'], parent )
|
|
87
87
|
parent.add_child( mainNode )
|
|
88
88
|
else
|
|
89
89
|
main['galleries'][0]['title'] = main['title']
|
|
90
90
|
main['galleries'][0]['inMenu'] = main['inMenu']
|
|
91
91
|
main['galleries'][0].update( @filedata['mainPage'] || {} )
|
|
92
|
+
main['pageNotUsed'] = true
|
|
92
93
|
end
|
|
93
94
|
|
|
94
|
-
main['galleries'].
|
|
95
|
-
node = Webgen::Plugin['PageHandler'].create_node_from_data( call_layouter( :gallery, gallery ), gallery['
|
|
95
|
+
main['galleries'].each_with_index do |gallery, gIndex|
|
|
96
|
+
node = Webgen::Plugin['PageHandler'].create_node_from_data( call_layouter( :gallery, gallery, main, gIndex ), gallery['srcName'], parent )
|
|
96
97
|
parent.add_child( node )
|
|
97
|
-
gallery['imageList'].
|
|
98
|
-
node = Webgen::Plugin['PageHandler'].create_node_from_data( call_layouter( :picture, image ), image['srcName'], parent )
|
|
98
|
+
gallery['imageList'].each_with_index do |image, iIndex|
|
|
99
|
+
node = Webgen::Plugin['PageHandler'].create_node_from_data( call_layouter( :picture, image, main, gIndex, iIndex ), image['srcName'], parent )
|
|
99
100
|
parent.add_child( node )
|
|
100
101
|
end
|
|
101
102
|
end
|
|
102
103
|
end
|
|
103
104
|
|
|
104
|
-
def create_main_page( images )
|
|
105
|
+
def create_main_page( images, parent )
|
|
105
106
|
main = {}
|
|
106
107
|
main['title'] = get_param( 'title' )
|
|
107
108
|
main['inMenu'] = get_param( 'mainPageInMenu' )
|
|
108
109
|
main['template'] = get_param( 'mainPageTemplate' )
|
|
109
110
|
main['srcName'] = gallery_file_name( main['title'] )
|
|
111
|
+
main['blocks'] = [{'name'=>'content', 'format'=>'html'}]
|
|
110
112
|
main.update( @filedata['mainPage'] || {} )
|
|
111
113
|
main
|
|
112
114
|
end
|
|
113
115
|
|
|
114
|
-
def create_gallery_pages( images )
|
|
116
|
+
def create_gallery_pages( images, parent )
|
|
115
117
|
galleries = []
|
|
116
118
|
picsPerPage = get_param( 'picturesPerPage' )
|
|
117
119
|
0.step( images.length - 1, picsPerPage ) do |i|
|
|
118
|
-
data =
|
|
120
|
+
data = (@filedata['galleryPages'] || {}).dup
|
|
119
121
|
|
|
120
|
-
data['
|
|
121
|
-
data['
|
|
122
|
+
data['blocks'] ||= [{'name'=>'content', 'format'=>'html'}]
|
|
123
|
+
data['template'] ||= get_param( 'galleryPageTemplate' )
|
|
124
|
+
data['inMenu'] ||= get_param( 'galleryPageInMenu' )
|
|
122
125
|
data['number'] = i/picsPerPage + 1
|
|
126
|
+
data['menuOrder'] = get_param( 'galleryMenuOrder' ) + data['number']
|
|
123
127
|
data['title'] = gallery_title( data['number'] )
|
|
124
|
-
data['
|
|
125
|
-
data['
|
|
126
|
-
data['prevGalleryTitle'] = gallery_title( data['prevGalleryNumber'] )
|
|
127
|
-
data['prevGalleryLink'] = gallery_file_name( data['prevGalleryTitle'] )
|
|
128
|
-
data['nextGalleryNumber']= ( images.length <= i + picsPerPage ? nil : data['number'] + 1 )
|
|
129
|
-
data['nextGalleryTitle'] = gallery_title( data['nextGalleryNumber'] )
|
|
130
|
-
data['nextGalleryLink'] = gallery_file_name( data['nextGalleryTitle'] )
|
|
131
|
-
data['images'] = images[i..(i + picsPerPage - 1)]
|
|
132
|
-
data['imageList'] = create_picture_pages( data['images'] )
|
|
128
|
+
data['srcName'] = gallery_file_name( data['title'] )
|
|
129
|
+
data['imageList'] = create_picture_pages( images[i..(i + picsPerPage - 1)], parent )
|
|
133
130
|
|
|
134
131
|
galleries << data
|
|
135
132
|
end
|
|
@@ -144,51 +141,73 @@ module FileHandlers
|
|
|
144
141
|
( title.nil? ? nil : title.tr( ' .', '_' ) + '.html' )
|
|
145
142
|
end
|
|
146
143
|
|
|
147
|
-
def create_picture_pages( images )
|
|
144
|
+
def create_picture_pages( images, parent )
|
|
148
145
|
imageList = []
|
|
149
146
|
images.each do |image|
|
|
150
|
-
imageData = @filedata[image] || {}
|
|
147
|
+
imageData = (@filedata[image] || {}).dup
|
|
151
148
|
|
|
149
|
+
imageData['blocks'] ||= [{'name'=>'content', 'format'=>'html'}]
|
|
152
150
|
imageData['title'] ||= "Picture #{File.basename( image )}"
|
|
153
151
|
imageData['description'] ||= ''
|
|
154
|
-
imageData['inMenu']
|
|
155
|
-
imageData['template']
|
|
152
|
+
imageData['inMenu'] ||= get_param( 'picturePageInMenu' )
|
|
153
|
+
imageData['template'] ||= get_param( 'picturePageTemplate' )
|
|
156
154
|
imageData['imageFilename'] = image
|
|
157
155
|
imageData['srcName'] = File.basename( image ).tr( ' .', '_' ) + '.html'
|
|
156
|
+
imageData['thumbnail'] ||= get_thumbnail( imageData, parent )
|
|
158
157
|
|
|
159
158
|
imageList << imageData
|
|
160
159
|
end
|
|
161
160
|
imageList
|
|
162
161
|
end
|
|
163
162
|
|
|
164
|
-
def
|
|
165
|
-
|
|
166
|
-
#{data['galleries'].collect {|g| "<img src='#{g['images'][0]}' width='100' height='100' alt='#{g['title']}' /> \"#{g['title']}\":#{g['link']}"}.join( "\n\n" )}
|
|
167
|
-
"
|
|
163
|
+
def get_thumbnail( imageData, parent )
|
|
164
|
+
imageData['imageFilename']
|
|
168
165
|
end
|
|
169
166
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Try to use RMagick as thumbnail creator
|
|
170
|
+
begin
|
|
171
|
+
require 'RMagick'
|
|
172
|
+
|
|
173
|
+
class PictureGalleryFileHandler
|
|
173
174
|
|
|
174
|
-
|
|
175
|
+
def get_thumbnail( imageData, parent )
|
|
176
|
+
p_node = Webgen::Plugin['DirHandler'].recursive_create_path( File.dirname( imageData['imageFilename'] ), parent )
|
|
177
|
+
node = Webgen::Plugin['ThumbnailWriter'].create_node( File.join( @path, imageData['imageFilename'] ), p_node )
|
|
178
|
+
p_node.add_child( node )
|
|
179
|
+
|
|
180
|
+
File.dirname( imageData['imageFilename'] ) + '/' + node['dest']
|
|
181
|
+
end
|
|
175
182
|
|
|
176
|
-
</div>
|
|
177
|
-
"
|
|
178
183
|
end
|
|
179
184
|
|
|
180
|
-
|
|
181
|
-
"
|
|
182
|
-
<div class=\"webgen-picture\">
|
|
185
|
+
class ThumbnailWriter < DefaultHandler
|
|
183
186
|
|
|
184
|
-
|
|
187
|
+
summary "Writes out thumbnails with RMagick"
|
|
188
|
+
add_param "thumbnailSize", "100x100", "The size of the thumbnails"
|
|
185
189
|
|
|
186
|
-
|
|
190
|
+
def create_node( file, parent )
|
|
191
|
+
node = Node.new( parent )
|
|
192
|
+
node['title'] = node['src'] = node['dest'] = 'tn_' + File.basename( file )
|
|
193
|
+
node['tn:imageFile'] = file
|
|
194
|
+
node['processor'] = self
|
|
195
|
+
node
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def write_node( node )
|
|
199
|
+
if Webgen::Plugin['FileHandler'].file_modified?( node['tn:imageFile'], node.recursive_value( 'dest' ) )
|
|
200
|
+
self.logger.info {"Creating thumbnail <#{node.recursive_value('dest')}> from <#{node['tn:imageFile']}>"}
|
|
201
|
+
image = Magick::ImageList.new( node['tn:imageFile'] )
|
|
202
|
+
image.change_geometry( get_param( 'thumbnailSize' ) ) {|c,r,i| i.resize!( c, r )}
|
|
203
|
+
image.write( node.recursive_value( 'dest' ) )
|
|
204
|
+
end
|
|
205
|
+
end
|
|
187
206
|
|
|
188
|
-
{description: }
|
|
189
|
-
"
|
|
190
207
|
end
|
|
191
208
|
|
|
209
|
+
rescue LoadError => e
|
|
210
|
+
self.logger.warn { "Could not load RMagick, creation of thumbnails not available" }
|
|
192
211
|
end
|
|
193
212
|
|
|
194
213
|
end
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#
|
|
2
|
+
#--
|
|
3
|
+
#
|
|
4
|
+
# $Id: defaultgallerylayouter.rb 220 2005-03-12 15:41:05Z 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
|
+
module PictureGalleryLayouter
|
|
24
|
+
|
|
25
|
+
class DefaultGalleryLayouter < Webgen::Plugin
|
|
26
|
+
|
|
27
|
+
summary "Base class for all Picture Gallery Layouters and, at the same time, default layouter"
|
|
28
|
+
|
|
29
|
+
define_handler 'layout'
|
|
30
|
+
|
|
31
|
+
register_layout 'default'
|
|
32
|
+
|
|
33
|
+
# Returns the thumbnail img tag for the given +image+.
|
|
34
|
+
def thumbnail_tag_for_image( image )
|
|
35
|
+
if image['thumbnail'] != image['imageFilename']
|
|
36
|
+
"<img src='#{image['thumbnail']}' alt='#{image['title']}' />"
|
|
37
|
+
else
|
|
38
|
+
"<img src='#{image['imageFilename']}' width='100' height='100' alt='#{image['title']}'/>"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Returns the gallery index of the previous gallery, if it exists, or +nil+ otherwise.
|
|
43
|
+
def prev_gallery( data, gIndex )
|
|
44
|
+
gIndex != 0 ? gIndex - 1 : nil
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Returns the gallery index of the next gallery, if it exists, or +nil+ otherwise.
|
|
48
|
+
def next_gallery( data, gIndex )
|
|
49
|
+
gIndex != data['galleries'].length - 1 ? gIndex + 1 : nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Returns the gallery and image indices of the previous picture, if it exists, or +nil+ otherwise.
|
|
53
|
+
def prev_picture( data, gIndex, iIndex )
|
|
54
|
+
result = nil
|
|
55
|
+
if gIndex != 0 || iIndex != 0
|
|
56
|
+
if iIndex == 0
|
|
57
|
+
gIndex -= 1
|
|
58
|
+
iIndex = data['galleries'][gIndex]['imageList'].length - 1
|
|
59
|
+
else
|
|
60
|
+
iIndex -= 1
|
|
61
|
+
end
|
|
62
|
+
result = [gIndex, iIndex]
|
|
63
|
+
end
|
|
64
|
+
return result
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Returns the gallery and image indices of the next picture, if it exists, or +nil+ otherwise.
|
|
68
|
+
def next_picture( data, gIndex, iIndex )
|
|
69
|
+
result = nil
|
|
70
|
+
if gIndex != data['galleries'].length - 1 || iIndex != data['galleries'][gIndex]['imageList'].length - 1
|
|
71
|
+
if iIndex == data['galleries'][gIndex]['imageList'].length - 1
|
|
72
|
+
gIndex += 1
|
|
73
|
+
iIndex = 0
|
|
74
|
+
else
|
|
75
|
+
iIndex += 1
|
|
76
|
+
end
|
|
77
|
+
result = [gIndex, iIndex]
|
|
78
|
+
end
|
|
79
|
+
return result
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Should be overwritten by subclasses! +data+ is the data structure which holds all information
|
|
83
|
+
# about the gallery.
|
|
84
|
+
def main( data )
|
|
85
|
+
s = "
|
|
86
|
+
<h2>#{data['title']}</h2>
|
|
87
|
+
<div class=\"webgen-gallery\">
|
|
88
|
+
<table>
|
|
89
|
+
"
|
|
90
|
+
0.step( data['galleries'].length - 1, 5 ) do |i|
|
|
91
|
+
s += "<tr>"
|
|
92
|
+
s += data['galleries'][i...i+5].collect {|g| "<td><a href=\"#{g['srcName']}\">#{thumbnail_tag_for_image( g['imageList'][0] )}<br />#{g['title']}</a></td>"}.join( "\n" )
|
|
93
|
+
s += "</tr>"
|
|
94
|
+
end
|
|
95
|
+
s += "</table></div>"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Should be overwritten by subclasses! +data+ is the data structure which holds all information
|
|
99
|
+
# about the gallery. +gIndex+ is the index of the current gallery.
|
|
100
|
+
def gallery( data, gIndex )
|
|
101
|
+
|
|
102
|
+
s = "
|
|
103
|
+
<h2>#{data['galleries'][gIndex]['title']}</h2>
|
|
104
|
+
<div class=\"webgen-gallery\">
|
|
105
|
+
"
|
|
106
|
+
|
|
107
|
+
s += "<a href=\"#{data['srcName']}\">^ #{data['title']} ^</a><br />" unless data['pageNotUsed']
|
|
108
|
+
prevIndex = prev_gallery( data, gIndex )
|
|
109
|
+
nextIndex = next_gallery( data, gIndex )
|
|
110
|
+
s += "<a href=\"#{data['galleries'][prevIndex]['srcName']}\">< #{data['galleries'][prevIndex]['title']}</a>" unless prevIndex.nil?
|
|
111
|
+
s += " — " unless prevIndex.nil? || nextIndex.nil?
|
|
112
|
+
s += "<a href=\"#{data['galleries'][nextIndex]['srcName']}\">#{data['galleries'][nextIndex]['title']} ></a>" unless nextIndex.nil?
|
|
113
|
+
s += "<br />"
|
|
114
|
+
|
|
115
|
+
s += "<table>"
|
|
116
|
+
0.step( data['galleries'][gIndex]['imageList'].length - 1, 5 ) do |i|
|
|
117
|
+
s += "<tr>"
|
|
118
|
+
s += data['galleries'][gIndex]['imageList'][i...i+5].collect {|i| "<td><a href=\"#{i['srcName']}\">#{thumbnail_tag_for_image( i )}<br />#{i['title']}</a></td>"}.join( "\n" )
|
|
119
|
+
s += "</tr>"
|
|
120
|
+
end
|
|
121
|
+
s += "</table></div>"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Should be overwritten by subclasses! +data+ is the data structure which holds all information
|
|
125
|
+
# about the gallery. +gIndex+ is the index of the current gallery. +iIndex+ is the index of the
|
|
126
|
+
# current image.
|
|
127
|
+
def picture( data, gIndex, iIndex )
|
|
128
|
+
s = "
|
|
129
|
+
<h2>#{data['galleries'][gIndex]['imageList'][iIndex]['title']}</h2>
|
|
130
|
+
<div class=\"webgen-picture\">
|
|
131
|
+
"
|
|
132
|
+
s += "<a href=\"#{data['galleries'][gIndex]['srcName']}\">^ #{data['galleries'][gIndex]['title']} ^</a><br />"
|
|
133
|
+
prevGIndex, prevIIndex = prev_picture( data, gIndex, iIndex )
|
|
134
|
+
nextGIndex, nextIIndex = next_picture( data, gIndex, iIndex )
|
|
135
|
+
s += "<a href=\"#{data['galleries'][prevGIndex]['imageList'][prevIIndex]['srcName']}\">" \
|
|
136
|
+
"< #{data['galleries'][prevGIndex]['imageList'][prevIIndex]['title']}</a>" unless prevGIndex.nil?
|
|
137
|
+
s += " — " unless prevGIndex.nil? || nextGIndex.nil?
|
|
138
|
+
s += "<a href=\"#{data['galleries'][nextGIndex]['imageList'][nextIIndex]['srcName']}\">" \
|
|
139
|
+
"#{data['galleries'][nextGIndex]['imageList'][nextIIndex]['title']} ></a>" unless nextGIndex.nil?
|
|
140
|
+
s += "<br />"
|
|
141
|
+
|
|
142
|
+
s += "
|
|
143
|
+
<img src='#{data['galleries'][gIndex]['imageList'][iIndex]['imageFilename']}' alt='#{data['galleries'][gIndex]['imageList'][iIndex]['title']}' />
|
|
144
|
+
|
|
145
|
+
<p>{description: }</p>
|
|
146
|
+
</div>
|
|
147
|
+
"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
end
|