Object
This class is used for managing webgen websites. It provides access to website bundles defined as resources and makes it easy to apply them to a webgen website.
Currently, the following actions are supported:
Bundles are partial webgen websites that contain certain functionality. For example, most of the bundles shipped with webgen are style bundles that define the basic page layout or how image galleries should look like. So style bundles are basically used to change the appearance of parts (or the whole) website. This makes them a powerful tool as this plugin makes it easy to change to another style bundle later!
However, not all bundles have to be style bundles. For example, you could as easily create a bundle for a plugin or for a complete website (e.g. a blog template).
The shipped bundles are defined using resources. Each such resource has to be a directory containing an optional README file in YAML format in which key-value pairs provide additional information about the bundle (e.g. copyright information, description, …). All other files/directories in the directory are copied to the root of the destination webgen website when the bundle is used.
This class uses a special naming convention to recognize website bundles:
A resource named webgen-website-bundle-CATEGORY-NAME is considered to be a bundle in the category CATEGORY called NAME (where CATEGORY is optional). There are no fixed categories, one can use anything here! The shipped style bundles are located in the ‘style’ category. You need to use the the full name, i.e. CATEGORY-NAME, for accessing a bundle later.
Website bundle names have to be unique!
Create a new WebsiteManager.
If dir is a String, then the website manager is created for the website in the directory dir.
If dir is a Website object, the website manager is created for the website represented by dir. If the website object is initialized if it isn’t already.
# File lib/webgen/websitemanager.rb, line 59 59: def initialize(dir) 60: if dir.kind_of?(Webgen::Website) 61: @website = dir 62: @website.init if @website.config.nil? 63: else 64: @website = Webgen::Website.new(dir) 65: @website.init 66: end 67: @bundles = {} 68: 69: @website.execute_in_env do 70: prefix = "webgen-website-bundle-" 71: @website.config['resources'].select {|name, data| name =~ /^#{prefix}/}.each do |name, data| 72: add_source(Webgen::Source::Resource.new(name), name.sub(prefix, '')) 73: end 74: end 75: end
Treat the source as a website bundle and make it available to the WebsiteManager under name.
# File lib/webgen/websitemanager.rb, line 79 79: def add_source(source, name) 80: paths = source.paths.dup 81: readme = paths.select {|path| path == '/README' }.first 82: paths.delete(readme) if readme 83: infos = OpenStruct.new(readme.nil? ? {} : YAML::load(readme.io.data)) 84: infos.paths = paths 85: @bundles[name] = infos 86: end
Apply the given bundle to the website by copying the files.
# File lib/webgen/websitemanager.rb, line 95 95: def apply_bundle(bundle) 96: raise ArgumentError.new("Invalid bundle name") if !@bundles.has_key?(bundle) 97: raise "Directory <#{@website.directory}> does not exist!" unless File.exists?(@website.directory) 98: write_paths(@bundles[bundle].paths) 99: end
Create the basic website skeleton (without any bundle applied).
# File lib/webgen/websitemanager.rb, line 89 89: def create_website 90: raise "Directory <#{@website.directory}> does already exist!" if File.exists?(@website.directory) 91: @website.execute_in_env { write_paths(Webgen::Source::Resource.new('webgen-website-skeleton').paths) } 92: end
Write the paths to the website directory.
# File lib/webgen/websitemanager.rb, line 106 106: def write_paths(paths) 107: paths.each do |path| 108: output_path = File.join(@website.directory, path.path) 109: if path.path =~ /\/$/ 110: FileUtils.mkdir_p(output_path) 111: else 112: FileUtils.mkdir_p(File.dirname(output_path)) 113: path.io.stream do |source| 114: File.open(output_path, 'wb') {|f| FileUtils.copy_stream(source, f) } 115: end 116: end 117: end 118: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.