Class Webgen::WebsiteManager
In: lib/webgen/websitemanager.rb
Parent: Object
Error RenderError CommandNotFoundError LoadError NodeCreationError ::Rake::TaskLib WebgenTask Helpers Configuration Node Context\n[lib/webgen/context.rb\nlib/webgen/context/nodes.rb\nlib/webgen/context/render.rb\nlib/webgen/context/tags.rb] Tree FileSystem Sitemap Copy Feed Virtual Sitemap Directory Page Fragment Template Metainfo Memory Coderay Sitemap IncludeFile BreadcrumbTrail Langbar TikZ Menu Tags Fragments Resource Website Tidy Head Kramdown Less Xmllint Blocks Comparable Language Path StandardError CmdParse::CommandParser CommandParser CmdParse::Command RunCommand WebguiCommand CreateCommand ApplyCommand WebsiteAccess Main Loggable OutputPathHelpers ExecuteCommand Link Date Relocatable Metainfo ::Kramdown::Converter::Html KramdownHtmlConverter Cache Blackboard WebsiteManager Logger Page ProxyNode Utils Scss RDoc Sass Erb RDiscount Erubis Haml Maruku Builder RedCloth AccessHash TarArchive Stacked FileSystem lib/webgen/cache.rb lib/webgen/error.rb lib/webgen/languages.rb lib/webgen/context/render.rb lib/webgen/website.rb lib/webgen/blackboard.rb lib/webgen/tree.rb lib/webgen/websitemanager.rb lib/webgen/logger.rb lib/webgen/configuration.rb lib/webgen/path.rb lib/webgen/webgentask.rb lib/webgen/page.rb lib/webgen/node.rb ClassMethods WebsiteAccess lib/webgen/cli/run_command.rb lib/webgen/cli/utils.rb lib/webgen/cli/apply_command.rb lib/webgen/cli/webgui_command.rb lib/webgen/cli.rb lib/webgen/cli/create_command.rb Color CLI LanguageManager lib/webgen/output/filesystem.rb Output lib/webgen/common/sitemap.rb Common lib/webgen/sourcehandler/memory.rb lib/webgen/sourcehandler/metainfo.rb lib/webgen/sourcehandler/copy.rb lib/webgen/sourcehandler/directory.rb lib/webgen/sourcehandler.rb lib/webgen/sourcehandler/page.rb lib/webgen/sourcehandler/template.rb lib/webgen/sourcehandler/fragment.rb lib/webgen/sourcehandler/sitemap.rb lib/webgen/sourcehandler/virtual.rb lib/webgen/sourcehandler/feed.rb OutputPathHelpers Base SourceHandler lib/webgen/tag/coderay.rb lib/webgen/tag/relocatable.rb lib/webgen/tag/menu.rb lib/webgen/tag/langbar.rb lib/webgen/tag/executecommand.rb lib/webgen/tag/breadcrumbtrail.rb lib/webgen/tag/metainfo.rb lib/webgen/tag/includefile.rb lib/webgen/tag/link.rb lib/webgen/tag/date.rb lib/webgen/tag/tikz.rb lib/webgen/tag/sitemap.rb Base Tag lib/webgen/contentprocessor/less.rb lib/webgen/contentprocessor/scss.rb lib/webgen/contentprocessor/blocks.rb lib/webgen/contentprocessor/rdoc.rb lib/webgen/contentprocessor/sass.rb lib/webgen/contentprocessor/erb.rb lib/webgen/contentprocessor/rdiscount.rb lib/webgen/contentprocessor/tags.rb lib/webgen/contentprocessor/erubis.rb lib/webgen/contentprocessor/kramdown/html.rb lib/webgen/contentprocessor/haml.rb lib/webgen/contentprocessor/maruku.rb lib/webgen/contentprocessor/xmllint.rb lib/webgen/contentprocessor/kramdown.rb lib/webgen/contentprocessor/head.rb lib/webgen/contentprocessor/builder.rb lib/webgen/contentprocessor/tidy.rb lib/webgen/contentprocessor/redcloth.rb lib/webgen/contentprocessor/fragments.rb lib/webgen/contentprocessor.rb ContentProcessor lib/webgen/source/tararchive.rb lib/webgen/source/stacked.rb lib/webgen/source/resource.rb lib/webgen/source/filesystem.rb Source Loggable Webgen dot/m_82_0.png

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.

General information

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).

website bundle resource naming convention

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!

Methods

Attributes

bundles  [R]  A hash with the available website bundles (mapping name to infos).
website  [R]  The used Website object.

Public Class methods

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.

[Source]

    # 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

Public Instance methods

Treat the source as a website bundle and make it available to the WebsiteManager under name.

[Source]

    # 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.

[Source]

    # 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).

[Source]

    # 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

Private Instance methods

Write the paths to the website directory.

[Source]

     # 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

[Validate]