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,50 @@
1
+ #
2
+ #--
3
+ #
4
+ # $Id: rdoc.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 'rdoc/markup/simple_markup'
24
+ require 'rdoc/markup/simple_markup/to_html'
25
+ require 'webgen/plugins/filehandler/pagehandler/page'
26
+
27
+ module ContentHandlers
28
+
29
+ # Handles text in RDoc format.
30
+ class RDocHandler < ContentHandler
31
+
32
+ summary "Handles content in RDOC format"
33
+ depends_on "PageHandler"
34
+
35
+ def initialize
36
+ register_format( 'rdoc' )
37
+ @processor = SM::SimpleMarkup.new
38
+ @formatter = SM::ToHtml.new
39
+ end
40
+
41
+ def format_content( txt )
42
+ @processor.convert( txt, @formatter )
43
+ rescue
44
+ self.logger.error { "Error converting RDOC text to HTML" }
45
+ ''
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,52 @@
1
+ #
2
+ #--
3
+ #
4
+ # $Id: textile.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
+ begin
24
+ require 'redcloth'
25
+ require 'webgen/plugins/filehandler/pagehandler/page'
26
+
27
+ module ContentHandlers
28
+
29
+ # Handles content in Textile format using RedCloth.
30
+ class TextileHandler < ContentHandler
31
+
32
+ summary "Handles content in Textile format using RedCloth"
33
+ depends_on "PageHandler"
34
+
35
+ def initialize
36
+ register_format( 'textile' )
37
+ end
38
+
39
+ def format_content( txt )
40
+ RedCloth.new( txt ).to_html
41
+ rescue
42
+ self.logger.error { "Error converting Textile text to HTML" }
43
+ ''
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ rescue LoadError => e
51
+ self.logger.warn { "Textile not available as content format as RedCloth could not be loaded: #{e.message}" }
52
+ end
@@ -0,0 +1,194 @@
1
+ #
2
+ #--
3
+ #
4
+ # $Id: picturegallery.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
+ class PictureGalleryFileHandler < DefaultHandler
30
+
31
+ summary "Handles picture gallery files for page file"
32
+ extension 'gallery'
33
+ add_param "picturesPerPage", 20, 'Number of picture per gallery page'
34
+ add_param "picturePageInMenu", false, 'True if the picture pages should be in the menu'
35
+ add_param "galleryPageInMenu", false, 'True if the gallery pages should be in the menu'
36
+ add_param "mainPageInMenu", true, 'True if the main page of the picture gallery should be in the menu'
37
+ add_param "galleryPageTemplate", nil, 'The template for gallery pages. If nil or a not existing file is specified, the default template is used.'
38
+ add_param "picturePageTemplate", nil, 'The template for picture pages. If nil or a not existing file is specified, the default template is used.'
39
+ add_param "mainPageTemplate", nil, 'The template for the main page. If nil or a not existing file is specified, the default template is used.'
40
+ add_param "files", 'images/**/*.jpg', 'The Dir glob for specifying the picture files'
41
+ add_param "title", 'Gallery', 'The title of the gallery'
42
+ add_param "layout", 'default', 'The layout used'
43
+
44
+ depends_on 'FileHandler', 'PageHandler'
45
+
46
+ def create_node( file, parent )
47
+ begin
48
+ @filedata = YAML::load( File.read( file ) )
49
+ rescue
50
+ self.logger.error { "Could not parse gallery file <#{file}>, not creating gallery pages" }
51
+ return
52
+ end
53
+ path = File.dirname( file )
54
+ images = Dir[File.join( path, get_param( 'files' ))].collect {|i| i.sub( /#{path + File::SEPARATOR}/, '' ) }
55
+ self.logger.info { "Creating gallery for file <#{file}> with #{images.length} pictures" }
56
+
57
+ create_gallery( images, parent )
58
+
59
+ nil
60
+ end
61
+
62
+ def write_node( node )
63
+ # do nothing
64
+ end
65
+
66
+ #######
67
+ private
68
+ #######
69
+
70
+ # Method overridden to lookup parameters specified in the gallery file first.
71
+ def get_param( name )
72
+ ( @filedata.has_key?( name ) ? @filedata[name] : super )
73
+ end
74
+
75
+ def call_layouter( type, data )
76
+ content = self.send( type.to_s + "_page_" + get_param( 'layout' ), data )
77
+ "#{data.to_yaml}\n---\n#{content}"
78
+ end
79
+
80
+ def create_gallery( images, parent )
81
+ nr_gallery_pages = (Float(images.length) / get_param( 'picturesPerPage' ) ).ceil
82
+ main = create_main_page( images )
83
+ main['galleries'] = create_gallery_pages( images )
84
+
85
+ if nr_gallery_pages != 1
86
+ mainNode = Webgen::Plugin['PageHandler'].create_node_from_data( call_layouter( :main, main ), main['srcName'], parent )
87
+ parent.add_child( mainNode )
88
+ else
89
+ main['galleries'][0]['title'] = main['title']
90
+ main['galleries'][0]['inMenu'] = main['inMenu']
91
+ main['galleries'][0].update( @filedata['mainPage'] || {} )
92
+ end
93
+
94
+ main['galleries'].each do |gallery|
95
+ node = Webgen::Plugin['PageHandler'].create_node_from_data( call_layouter( :gallery, gallery ), gallery['link'], parent )
96
+ parent.add_child( node )
97
+ gallery['imageList'].each do |image|
98
+ node = Webgen::Plugin['PageHandler'].create_node_from_data( call_layouter( :picture, image ), image['srcName'], parent )
99
+ parent.add_child( node )
100
+ end
101
+ end
102
+ end
103
+
104
+ def create_main_page( images )
105
+ main = {}
106
+ main['title'] = get_param( 'title' )
107
+ main['inMenu'] = get_param( 'mainPageInMenu' )
108
+ main['template'] = get_param( 'mainPageTemplate' )
109
+ main['srcName'] = gallery_file_name( main['title'] )
110
+ main.update( @filedata['mainPage'] || {} )
111
+ main
112
+ end
113
+
114
+ def create_gallery_pages( images )
115
+ galleries = []
116
+ picsPerPage = get_param( 'picturesPerPage' )
117
+ 0.step( images.length - 1, picsPerPage ) do |i|
118
+ data = Hash.new
119
+
120
+ data['template'] = get_param( 'galleryPageTemplate' )
121
+ data['inMenu'] = get_param( 'galleryPageInMenu' )
122
+ data['number'] = i/picsPerPage + 1
123
+ data['title'] = gallery_title( data['number'] )
124
+ data['link'] = gallery_file_name( data['title'] )
125
+ data['prevGalleryNumber'] = ( i == 0 ? nil : data['number'] - 1 )
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'] )
133
+
134
+ galleries << data
135
+ end
136
+ galleries
137
+ end
138
+
139
+ def gallery_title( index )
140
+ ( index.nil? ? nil : get_param( 'title' ) + ' ' + index.to_s )
141
+ end
142
+
143
+ def gallery_file_name( title )
144
+ ( title.nil? ? nil : title.tr( ' .', '_' ) + '.html' )
145
+ end
146
+
147
+ def create_picture_pages( images )
148
+ imageList = []
149
+ images.each do |image|
150
+ imageData = @filedata[image] || {}
151
+
152
+ imageData['title'] ||= "Picture #{File.basename( image )}"
153
+ imageData['description'] ||= ''
154
+ imageData['inMenu'] = get_param( 'picturePageInMenu' )
155
+ imageData['template'] = get_param( 'picturePageTemplate' )
156
+ imageData['imageFilename'] = image
157
+ imageData['srcName'] = File.basename( image ).tr( ' .', '_' ) + '.html'
158
+
159
+ imageList << imageData
160
+ end
161
+ imageList
162
+ end
163
+
164
+ def main_page_default( data )
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
+ "
168
+ end
169
+
170
+ def gallery_page_default( data )
171
+ "
172
+ <div class=\"webgen-gallery\">
173
+
174
+ #{data['imageList'].collect {|i| "<img src='#{i['imageFilename']}' width='100' height='100' alt='#{i['title']}'/> \"#{i['title']}\":#{i['srcName']}" }.join( "\n\n" )}
175
+
176
+ </div>
177
+ "
178
+ end
179
+
180
+ def picture_page_default( data )
181
+ "
182
+ <div class=\"webgen-picture\">
183
+
184
+ <img src='#{data['imageFilename']}' alt='#{data['title']}' />
185
+
186
+ </div>
187
+
188
+ {description: }
189
+ "
190
+ end
191
+
192
+ end
193
+
194
+ end
@@ -0,0 +1,98 @@
1
+ #
2
+ #--
3
+ #
4
+ # $Id: template.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 template files. Template files are generic files which specify the layout.
28
+ class TemplateFileHandler < DefaultHandler
29
+
30
+ summary "Represents the template files for the page generation in the tree"
31
+ extension 'template'
32
+ add_param 'defaultTemplate', 'default.template', 'The default file name for the template file.'
33
+ depends_on 'FileHandler'
34
+
35
+ def create_node( srcName, parent )
36
+ node = Node.new( parent )
37
+ node['title'] = 'Template'
38
+ node['src'] = node['dest'] = File.basename( srcName )
39
+ node['processor'] = self
40
+ File.open( srcName ) { |file| node['content'] = file.read }
41
+ node
42
+ end
43
+
44
+ def write_node( node )
45
+ # do not write anything
46
+ end
47
+
48
+ # Return the template for +node+.
49
+ def get_template_for_node( node )
50
+ return get_template( node ) || get_default_template( node )
51
+ end
52
+
53
+ #######
54
+ private
55
+ #######
56
+
57
+ def get_template( node )
58
+ if node['template'].kind_of?( String )
59
+ templateNode = node.node_for_string( node['template'] )
60
+ if templateNode.nil?
61
+ self.logger.warn { "Specified template for file <#{node.recursive_value('src')}> not found, using default template!" }
62
+ end
63
+ node['template'] = templateNode unless templateNode.nil?
64
+ return templateNode
65
+ end
66
+ end
67
+
68
+ # Return the default template for +node+. If the template node is not found in the directory of
69
+ # the node, the parent directories are searched.
70
+ def get_default_template( node )
71
+ node = node.parent until node.kind_of?( FileHandlers::DirHandler::DirNode )
72
+ templateNode = node.find { |child| child['src'] == get_param( 'defaultTemplate' ) }
73
+ if templateNode.nil?
74
+ if node.parent.nil?
75
+ self.logger.error { "Template file #{get_param( 'defaultTemplate' )} in root directory not found, creating dummy!" }
76
+ templateNode = DummyTemplateNode.new( node )
77
+ node.add_child( templateNode )
78
+ else
79
+ templateNode = get_default_template( node.parent )
80
+ end
81
+ end
82
+ templateNode
83
+ end
84
+
85
+ end
86
+
87
+ class DummyTemplateNode < Node
88
+
89
+ def initialize( parent )
90
+ super( parent )
91
+ self['src'] = self['dest'] = self['title'] = Webgen::Plugin['TemplateFileHandler']['defaultTemplate']
92
+ self['processor'] = Webgen::Plugin['TemplateFileHandler']
93
+ self['content'] = ''
94
+ end
95
+
96
+ end
97
+
98
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ #--
3
+ #
4
+ # $Id: date.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
+
25
+ module Tags
26
+
27
+ # Prints out the date using a format string which will be passed to Time#strftime. Therefore you
28
+ # can use everything Time#strftime offers.
29
+ class DateTag < DefaultTag
30
+
31
+ summary "Prints out the date"
32
+ add_param 'format', '%A, %B %d %H:%M:%S %Z %Y', 'The format of the date (same options as Time#strftime).'
33
+ depends_on 'Tags'
34
+
35
+ def initialize
36
+ super
37
+ register_tag( 'date' )
38
+ end
39
+
40
+ def process_tag( tag, node, refNode )
41
+ Time.now.strftime( get_param( 'format' ) )
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,53 @@
1
+ #
2
+ #--
3
+ #
4
+ # $Id: executecommand.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 'cgi'
24
+ require 'webgen/plugins/tags/tags'
25
+
26
+ module Tags
27
+
28
+ # Executes the given command and writes the standard output into the output file. All HTML special
29
+ # characters are escaped.
30
+ class ExecuteCommandTag < DefaultTag
31
+
32
+ summary "Executes the given command and includes its standard output"
33
+ depends_on 'Tags'
34
+ add_param 'command', nil, 'The command which should be executed'
35
+ add_param 'processOutput', true, 'The output of the command will be processed if true'
36
+ add_param 'escapeHTML', true, 'Special HTML characters in the output will be escaped if true'
37
+ set_mandatory 'command', true
38
+
39
+ def initialize
40
+ super
41
+ register_tag( 'execute' )
42
+ end
43
+
44
+ def process_tag( tag, node, refNode )
45
+ @processOutput = get_param( 'processOutput' )
46
+ output = ( get_param( 'command' ) ? `#{get_param( 'command' )}` : '' )
47
+ output = CGI::escapeHTML( output ) if get_param( 'escapeHTML' )
48
+ output
49
+ end
50
+
51
+ end
52
+
53
+ end