gettalong-webgen 0.5.4.20080929
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +5 -0
- data/COPYING +10 -0
- data/GPL +340 -0
- data/Rakefile +324 -0
- data/THANKS +17 -0
- data/bin/webgen +10 -0
- data/data/webgen/resources.yaml +3 -0
- data/data/webgen/webgui/controller/main.rb +129 -0
- data/data/webgen/webgui/overrides/win32console.rb +0 -0
- data/data/webgen/webgui/public/css/jquery.autocomplete.css +50 -0
- data/data/webgen/webgui/public/css/ramaze_error.css +90 -0
- data/data/webgen/webgui/public/css/style.css +55 -0
- data/data/webgen/webgui/public/img/headerbg.jpg +0 -0
- data/data/webgen/webgui/public/img/webgen_logo.png +0 -0
- data/data/webgen/webgui/public/js/jquery.autocomplete.js +15 -0
- data/data/webgen/webgui/public/js/jquery.js +32 -0
- data/data/webgen/webgui/view/create_website.xhtml +22 -0
- data/data/webgen/webgui/view/error.xhtml +64 -0
- data/data/webgen/webgui/view/index.xhtml +22 -0
- data/data/webgen/webgui/view/manage_website.xhtml +18 -0
- data/data/webgen/webgui/view/page.xhtml +40 -0
- data/data/webgen/website_skeleton/README +10 -0
- data/data/webgen/website_skeleton/Rakefile +40 -0
- data/data/webgen/website_skeleton/config.yaml +17 -0
- data/data/webgen/website_skeleton/ext/init.rb +6 -0
- data/data/webgen/website_styles/1024px/README +13 -0
- data/data/webgen/website_styles/1024px/src/default.css +188 -0
- data/data/webgen/website_styles/1024px/src/default.template +60 -0
- data/data/webgen/website_styles/1024px/src/images/background.gif +0 -0
- data/data/webgen/website_styles/andreas00/README +13 -0
- data/data/webgen/website_styles/andreas00/src/default.css +290 -0
- data/data/webgen/website_styles/andreas00/src/default.template +60 -0
- data/data/webgen/website_styles/andreas00/src/images/bg.gif +0 -0
- data/data/webgen/website_styles/andreas00/src/images/front.jpg +0 -0
- data/data/webgen/website_styles/andreas00/src/images/menubg.gif +0 -0
- data/data/webgen/website_styles/andreas00/src/images/menubg2.gif +0 -0
- data/data/webgen/website_styles/andreas01/README +14 -0
- data/data/webgen/website_styles/andreas01/src/default.css +310 -0
- data/data/webgen/website_styles/andreas01/src/default.template +61 -0
- data/data/webgen/website_styles/andreas01/src/images/bg.gif +0 -0
- data/data/webgen/website_styles/andreas01/src/images/front.jpg +0 -0
- data/data/webgen/website_styles/andreas01/src/print.css +35 -0
- data/data/webgen/website_styles/andreas03/README +14 -0
- data/data/webgen/website_styles/andreas03/src/default.css +223 -0
- data/data/webgen/website_styles/andreas03/src/default.template +58 -0
- data/data/webgen/website_styles/andreas03/src/images/bodybg.png +0 -0
- data/data/webgen/website_styles/andreas03/src/images/contbg.png +0 -0
- data/data/webgen/website_styles/andreas03/src/images/footerbg.png +0 -0
- data/data/webgen/website_styles/andreas03/src/images/gradient1.png +0 -0
- data/data/webgen/website_styles/andreas03/src/images/gradient2.png +0 -0
- data/data/webgen/website_styles/andreas04/README +15 -0
- data/data/webgen/website_styles/andreas04/src/default.css +290 -0
- data/data/webgen/website_styles/andreas04/src/default.template +81 -0
- data/data/webgen/website_styles/andreas04/src/images/blinkarrow.gif +0 -0
- data/data/webgen/website_styles/andreas04/src/images/bodybg.png +0 -0
- data/data/webgen/website_styles/andreas04/src/images/contentbg.png +0 -0
- data/data/webgen/website_styles/andreas04/src/images/entrybg.png +0 -0
- data/data/webgen/website_styles/andreas04/src/images/flash.gif +0 -0
- data/data/webgen/website_styles/andreas04/src/images/flash2.gif +0 -0
- data/data/webgen/website_styles/andreas04/src/images/globe.gif +0 -0
- data/data/webgen/website_styles/andreas04/src/images/globebottom.gif +0 -0
- data/data/webgen/website_styles/andreas04/src/images/linkarrow.gif +0 -0
- data/data/webgen/website_styles/andreas04/src/images/menuhover.png +0 -0
- data/data/webgen/website_styles/andreas05/README +14 -0
- data/data/webgen/website_styles/andreas05/src/default.css +33 -0
- data/data/webgen/website_styles/andreas05/src/default.template +40 -0
- data/data/webgen/website_styles/andreas05/src/images/bodybg.gif +0 -0
- data/data/webgen/website_styles/andreas05/src/images/front.png +0 -0
- data/data/webgen/website_styles/andreas06/README +14 -0
- data/data/webgen/website_styles/andreas06/src/default.css +354 -0
- data/data/webgen/website_styles/andreas06/src/default.template +70 -0
- data/data/webgen/website_styles/andreas06/src/images/bodybg.gif +0 -0
- data/data/webgen/website_styles/andreas06/src/images/boxbg.gif +0 -0
- data/data/webgen/website_styles/andreas06/src/images/greypx.gif +0 -0
- data/data/webgen/website_styles/andreas06/src/images/header.jpg +0 -0
- data/data/webgen/website_styles/andreas06/src/images/innerbg.gif +0 -0
- data/data/webgen/website_styles/andreas06/src/images/leaves.jpg +0 -0
- data/data/webgen/website_styles/andreas06/src/images/tabs.gif +0 -0
- data/data/webgen/website_styles/andreas07/README +15 -0
- data/data/webgen/website_styles/andreas07/src/browserfix.css +7 -0
- data/data/webgen/website_styles/andreas07/src/default.css +92 -0
- data/data/webgen/website_styles/andreas07/src/default.template +42 -0
- data/data/webgen/website_styles/andreas07/src/images/bodybg.gif +0 -0
- data/data/webgen/website_styles/andreas07/src/images/sidebarbg.gif +0 -0
- data/data/webgen/website_styles/andreas08/README +14 -0
- data/data/webgen/website_styles/andreas08/src/default.css +224 -0
- data/data/webgen/website_styles/andreas08/src/default.template +51 -0
- data/data/webgen/website_styles/andreas09/README +14 -0
- data/data/webgen/website_styles/andreas09/src/default.css +308 -0
- data/data/webgen/website_styles/andreas09/src/default.template +68 -0
- data/data/webgen/website_styles/andreas09/src/images/bodybg-black.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/bodybg-green.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/bodybg-orange.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/bodybg-purple.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/bodybg-red.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/bodybg.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/footerbg.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/menuhover-black.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/menuhover-green.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/menuhover-orange.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/menuhover-purple.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/menuhover-red.jpg +0 -0
- data/data/webgen/website_styles/andreas09/src/images/menuhover.jpg +0 -0
- data/data/webgen/website_styles/simple/README +6 -0
- data/data/webgen/website_styles/simple/src/default.css +84 -0
- data/data/webgen/website_styles/simple/src/default.template +36 -0
- data/data/webgen/website_templates/default/README +6 -0
- data/data/webgen/website_templates/default/src/index.page +8 -0
- data/data/webgen/website_templates/project/README +5 -0
- data/data/webgen/website_templates/project/src/about.page +12 -0
- data/data/webgen/website_templates/project/src/download.page +15 -0
- data/data/webgen/website_templates/project/src/features.page +8 -0
- data/data/webgen/website_templates/project/src/index.page +9 -0
- data/data/webgen/website_templates/project/src/screenshots.page +18 -0
- data/doc/contentprocessor.template +11 -0
- data/doc/contentprocessor/blocks.page +66 -0
- data/doc/contentprocessor/builder.page +80 -0
- data/doc/contentprocessor/erb.page +56 -0
- data/doc/contentprocessor/erubis.page +46 -0
- data/doc/contentprocessor/haml.page +47 -0
- data/doc/contentprocessor/maruku.page +41 -0
- data/doc/contentprocessor/rdiscount.page +37 -0
- data/doc/contentprocessor/rdoc.page +36 -0
- data/doc/contentprocessor/redcloth.page +39 -0
- data/doc/contentprocessor/sass.page +31 -0
- data/doc/contentprocessor/tags.page +73 -0
- data/doc/extensions.metainfo +29 -0
- data/doc/extensions.page +16 -0
- data/doc/extensions.template +17 -0
- data/doc/faq.page +214 -0
- data/doc/getting_started.page +134 -0
- data/doc/index.page +65 -0
- data/doc/manual.page +532 -0
- data/doc/reference_configuration.page +646 -0
- data/doc/reference_metainfo.page +213 -0
- data/doc/sourcehandler.template +21 -0
- data/doc/sourcehandler/copy.page +19 -0
- data/doc/sourcehandler/directory.page +27 -0
- data/doc/sourcehandler/feed.page +82 -0
- data/doc/sourcehandler/metainfo.page +41 -0
- data/doc/sourcehandler/page.page +30 -0
- data/doc/sourcehandler/sitemap.page +46 -0
- data/doc/sourcehandler/template.page +45 -0
- data/doc/sourcehandler/virtual.page +49 -0
- data/doc/tag.template +25 -0
- data/doc/tag/breadcrumbtrail.page +40 -0
- data/doc/tag/coderay.page +49 -0
- data/doc/tag/date.page +31 -0
- data/doc/tag/executecommand.page +26 -0
- data/doc/tag/includefile.page +32 -0
- data/doc/tag/langbar.page +22 -0
- data/doc/tag/menu.page +92 -0
- data/doc/tag/metainfo.page +29 -0
- data/doc/tag/relocatable.page +38 -0
- data/doc/tag/sitemap.page +31 -0
- data/doc/upgrading.page +139 -0
- data/doc/webgen_page_format.page +128 -0
- data/lib/webgen/blackboard.rb +73 -0
- data/lib/webgen/cache.rb +85 -0
- data/lib/webgen/cli.rb +118 -0
- data/lib/webgen/cli/create_command.rb +64 -0
- data/lib/webgen/cli/run_command.rb +20 -0
- data/lib/webgen/cli/utils.rb +86 -0
- data/lib/webgen/cli/webgui_command.rb +49 -0
- data/lib/webgen/common.rb +10 -0
- data/lib/webgen/common/sitemap.rb +76 -0
- data/lib/webgen/configuration.rb +147 -0
- data/lib/webgen/contentprocessor.rb +96 -0
- data/lib/webgen/contentprocessor/blocks.rb +46 -0
- data/lib/webgen/contentprocessor/builder.rb +26 -0
- data/lib/webgen/contentprocessor/context.rb +90 -0
- data/lib/webgen/contentprocessor/erb.rb +24 -0
- data/lib/webgen/contentprocessor/erubis.rb +40 -0
- data/lib/webgen/contentprocessor/haml.rb +25 -0
- data/lib/webgen/contentprocessor/maruku.rb +18 -0
- data/lib/webgen/contentprocessor/rdiscount.rb +15 -0
- data/lib/webgen/contentprocessor/rdoc.rb +17 -0
- data/lib/webgen/contentprocessor/redcloth.rb +15 -0
- data/lib/webgen/contentprocessor/sass.rb +18 -0
- data/lib/webgen/contentprocessor/tags.rb +134 -0
- data/lib/webgen/coreext.rb +10 -0
- data/lib/webgen/default_config.rb +198 -0
- data/lib/webgen/languages.rb +578 -0
- data/lib/webgen/loggable.rb +23 -0
- data/lib/webgen/logger.rb +78 -0
- data/lib/webgen/node.rb +347 -0
- data/lib/webgen/output.rb +37 -0
- data/lib/webgen/output/filesystem.rb +67 -0
- data/lib/webgen/page.rb +133 -0
- data/lib/webgen/path.rb +182 -0
- data/lib/webgen/source.rb +24 -0
- data/lib/webgen/source/filesystem.rb +58 -0
- data/lib/webgen/source/resource.rb +42 -0
- data/lib/webgen/source/stacked.rb +53 -0
- data/lib/webgen/sourcehandler.rb +202 -0
- data/lib/webgen/sourcehandler/base.rb +211 -0
- data/lib/webgen/sourcehandler/copy.rb +41 -0
- data/lib/webgen/sourcehandler/directory.rb +31 -0
- data/lib/webgen/sourcehandler/feed.rb +121 -0
- data/lib/webgen/sourcehandler/fragment.rb +71 -0
- data/lib/webgen/sourcehandler/metainfo.rb +117 -0
- data/lib/webgen/sourcehandler/page.rb +77 -0
- data/lib/webgen/sourcehandler/sitemap.rb +60 -0
- data/lib/webgen/sourcehandler/template.rb +68 -0
- data/lib/webgen/sourcehandler/virtual.rb +75 -0
- data/lib/webgen/tag.rb +23 -0
- data/lib/webgen/tag/base.rb +162 -0
- data/lib/webgen/tag/breadcrumbtrail.rb +71 -0
- data/lib/webgen/tag/coderay.rb +32 -0
- data/lib/webgen/tag/date.rb +18 -0
- data/lib/webgen/tag/executecommand.rb +29 -0
- data/lib/webgen/tag/includefile.rb +42 -0
- data/lib/webgen/tag/langbar.rb +52 -0
- data/lib/webgen/tag/menu.rb +186 -0
- data/lib/webgen/tag/metainfo.rb +25 -0
- data/lib/webgen/tag/relocatable.rb +53 -0
- data/lib/webgen/tag/sitemap.rb +42 -0
- data/lib/webgen/tree.rb +80 -0
- data/lib/webgen/version.rb +6 -0
- data/lib/webgen/webgentask.rb +148 -0
- data/lib/webgen/website.rb +214 -0
- data/lib/webgen/websiteaccess.rb +29 -0
- data/lib/webgen/websitemanager.rb +125 -0
- data/man/man1/webgen.1 +67 -0
- data/misc/default.css +360 -0
- data/misc/default.template +75 -0
- data/misc/htmldoc.metainfo +25 -0
- data/misc/htmldoc.virtual +5 -0
- data/misc/images/arrow.gif +0 -0
- data/misc/images/error.gif +0 -0
- data/misc/images/exclamation.gif +0 -0
- data/misc/images/headerbg.jpg +0 -0
- data/misc/images/information.gif +0 -0
- data/misc/images/quote.gif +0 -0
- data/setup.rb +1585 -0
- data/test/helper.rb +41 -0
- data/test/test_blackboard.rb +58 -0
- data/test/test_cache.rb +57 -0
- data/test/test_common_sitemap.rb +56 -0
- data/test/test_configuration.rb +66 -0
- data/test/test_contentprocessor.rb +31 -0
- data/test/test_contentprocessor_blocks.rb +34 -0
- data/test/test_contentprocessor_builder.rb +19 -0
- data/test/test_contentprocessor_context.rb +38 -0
- data/test/test_contentprocessor_erb.rb +20 -0
- data/test/test_contentprocessor_erubis.rb +47 -0
- data/test/test_contentprocessor_haml.rb +20 -0
- data/test/test_contentprocessor_maruku.rb +27 -0
- data/test/test_contentprocessor_rdiscount.rb +15 -0
- data/test/test_contentprocessor_rdoc.rb +16 -0
- data/test/test_contentprocessor_redcloth.rb +12 -0
- data/test/test_contentprocessor_sass.rb +20 -0
- data/test/test_contentprocessor_tags.rb +97 -0
- data/test/test_languages.rb +53 -0
- data/test/test_loggable.rb +30 -0
- data/test/test_logger.rb +73 -0
- data/test/test_node.rb +339 -0
- data/test/test_output_filesystem.rb +58 -0
- data/test/test_page.rb +203 -0
- data/test/test_path.rb +131 -0
- data/test/test_source_filesystem.rb +59 -0
- data/test/test_source_resource.rb +26 -0
- data/test/test_source_stacked.rb +34 -0
- data/test/test_sourcehandler_base.rb +92 -0
- data/test/test_sourcehandler_copy.rb +45 -0
- data/test/test_sourcehandler_directory.rb +25 -0
- data/test/test_sourcehandler_feed.rb +74 -0
- data/test/test_sourcehandler_fragment.rb +67 -0
- data/test/test_sourcehandler_metainfo.rb +93 -0
- data/test/test_sourcehandler_page.rb +70 -0
- data/test/test_sourcehandler_sitemap.rb +47 -0
- data/test/test_sourcehandler_template.rb +63 -0
- data/test/test_sourcehandler_virtual.rb +56 -0
- data/test/test_tag_base.rb +82 -0
- data/test/test_tag_breadcrumbtrail.rb +89 -0
- data/test/test_tag_coderay.rb +30 -0
- data/test/test_tag_date.rb +16 -0
- data/test/test_tag_executecommand.rb +39 -0
- data/test/test_tag_includefile.rb +48 -0
- data/test/test_tag_langbar.rb +60 -0
- data/test/test_tag_menu.rb +195 -0
- data/test/test_tag_metainfo.rb +17 -0
- data/test/test_tag_relocatable.rb +57 -0
- data/test/test_tag_sitemap.rb +44 -0
- data/test/test_tree.rb +69 -0
- data/test/test_webgentask.rb +21 -0
- data/test/test_website.rb +96 -0
- data/test/test_websiteaccess.rb +23 -0
- data/test/test_websitemanager.rb +68 -0
- metadata +575 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'webgen/websiteaccess'
|
2
|
+
require 'webgen/tag'
|
3
|
+
|
4
|
+
module Webgen::Tag
|
5
|
+
|
6
|
+
# Generates a sitemap. The sitemap contains the hierarchy of all pages on the web site.
|
7
|
+
class Sitemap
|
8
|
+
|
9
|
+
include Base
|
10
|
+
include Webgen::WebsiteAccess
|
11
|
+
|
12
|
+
# Create the sitemap.
|
13
|
+
def call(tag, body, context)
|
14
|
+
tree = website.blackboard.invoke(:create_sitemap, context.dest_node, context.content_node.lang, @params)
|
15
|
+
(tree.children.empty? ? '' : output_sitemap(tree, context))
|
16
|
+
end
|
17
|
+
|
18
|
+
#######
|
19
|
+
private
|
20
|
+
#######
|
21
|
+
|
22
|
+
# The modified tag base to support the easy specification of common.sitemap.* options.
|
23
|
+
def tag_config_base
|
24
|
+
'common.sitemap'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Create the HTML representation of the sitemap nodes in +tree+ in respect to +context+.
|
28
|
+
def output_sitemap(tree, context)
|
29
|
+
out = "<ul>"
|
30
|
+
tree.children.each do |child|
|
31
|
+
sub = (child.children.length > 0 ? output_sitemap(child, context) : '')
|
32
|
+
out << "<li>" + context.dest_node.link_to(child.node, :lang => child.node.lang || context.content_node.lang)
|
33
|
+
out << sub
|
34
|
+
out << "</li>"
|
35
|
+
end
|
36
|
+
out << "</ul>"
|
37
|
+
out
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/webgen/tree.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'webgen/websiteaccess'
|
2
|
+
require 'webgen/node'
|
3
|
+
|
4
|
+
module Webgen
|
5
|
+
|
6
|
+
# Represents a tree of nodes.
|
7
|
+
class Tree
|
8
|
+
|
9
|
+
include WebsiteAccess
|
10
|
+
|
11
|
+
# The dummy root. This is the default node that gets created when the Tree is created sothat the
|
12
|
+
# real root node can be treated like any other node. It has only one child, namely the real root
|
13
|
+
# node of the tree.
|
14
|
+
attr_reader :dummy_root
|
15
|
+
|
16
|
+
# Direct access to the hashes for node resolving. Only use this for reading purposes! If you
|
17
|
+
# just want to get a specific node for an alcn/acn/output path, use #node instead.
|
18
|
+
attr_reader :node_access
|
19
|
+
|
20
|
+
# The hash containing processing information for each node. This is normally not accessed
|
21
|
+
# directly but via the Node#node_info method.
|
22
|
+
attr_reader :node_info
|
23
|
+
|
24
|
+
# Create a new Tree object.
|
25
|
+
def initialize
|
26
|
+
@node_access = {:alcn => {}, :acn => {}, :path => {}}
|
27
|
+
@node_info = {}
|
28
|
+
@dummy_root = Node.new(self, '', '')
|
29
|
+
end
|
30
|
+
|
31
|
+
# The real root node of the tree.
|
32
|
+
def root
|
33
|
+
@dummy_root.children.first
|
34
|
+
end
|
35
|
+
|
36
|
+
# Access a node via a +path+ of a specific +type+. If type is +alcn+ then +path+ has to be an
|
37
|
+
# absolute localized canonical name, if type is +acn+ then +path+ has to be an absolute
|
38
|
+
# canonical name and if type is +path+ then +path+ needs to be an output path.
|
39
|
+
#
|
40
|
+
# Returns the requested Node or +nil+ if such a node does not exist.
|
41
|
+
def node(path, type = :alcn)
|
42
|
+
(type == :acn ? @node_access[type][path] && @node_access[type][path].first : @node_access[type][path])
|
43
|
+
end
|
44
|
+
alias_method :[], :node
|
45
|
+
|
46
|
+
# A utility method called by Node#initialize. This method should not be used directly!
|
47
|
+
def register_node(node)
|
48
|
+
if @node_access[:alcn].has_key?(node.absolute_lcn)
|
49
|
+
raise "Can't have two nodes with same absolute lcn: #{node.absolute_lcn}"
|
50
|
+
else
|
51
|
+
@node_access[:alcn][node.absolute_lcn] = node
|
52
|
+
end
|
53
|
+
(@node_access[:acn][node.absolute_cn] ||= []) << node
|
54
|
+
if @node_access[:path].has_key?(node.path)
|
55
|
+
raise "Can't have two nodes with same output path: #{node.path}" unless node['no_output']
|
56
|
+
else
|
57
|
+
@node_access[:path][node.path] = node
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Delete the node identified by +node_or_alcn+ and all of its children from the
|
62
|
+
# tree. Directories are only deleted if +delete_dir+ is +true+.
|
63
|
+
def delete_node(node_or_alcn, delete_dir = false)
|
64
|
+
n = node_or_alcn.kind_of?(Node) ? node_or_alcn : @node_access[:alcn][node_or_alcn]
|
65
|
+
return if n.nil? || n == @dummy_root || (n.is_directory? && !delete_dir)
|
66
|
+
|
67
|
+
n.children.dup.each {|child| delete_node(child, delete_dir)}
|
68
|
+
|
69
|
+
website.blackboard.dispatch_msg(:before_node_deleted, n)
|
70
|
+
n.parent.children.delete(n)
|
71
|
+
@node_access[:alcn].delete(n.absolute_lcn)
|
72
|
+
@node_access[:acn][n.absolute_cn].delete(n)
|
73
|
+
@node_access[:path].delete(n.path)
|
74
|
+
|
75
|
+
node_info.delete(n.absolute_lcn)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
#
|
3
|
+
#--
|
4
|
+
# webgentask.rb:
|
5
|
+
#
|
6
|
+
# Define a task library for running webgen
|
7
|
+
#
|
8
|
+
# Copyright (C) 2007 Jeremy Hinegardner
|
9
|
+
#
|
10
|
+
# Tasks restructuration by Massimiliano Filacchioni
|
11
|
+
# Modifications for 0.5.0 by Thomas Leitner
|
12
|
+
#
|
13
|
+
# This program is free software; you can redistribute it and/or modify
|
14
|
+
# it under the terms of the GNU General Public License as published by
|
15
|
+
# the Free Software Foundation; either version 2 of the License, or (at
|
16
|
+
# your option) any later version.
|
17
|
+
#
|
18
|
+
# This program is distributed in the hope that it will be useful, but
|
19
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
20
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
21
|
+
# General Public License for more details.
|
22
|
+
#
|
23
|
+
# You should have received a copy of the GNU General Public License
|
24
|
+
# along with this program; if not, write to the Free Software
|
25
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
26
|
+
# USA
|
27
|
+
#
|
28
|
+
#++
|
29
|
+
#
|
30
|
+
|
31
|
+
require 'rake'
|
32
|
+
require 'rake/tasklib'
|
33
|
+
|
34
|
+
module Webgen
|
35
|
+
|
36
|
+
##
|
37
|
+
# Task library to manage a webgen website.
|
38
|
+
#
|
39
|
+
# It is assumed that you have already used the 'webgen' command to create the website directory
|
40
|
+
# for the site.
|
41
|
+
#
|
42
|
+
# === Basics
|
43
|
+
#
|
44
|
+
# require 'webgen/webgentask'
|
45
|
+
#
|
46
|
+
# Webgen::WebgenTask.new
|
47
|
+
#
|
48
|
+
# === Attributes
|
49
|
+
#
|
50
|
+
# The attributes available in the new block are:
|
51
|
+
#
|
52
|
+
# * directory - the root directory of the webgen site
|
53
|
+
# (default Dir.pwd)
|
54
|
+
# * config - the config block for setting additional configuration options
|
55
|
+
# * clobber_outdir - remove webgens output directory on clobber
|
56
|
+
# (default false)
|
57
|
+
#
|
58
|
+
# === Tasks Provided
|
59
|
+
#
|
60
|
+
# The tasks provided are :
|
61
|
+
#
|
62
|
+
# * webgen - render the webgen website
|
63
|
+
# * clobber_webgen - remove all the files created during generation
|
64
|
+
#
|
65
|
+
# === Integrate webgen in other project
|
66
|
+
#
|
67
|
+
# To integrate webgen tasks in another project you can use rake namespaces. For example assuming
|
68
|
+
# webgen's site directory is +webgen+ under the main project directory use the following code
|
69
|
+
# fragment in project Rakefile:
|
70
|
+
#
|
71
|
+
# require 'webgen/webgentask'
|
72
|
+
#
|
73
|
+
# namespace :dev do
|
74
|
+
# Webgen::WebgenTask.new do |site|
|
75
|
+
# site.directory = File.join(Dir.pwd, "webgen")
|
76
|
+
# site.clobber_outdir = true
|
77
|
+
# site.config_block = lambda |config|
|
78
|
+
# config['website.lang'] = 'de'
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# task :clobber => ['dev:clobber_webgen']
|
84
|
+
#
|
85
|
+
# This will create the following tasks:
|
86
|
+
#
|
87
|
+
# * dev:webgen
|
88
|
+
# * dev:clobber_webgen
|
89
|
+
#
|
90
|
+
# and add dev:clobber_webgen to the main clobber task.
|
91
|
+
#
|
92
|
+
class WebgenTask < ::Rake::TaskLib
|
93
|
+
|
94
|
+
# The directory of the webgen website. This would be the directory of your <tt>config.yaml</tt>
|
95
|
+
# file. Or the parent directory of the <tt>src/</tt> directory for webgen.
|
96
|
+
#
|
97
|
+
# The default for this is assumed to be
|
98
|
+
# Dir.pwd
|
99
|
+
attr_accessor :directory
|
100
|
+
|
101
|
+
# The configuration block that is invoked when the Webgen::Website object is initialized. This
|
102
|
+
# can be used to set configuration parameters and to avoid having a <tt>config.yaml</tt> file
|
103
|
+
# lying around.
|
104
|
+
attr_accessor :config_block
|
105
|
+
|
106
|
+
# During the clobber, should webgen's output directory be clobbered. The default is false.
|
107
|
+
attr_accessor :clobber_outdir
|
108
|
+
|
109
|
+
# Create webgen tasks. You can override the task name with the parameter +name+.
|
110
|
+
def initialize(name = 'webgen')
|
111
|
+
@name = name
|
112
|
+
@directory = Dir.pwd
|
113
|
+
@clobber_outdir = false
|
114
|
+
@config_block = nil
|
115
|
+
|
116
|
+
yield self if block_given?
|
117
|
+
|
118
|
+
define
|
119
|
+
end
|
120
|
+
|
121
|
+
#######
|
122
|
+
private
|
123
|
+
#######
|
124
|
+
|
125
|
+
def define # :nodoc:
|
126
|
+
desc "Render the webgen website"
|
127
|
+
task @name, :verbosity, :log_level do |t, args|
|
128
|
+
require 'webgen/website'
|
129
|
+
website = Webgen::Website.new(@directory, Webgen::Logger.new($stdout), &@config_block)
|
130
|
+
website.logger.verbosity = args[:verbosity].to_s.intern unless args[:verbosity].to_s.empty?
|
131
|
+
website.logger.level = args[:log_level].to_i if args[:log_level]
|
132
|
+
website.render
|
133
|
+
end
|
134
|
+
|
135
|
+
task :clobber => paste('clobber_', @name)
|
136
|
+
|
137
|
+
desc "Remove webgen products"
|
138
|
+
task paste('clobber_', @name) do
|
139
|
+
require 'webgen/website'
|
140
|
+
website = Webgen::Website.new(@directory, Webgen::Logger.new($stdout), &@config_block)
|
141
|
+
website.clean(@clobber_outdir)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
@@ -0,0 +1,214 @@
|
|
1
|
+
# Standard lib requires
|
2
|
+
require 'logger'
|
3
|
+
require 'set'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
# Requirements for Website
|
7
|
+
require 'webgen/coreext'
|
8
|
+
require 'webgen/loggable'
|
9
|
+
require 'webgen/logger'
|
10
|
+
require 'webgen/configuration'
|
11
|
+
require 'webgen/websiteaccess'
|
12
|
+
require 'webgen/blackboard'
|
13
|
+
require 'webgen/cache'
|
14
|
+
require 'webgen/tree'
|
15
|
+
|
16
|
+
# Files for autoloading
|
17
|
+
require 'webgen/common'
|
18
|
+
require 'webgen/source'
|
19
|
+
require 'webgen/output'
|
20
|
+
require 'webgen/sourcehandler'
|
21
|
+
require 'webgen/contentprocessor'
|
22
|
+
|
23
|
+
# Load other needed files
|
24
|
+
require 'webgen/path'
|
25
|
+
require 'webgen/node'
|
26
|
+
require 'webgen/page'
|
27
|
+
|
28
|
+
|
29
|
+
# The Webgen namespace houses all classes/modules used by webgen.
|
30
|
+
module Webgen
|
31
|
+
|
32
|
+
# Returns the data directory for webgen.
|
33
|
+
def self.data_dir
|
34
|
+
unless defined?(@@data_dir)
|
35
|
+
require 'rbconfig'
|
36
|
+
@@data_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'webgen'))
|
37
|
+
@@data_dir = File.expand_path(File.join(Config::CONFIG["datadir"], "webgen")) if !File.exists?(@@data_dir)
|
38
|
+
raise "Could not find webgen data directory! This is a bug, report it please!" unless File.directory?(@@data_dir)
|
39
|
+
end
|
40
|
+
@@data_dir
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# Represents a webgen website and is used to render it.
|
45
|
+
class Website
|
46
|
+
|
47
|
+
# Raised when the configuration file of the website is invalid.
|
48
|
+
class ConfigFileInvalid < RuntimeError; end
|
49
|
+
|
50
|
+
include Loggable
|
51
|
+
|
52
|
+
# The website configuration. Can only be used after #init has been called (which is
|
53
|
+
# automatically done in #render).
|
54
|
+
attr_reader :config
|
55
|
+
|
56
|
+
# The blackboard used for inter-object communication. Can only be used after #init has been
|
57
|
+
# called.
|
58
|
+
attr_reader :blackboard
|
59
|
+
|
60
|
+
# A cache to store information that should be available between runs. Can only be used after
|
61
|
+
# #init has been called.
|
62
|
+
attr_reader :cache
|
63
|
+
|
64
|
+
# The internal data structure used to store information about individual nodes.
|
65
|
+
attr_reader :tree
|
66
|
+
|
67
|
+
# The logger used for logging. If set to +nil+, logging is disabled.
|
68
|
+
attr_accessor :logger
|
69
|
+
|
70
|
+
# The website directory.
|
71
|
+
attr_reader :directory
|
72
|
+
|
73
|
+
# Create a new webgen website for the website in the directory +dir+. You can provide a
|
74
|
+
# block (has to take the configuration object as parameter) for adjusting the configuration
|
75
|
+
# values during the initialization.
|
76
|
+
def initialize(dir, logger=Webgen::Logger.new($stdout, false), &block)
|
77
|
+
@blackboard = nil
|
78
|
+
@cache = nil
|
79
|
+
@config = nil
|
80
|
+
@logger = logger
|
81
|
+
@config_block = block
|
82
|
+
@directory = dir
|
83
|
+
end
|
84
|
+
|
85
|
+
# Define a service +service_name+ provided by the instance of +klass+. The parameter +method+
|
86
|
+
# needs to define the method which should be invoked when the service is invoked. Can only be
|
87
|
+
# used after #init has been called.
|
88
|
+
def autoload_service(service_name, klass, method = service_name)
|
89
|
+
blackboard.add_service(service_name) {|*args| cache.instance(klass).send(method, *args)}
|
90
|
+
end
|
91
|
+
|
92
|
+
# Initialize the configuration, blackboard and cache objects and load the default configuration
|
93
|
+
# as well as website specific extension files. An already existing configuration/blackboard is
|
94
|
+
# deleted!
|
95
|
+
def init
|
96
|
+
execute_in_env do
|
97
|
+
@blackboard = Blackboard.new
|
98
|
+
@config = Configuration.new
|
99
|
+
|
100
|
+
load 'webgen/default_config.rb'
|
101
|
+
Dir.glob(File.join(@directory, 'ext', '**/init.rb')) {|f| load(f)}
|
102
|
+
read_config_file
|
103
|
+
|
104
|
+
@config_block.call(@config) if @config_block
|
105
|
+
restore_tree_and_cache
|
106
|
+
end
|
107
|
+
self
|
108
|
+
end
|
109
|
+
|
110
|
+
# Render the website (after calling #init if the website is not already initialized).
|
111
|
+
def render
|
112
|
+
execute_in_env do
|
113
|
+
init unless @config
|
114
|
+
|
115
|
+
puts "Starting webgen..."
|
116
|
+
shm = SourceHandler::Main.new
|
117
|
+
shm.render(@tree)
|
118
|
+
save_tree_and_cache
|
119
|
+
puts "Finished"
|
120
|
+
|
121
|
+
if @logger && @logger.log_output.length > 0
|
122
|
+
puts "\nLog messages:"
|
123
|
+
puts @logger.log_output
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Clean the website directory from all generated output files (including the cache file). If
|
129
|
+
# +del_outdir+ is +true+, then the base output directory is also deleted. When a delete
|
130
|
+
# operation fails, the error is silently ignored and the clean operation continues.
|
131
|
+
#
|
132
|
+
# Note: Uses the configured output instance for the operations!
|
133
|
+
def clean(del_outdir = false)
|
134
|
+
init
|
135
|
+
execute_in_env do
|
136
|
+
output = @blackboard.invoke(:output_instance)
|
137
|
+
@tree.node_access[:alcn].each do |name, node|
|
138
|
+
next if node.is_fragment? || node['no_output'] || node.path == '/' || node == @tree.dummy_root
|
139
|
+
output.delete(node.path) rescue nil
|
140
|
+
end
|
141
|
+
|
142
|
+
if @config['website.cache'].first == :file
|
143
|
+
FileUtils.rm(File.join(@directory, @config['website.cache'].last)) rescue nil
|
144
|
+
end
|
145
|
+
|
146
|
+
if del_outdir
|
147
|
+
output.delete('/') rescue nil
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# The provided block is executed within a proper environment sothat any object can access the
|
153
|
+
# Website object.
|
154
|
+
def execute_in_env
|
155
|
+
set_back = Thread.current[:webgen_website].nil?
|
156
|
+
Thread.current[:webgen_website] = self
|
157
|
+
yield
|
158
|
+
ensure
|
159
|
+
Thread.current[:webgen_website] = nil if set_back
|
160
|
+
end
|
161
|
+
|
162
|
+
#######
|
163
|
+
private
|
164
|
+
#######
|
165
|
+
|
166
|
+
# Restore the tree and the cache from +website.cache+ and returns the Tree object.
|
167
|
+
def restore_tree_and_cache
|
168
|
+
@cache = Cache.new
|
169
|
+
@tree = Tree.new
|
170
|
+
data = if config['website.cache'].first == :file
|
171
|
+
cache_file = File.join(@directory, config['website.cache'].last)
|
172
|
+
File.open(cache_file, 'rb') {|f| f.read} if File.exists?(cache_file)
|
173
|
+
else
|
174
|
+
config['website.cache'].last
|
175
|
+
end
|
176
|
+
cache_data, @tree = Marshal.load(data) rescue nil
|
177
|
+
@cache.restore(cache_data) if cache_data
|
178
|
+
end
|
179
|
+
|
180
|
+
# Save the +tree+ and the +cache+ to +website.cache+.
|
181
|
+
def save_tree_and_cache
|
182
|
+
cache_data = [@cache.dump, @tree]
|
183
|
+
if config['website.cache'].first == :file
|
184
|
+
cache_file = File.join(@directory, config['website.cache'].last)
|
185
|
+
File.open(cache_file, 'wb') {|f| Marshal.dump(cache_data, f)}
|
186
|
+
else
|
187
|
+
config['website.cache'][1] = Marshal.dump(cache_data)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# Update the configuration object for the website with infos found in the configuration file.
|
192
|
+
def read_config_file
|
193
|
+
file = File.join(@directory, 'config.yaml')
|
194
|
+
if File.exists?(file)
|
195
|
+
begin
|
196
|
+
config = YAML::load(File.read(file)) || {}
|
197
|
+
raise 'Structure of config file is not valid, has to be a Hash' if !config.kind_of?(Hash)
|
198
|
+
config.each do |key, value|
|
199
|
+
case key
|
200
|
+
when *Webgen::Configuration::Helpers.public_instance_methods(false) then @config.send(key, value)
|
201
|
+
else @config[key] = value
|
202
|
+
end
|
203
|
+
end
|
204
|
+
rescue RuntimeError, ArgumentError => e
|
205
|
+
raise ConfigFileInvalid, "Configuration invalid: " + e.message
|
206
|
+
end
|
207
|
+
elsif File.exists?(File.join(@directory, 'config.yml'))
|
208
|
+
log(:warn) { "No configuration file called config.yaml found (there is a config.yml - spelling error?)" }
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|