webgen 0.3.0

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.
Files changed (105) hide show
  1. data/COPYING +340 -0
  2. data/ChangeLog +2172 -0
  3. data/README +16 -0
  4. data/Rakefile +283 -0
  5. data/TODO +133 -0
  6. data/VERSION +1 -0
  7. data/bin/webgen +5 -0
  8. data/doc/extension.config +55 -0
  9. data/doc/src/default.css +129 -0
  10. data/doc/src/default.template +45 -0
  11. data/doc/src/design.gallery +18 -0
  12. data/doc/src/designs/default.png +0 -0
  13. data/doc/src/designs/nostyle.png +0 -0
  14. data/doc/src/designs/old.png +0 -0
  15. data/doc/src/documentation/extloader.page +20 -0
  16. data/doc/src/documentation/filehandler/backing.page +16 -0
  17. data/doc/src/documentation/filehandler/copy.page +12 -0
  18. data/doc/src/documentation/filehandler/directory.page +15 -0
  19. data/doc/src/documentation/filehandler/index.page +13 -0
  20. data/doc/src/documentation/filehandler/page.page +122 -0
  21. data/doc/src/documentation/filehandler/picturegallery.page +25 -0
  22. data/doc/src/documentation/filehandler/template.page +21 -0
  23. data/doc/src/documentation/index.page +47 -0
  24. data/doc/src/documentation/tags/date.page +19 -0
  25. data/doc/src/documentation/tags/executecommand.page +19 -0
  26. data/doc/src/documentation/tags/includefile.page +15 -0
  27. data/doc/src/documentation/tags/index.page +39 -0
  28. data/doc/src/documentation/tags/lang.de.page +6 -0
  29. data/doc/src/documentation/tags/lang.page +27 -0
  30. data/doc/src/documentation/tags/menu.de.page +11 -0
  31. data/doc/src/documentation/tags/menu.page +30 -0
  32. data/doc/src/documentation/tags/meta.page +20 -0
  33. data/doc/src/documentation/tags/multilang.de.page +4 -0
  34. data/doc/src/documentation/tags/multilang.fr.page +4 -0
  35. data/doc/src/documentation/tags/multilang.page +4 -0
  36. data/doc/src/documentation/tags/navbar.page +19 -0
  37. data/doc/src/documentation/tags/relocatable.page +16 -0
  38. data/doc/src/documentation/tags/wikilink.page +18 -0
  39. data/doc/src/download.page +42 -0
  40. data/doc/src/features.page +14 -0
  41. data/doc/src/index.page +48 -0
  42. data/doc/src/logo.png +0 -0
  43. data/doc/src/meta.info +22 -0
  44. data/install.rb +19 -0
  45. data/lib/util/composite.rb +101 -0
  46. data/lib/util/listener.rb +105 -0
  47. data/lib/webgen/configuration.rb +216 -0
  48. data/lib/webgen/logging.rb +73 -0
  49. data/lib/webgen/node.rb +147 -0
  50. data/lib/webgen/plugins/extloader.rb +88 -0
  51. data/lib/webgen/plugins/filehandler/backing.rb +200 -0
  52. data/lib/webgen/plugins/filehandler/directory.rb +96 -0
  53. data/lib/webgen/plugins/filehandler/filecopy.rb +59 -0
  54. data/lib/webgen/plugins/filehandler/filehandler.rb +209 -0
  55. data/lib/webgen/plugins/filehandler/pagehandler/html.rb +43 -0
  56. data/lib/webgen/plugins/filehandler/pagehandler/markdown.rb +53 -0
  57. data/lib/webgen/plugins/filehandler/pagehandler/page.rb +205 -0
  58. data/lib/webgen/plugins/filehandler/pagehandler/rdoc.rb +50 -0
  59. data/lib/webgen/plugins/filehandler/pagehandler/textile.rb +52 -0
  60. data/lib/webgen/plugins/filehandler/picturegallery.rb +194 -0
  61. data/lib/webgen/plugins/filehandler/template.rb +98 -0
  62. data/lib/webgen/plugins/tags/date.rb +46 -0
  63. data/lib/webgen/plugins/tags/executecommand.rb +53 -0
  64. data/lib/webgen/plugins/tags/includefile.rb +60 -0
  65. data/lib/webgen/plugins/tags/lang.rb +50 -0
  66. data/lib/webgen/plugins/tags/menu.rb +198 -0
  67. data/lib/webgen/plugins/tags/meta.rb +54 -0
  68. data/lib/webgen/plugins/tags/navbar.rb +62 -0
  69. data/lib/webgen/plugins/tags/relocatable.rb +58 -0
  70. data/lib/webgen/plugins/tags/tags.rb +247 -0
  71. data/lib/webgen/plugins/tags/wikilink.rb +58 -0
  72. data/lib/webgen/plugins/treewalker.rb +81 -0
  73. data/lib/webgen/webgen.rb +155 -0
  74. data/setup.rb +1331 -0
  75. data/testsite/config.yaml +7 -0
  76. data/testsite/src/bluecloth.page +102 -0
  77. data/testsite/src/default.css +146 -0
  78. data/testsite/src/default.template +33 -0
  79. data/testsite/src/home.en.page +22 -0
  80. data/testsite/src/home.page +22 -0
  81. data/testsite/src/images/bghack.png +0 -0
  82. data/testsite/src/images/o.png +0 -0
  83. data/testsite/src/images/smagacor.png +0 -0
  84. data/testsite/src/images/tictactoe.png +0 -0
  85. data/testsite/src/images/x.png +0 -0
  86. data/testsite/src/index.page +21 -0
  87. data/testsite/src/meta.info +15 -0
  88. data/testsite/src/news.page +20 -0
  89. data/testsite/src/news_are_so-cool.de.page +19 -0
  90. data/testsite/src/noindex/noindex.page +20 -0
  91. data/testsite/src/pictures/index.page +20 -0
  92. data/testsite/src/projects.de.page +11 -0
  93. data/testsite/src/projects.es.page +11 -0
  94. data/testsite/src/projects.page +17 -0
  95. data/testsite/src/projects/00.index.de.page +10 -0
  96. data/testsite/src/projects/01.project2.page +20 -0
  97. data/testsite/src/projects/02.project1.page +20 -0
  98. data/testsite/src/projects/05.project3.page +22 -0
  99. data/testsite/src/projects/index.page +20 -0
  100. data/testsite/src/projects/subproj/index.page +22 -0
  101. data/testsite/src/projects/subproj/project3.page +21 -0
  102. data/testsite/src/rdoc.page +12 -0
  103. data/testsite/src/redcloth.page +106 -0
  104. data/testsite/src/test.gallery +5 -0
  105. metadata +155 -0
@@ -0,0 +1,147 @@
1
+ #
2
+ #--
3
+ #
4
+ # $Id: node.rb 203 2005-02-21 18:42:04Z 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/logging'
24
+ require 'util/composite'
25
+
26
+ class Node
27
+
28
+ include Composite
29
+
30
+ attr_reader :parent
31
+ attr_accessor :metainfo
32
+
33
+ def initialize( parent )
34
+ @parent = parent
35
+ @metainfo = Hash.new
36
+ end
37
+
38
+ # Get object +name+ from +metainfo+.
39
+ def []( name )
40
+ @metainfo[name]
41
+ end
42
+
43
+ # Assign +value+ to +metainfo+ called +name.
44
+ def []=( name, value )
45
+ @metainfo[name] = value
46
+ end
47
+
48
+ # Get the recursive value for metainfo +name+. +ignoreVirtual+ specifies if virtual nodes should
49
+ # not be appended, but they are traversed nonetheless.
50
+ def recursive_value( name, ignoreVirtual = true )
51
+ value = ignoreVirtual && @metainfo['virtual'] ? '' : @metainfo[name]
52
+ if value.nil?
53
+ value = ''
54
+ self.logger.warn { "No meta information called '#{name}' for <#{metainfo['src']}>" }
55
+ end
56
+ @parent.nil? ? value : @parent.recursive_value( name, ignoreVirtual ) + value
57
+ end
58
+
59
+
60
+ # Return the relative path from this node to the destNode, virtual nodes are not used in the
61
+ # calculation. The destNode can be any non virtual node. If +destNode+ starts with http://, the
62
+ # relative path to it is the empty string. If +includeDestNode+ is true, then the path of the
63
+ # destination node is appended to the calculated path.
64
+ def relpath_to_node( destNode, includeDestNode = true)
65
+ if destNode['dest'] =~ /^http:\/\//
66
+ path = ''
67
+ else
68
+ from = recursive_value( 'dest' ).sub( /#{self['dest']}$/, '' ).split( '/' )[1..-1] || []
69
+ to = destNode.recursive_value( 'dest' ).sub( /#{destNode['dest']}$/, '' ).split( '/' )[1..-1] || []
70
+
71
+ while from.size > 0 and to.size > 0 and from[0] == to[0]
72
+ from.shift
73
+ to.shift
74
+ end
75
+
76
+ from.fill( '..' )
77
+ from.concat( to )
78
+ path = ( from.length == 0 ? '.' : from.join( '/' ) )
79
+ path += '/' + destNode['dest'] if includeDestNode && !destNode.parent.nil?
80
+ end
81
+ path
82
+ end
83
+
84
+
85
+ # Return the node identified by +destString+ relative to the current node.
86
+ def node_for_string( destString )
87
+ node = get_node_for_string( destString )
88
+ if node.nil?
89
+ self.logger.warn { "Could not get destination node '#{destString}' for <#{metainfo['src']}>" }
90
+ end
91
+ node
92
+ end
93
+
94
+ # Check if there is a node for +destString+.
95
+ def node_for_string?( destString )
96
+ get_node_for_string( destString ) != nil
97
+ end
98
+
99
+ # Return the level of the node. The level specifies how deep the node is in the hierarchy.
100
+ def level( ignoreVirtual = true )
101
+ if self.parent.nil?
102
+ 1
103
+ else
104
+ self.parent.level( ignoreVirtual ) \
105
+ + ( (@metainfo['virtual'] && ignoreVirtual) || (@metainfo['dest'] !~ /\/$/) ? 0 : 1 )
106
+ end
107
+ end
108
+
109
+ # Checks if the current node is in the subtree in which the supplied node is. This is done by
110
+ # analyzing the paths of the two nodes.
111
+ def in_subtree?( node )
112
+ node = node.parent if node.metainfo['dest'] !~ /\/$/
113
+ node = node.parent while node['virtual']
114
+ /^#{node.recursive_value( 'dest' )}/ =~ recursive_value( 'dest' )
115
+ end
116
+
117
+ # Returns the root node for +node+.
118
+ def self.root( node )
119
+ node = node.parent until node.parent.nil?
120
+ node
121
+ end
122
+
123
+ #######
124
+ private
125
+ #######
126
+
127
+ def get_node_for_string( destString )
128
+ if /^\// =~ destString
129
+ node = Node.root( self )
130
+ destString = destString[1..-1]
131
+ else
132
+ node = self.parent || self
133
+ node = node.parent while !node.nil? && node['virtual']
134
+ end
135
+
136
+ destString.split( '/' ).each do |element|
137
+ return nil if node.nil?
138
+ case element
139
+ when '..' then node = node.parent
140
+ else node = node.find do |child| /^#{element}\/?$/ =~ child['dest'] end
141
+ end
142
+ end
143
+
144
+ node
145
+ end
146
+
147
+ end
@@ -0,0 +1,88 @@
1
+ #
2
+ #--
3
+ #
4
+ # $Id: extloader.rb 203 2005-02-21 18:42:04Z 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/tags/tags'
24
+ require 'webgen/plugins/filehandler/filehandler'
25
+
26
+ module Webgen
27
+
28
+ # Loads website specific extensions.
29
+ class ExtensionLoader < Plugin
30
+
31
+ summary "Loads extensions from a configuration file"
32
+ depends_on 'Tags', 'FileHandler'
33
+ add_param 'extconfig', 'extension.config', 'Configuration file for extensions'
34
+
35
+ def parse_config_file
36
+ file = get_param( 'extconfig' )
37
+ if File.exists?( file )
38
+ begin
39
+ instance_eval( File.read( file ), file )
40
+ rescue Exception => e
41
+ self.logger.error { "Error parsing file <#{file}>: #{e.message}" }
42
+ end
43
+ end
44
+ end
45
+
46
+ def simple_tag( name, processOutput = true, &block )
47
+ register_tag( name, Tags::SimpleTag.new( processOutput, block ) )
48
+ end
49
+
50
+ def register_tag( name, processor )
51
+ Plugin['Tags'].tags[name] = processor
52
+ end
53
+
54
+ def register_filehandler( name, processor )
55
+ Plugin['FileHandler'].extensions[name] = processor
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+
63
+ module Tags
64
+
65
+ class SimpleTag < DefaultTag
66
+
67
+ VIRTUAL = true
68
+
69
+ summary "Used by the Tag Loader, provides the interface used by the Tags class"
70
+
71
+ def initialize( processOutput, block )
72
+ super()
73
+ @processOutput = processOutput
74
+ @block = block
75
+ end
76
+
77
+ def process_tag( tag, node, refNode )
78
+ begin
79
+ @block.call( tag, node, refNode )
80
+ rescue Exception => e
81
+ self.logger.error { "Error executing extension code: #{e.message}" }
82
+ return ''
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,200 @@
1
+ #
2
+ #--
3
+ #
4
+ # $Id: backing.rb 203 2005-02-21 18:42:04Z 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/filehandler/filehandler'
24
+ require 'webgen/plugins/filehandler/directory'
25
+ require 'webgen/plugins/filehandler/pagehandler/page'
26
+
27
+ module FileHandlers
28
+
29
+ # Handles page description backing files. Backing files are files that specify meta information
30
+ # for other files. They are written in YAML and have a very easy structure:
31
+ #
32
+ # filename1.html:
33
+ # lang1:
34
+ # metainfo1: value1
35
+ # metainfo2: value2
36
+ # lang2:
37
+ # metainfo21: value21
38
+ #
39
+ # dir1/../dir1/filenam2.html:
40
+ # lang1:
41
+ # title: New titel by backing file
42
+ #
43
+ # /index.html:
44
+ # lang1:
45
+ # title: YES!!!
46
+ #
47
+ # As you can see, you can use relative and absoulte paths in the filenames. However, you cannot
48
+ # specify meta information for files which are in one of the parent directories of the backing
49
+ # file. These backing files are very useful if you are using page description files which do not
50
+ # support meta information, e.g. HTML fragment files.
51
+ #
52
+ # Using backing files you can add virtual files and directories. If the file specified in the
53
+ # entry does not exist, a virtual page node for that entry will be created. This will also create
54
+ # the whole directory tree this virtual node is in. This allows you, for example, to add external
55
+ # items to the menu. You need to specify the +dest+ meta information which points to the actual
56
+ # location of the referenced page. If the virtual page references an external page, you have to
57
+ # add the +external+ meta information (i.e. set +external+ to +true+).
58
+ class BackingFileHandler < DefaultHandler
59
+
60
+ summary "Handles backing files for page file"
61
+ extension 'info'
62
+ depends_on 'FileHandler'
63
+
64
+ def initialize
65
+ super
66
+ Webgen::Plugin['FileHandler'].add_msg_listener( :AFTER_DIR_READ, method( :process_backing_file ) )
67
+ end
68
+
69
+ def create_node( path, parent )
70
+ node = Node.new( parent )
71
+ node['src'] = node['dest'] = node['title'] = File.basename( path )
72
+ begin
73
+ node['content'] = YAML::load( File.new( path ) )
74
+ if !valid_content( node['content'] )
75
+ node['content'] = {}
76
+ self.logger.error { "Content of backing file <#{backingFile.recursive_value( 'src' )}> not correctcly structured" }
77
+ end
78
+ rescue
79
+ self.logger.error { "Content not correctly formatted (should be valid YAML) in backing file <#{path}>" }
80
+ ensure
81
+ node['content'] ||= {}
82
+ end
83
+ node['processor'] = self
84
+ node
85
+ end
86
+
87
+ def write_node( node )
88
+ # nothing to write
89
+ end
90
+
91
+ #######
92
+ private
93
+ #######
94
+
95
+ def valid_content( data )
96
+ data.kind_of?( Hash ) \
97
+ && data.all? {|k,v| v.kind_of?( Hash ) && v.all? {|k1,v1| v1.kind_of?( Hash )} }
98
+ end
99
+
100
+ def process_backing_file( dirNode )
101
+ backingFiles = dirNode.find_all {|child| /\.#{Webgen::Plugin.config[self.class.name].extension}$/ =~ child['src'] }
102
+
103
+ backingFiles.each do |backingFile|
104
+ backingFile['content'].each do |filename, data|
105
+ if dirNode.node_for_string?( filename )
106
+ backedFile = dirNode.node_for_string( filename )
107
+ data.each do |language, fileData|
108
+ langFile = Webgen::Plugin['PageHandler'].get_lang_node( backedFile, language )
109
+ next unless langFile['lang'] == language
110
+
111
+ self.logger.info { "Setting meta info data on file <#{langFile.recursive_value( 'dest' )}>" }
112
+ langFile.metainfo.update( fileData )
113
+ end
114
+ else
115
+ add_virtual_node( dirNode, filename, data )
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+
122
+ def add_virtual_node( dirNode, path, data )
123
+ dirname = File.dirname( path ).sub( /^.$/, '' )
124
+ filename = File.basename( path )
125
+ dirNode = create_path( dirname, dirNode )
126
+
127
+ data.each do |language, filedata|
128
+ self.logger.debug { "Trying to create virtual node for '#{filename}'..." }
129
+ filedata['lang'] = language
130
+
131
+ handler = VirtualPageHandler.new
132
+ pageNode = handler.create_node_from_data( '', filename, dirNode )
133
+ unless pageNode.nil?
134
+ pageNode['processor'] = Webgen::Plugin['VirtualPageHandler']
135
+ self.logger.debug { "Adding virtual page node <#{pageNode.recursive_value( 'src', false )}> to directory <#{dirNode.recursive_value( 'src' )}>" }
136
+ dirNode.add_child( pageNode )
137
+ end
138
+ pageNode ||= Webgen::Plugin['VirtualPageHandler'].get_page_node( filename, dirNode ) #TODO
139
+ node = Webgen::Plugin['VirtualPageHandler'].get_lang_node( pageNode, language )
140
+ node.metainfo.update( filedata )
141
+ self.logger.info { "Created virtual node <#{node.recursive_value( 'src' )}> (#{language}) in <#{dirNode.recursive_value( 'dest' )}> " \
142
+ "referencing '#{node['dest']}'" }
143
+ end
144
+ end
145
+
146
+
147
+ def create_path( dirname, dirNode )
148
+ if /^#{File::SEPARATOR}/ =~ dirname
149
+ node = Node.root( dirNode )
150
+ dirname = dirname[1..-1]
151
+ else
152
+ node = dirNode
153
+ end
154
+
155
+ parent = node
156
+ dirname.split( File::SEPARATOR ).each do |element|
157
+ case element
158
+ when '..'
159
+ node = node.parent
160
+ else
161
+ node = node.find do |child| /^#{element}\/?$/ =~ child['src'] end
162
+ end
163
+ if node.nil?
164
+ node = FileHandlers::DirHandler::DirNode.new( parent, element )
165
+ node['processor'] = Webgen::Plugin['VirtualDirHandler']
166
+ parent.add_child( node )
167
+ self.logger.info { "Created virtual directory <#{node.recursive_value( 'dest' )}>" }
168
+ end
169
+ parent = node
170
+ end
171
+
172
+ return node
173
+ end
174
+
175
+ end
176
+
177
+
178
+ # Handles virtual directories, that is, directories that do not exist in the source tree.
179
+ class VirtualDirHandler < DirHandler
180
+
181
+ summary "Handles virtual directories"
182
+ depends_on "DirHandler"
183
+
184
+ def write_node( node )
185
+ end
186
+
187
+ end
188
+
189
+ # Handles virtual pages, that is, pages that do not exist in the source tree.
190
+ class VirtualPageHandler < PageHandler
191
+
192
+ summary "Handles virtual pages"
193
+ depends_on "PageHandler"
194
+
195
+ def write_node( node )
196
+ end
197
+
198
+ end
199
+
200
+ end
@@ -0,0 +1,96 @@
1
+ #
2
+ #--
3
+ #
4
+ # $Id: directory.rb 203 2005-02-21 18:42:04Z 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/filehandler/filehandler'
24
+
25
+ module FileHandlers
26
+
27
+ # Handles directories.
28
+ class DirHandler < DefaultHandler
29
+
30
+ # Specialized node describing a directory.
31
+ class DirNode < Node
32
+
33
+ def initialize( parent, name )
34
+ super( parent )
35
+ self['title'] = self['directoryName'] = name
36
+ self['src'] = self['dest'] = name + '/'
37
+ self['processor'] = Webgen::Plugin['DirHandler']
38
+ end
39
+
40
+ def []( name )
41
+ process_dir_index if super('indexFile').nil? && name == 'indexFile'
42
+ super
43
+ end
44
+
45
+ def process_dir_index
46
+ node = Webgen::Plugin['PageHandler'].get_page_node( Webgen::Plugin['DirHandler']['indexFile'], self )
47
+ if node
48
+ self.logger.info { "Directory index file for <#{self.recursive_value( 'src' )}> => <#{node.recursive_value( 'src', false )}>" }
49
+ self['indexFile'] = node
50
+ else
51
+ self.logger.warn { "No directory index file found for directory <#{self.recursive_value( 'src' )}>" }
52
+ self['indexFile'] = nil
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+
59
+ summary "Handles directories"
60
+ extension :dir
61
+ add_param 'indexFile', 'index.html', 'The default file name for the directory index file.'
62
+ depends_on 'FileHandler'
63
+
64
+
65
+ # Return a new DirNode.
66
+ def create_node( path, parent )
67
+ DirNode.new( parent, File.basename( path ) )
68
+ end
69
+
70
+ # Create the directory (and all its parent directories if necessary).
71
+ def write_node( node )
72
+ name = node.recursive_value( 'dest' )
73
+ FileUtils.makedirs( name ) unless File.exists?( name )
74
+ end
75
+
76
+ # Return the language node for the directory +node+ using the specified language +lang+. If an
77
+ # index file is specified, then the its correct language node is returned, else +node+ is
78
+ # returned.
79
+ def get_lang_node( node, lang = node['lang'] )
80
+ if node['indexFile']
81
+ node['indexFile']['processor'].get_lang_node( node['indexFile'], lang )
82
+ else
83
+ node
84
+ end
85
+ end
86
+
87
+ # Get the HTML link for the directory +node+.
88
+ def get_html_link( node, refNode, title = nil )
89
+ lang_node = get_lang_node( node, refNode['lang'] )
90
+ title ||= lang_node['directoryName'] || node['directoryName']
91
+ super( lang_node, refNode, title )
92
+ end
93
+
94
+ end
95
+
96
+ end