Class: Webgen::Website
- Inherits:
-
Object
- Object
- Webgen::Website
- Defined in:
- lib/webgen/website.rb
Overview
About
Represents a webgen website and provides the main interface for users.
Normally, webgen is used from the command line via the webgen
command or from Rakefiles via Webgen::RakeTask. However, you can also easily use webgen as a library and this class provides the interface for this usage!
You may notice that this class doesn’t have many methods. This is because webgen is designed from ground up to be extensible. Most of the ‘magic’ happens in extensions which are registered on the #ext OpenStruct object. The simple ‘core’ classes that are not extensions have separate accessor methods (#config for the Configuration object, #blackboard for the Blackboard and so on).
Since a webgen website is, basically, just a directory, the only parameter needed for creating a new Website object is the website directory. Once created, the website is fully initialized and one can work with it:
-
If you want to generate the website, you just need to call #execute_task with :generate_website as parameter.
-
If you want to retrieve data from the website, you can use the various accessors on the Website object itself or use #ext to access all available extensions.
Note: This is generally only useful if the website has been generated before because otherwise there probably is no data to retrieve.
Constant Summary collapse
- CONFIG_FILENAME =
The name of the configuration file webgen uses.
'webgen.config'
Instance Attribute Summary collapse
-
#blackboard ⇒ Object
readonly
The blackboard used for inter-object communication.
-
#cache ⇒ Object
readonly
A cache to store information that should be available the next time the website gets generated.
-
#config ⇒ Object
readonly
The website configuration.
-
#directory ⇒ Object
readonly
The website directory.
-
#ext ⇒ Object
readonly
Access to all extension objects.
-
#logger ⇒ Object
readonly
The Webgen::Logger used for logging.
-
#tree ⇒ Object
readonly
The internal data structure used to store information about individual nodes.
Instance Method Summary collapse
-
#execute_task(task, *options) ⇒ Object
Execute the given task.
-
#initialize(dir, logger = nil, &block) ⇒ Website
constructor
Create a new webgen Website object for the website in the directory
dir
. -
#save_cache ⇒ Object
Save the
cache
. -
#tmpdir(path = '', create = false) ⇒ Object
Append the path to the website’s temporary directory and return the full path to it.
Constructor Details
#initialize(dir, logger = nil, &block) ⇒ Website
Create a new webgen Website object for the website in the directory dir
.
If no logger is specified, a dummy logger that logs to a StringIO is created.
You can provide a block for modifying the Website object in any way during the initialization:
-
If the block only takes one parameter, it is called with the Website object after the initialization is done but before the cache is restored.
-
If it takes two parameters, the first one is the Website object and the second one is a boolean specifying whether the block is currently called any initialization (value is
true
) or after it (value is +false).
95 96 97 98 99 100 |
# File 'lib/webgen/website.rb', line 95 def initialize(dir, logger = nil, &block) @directory = dir @logger = logger || Webgen::Logger.new(StringIO.new) @init_block = block init end |
Instance Attribute Details
#blackboard ⇒ Object (readonly)
The blackboard used for inter-object communication.
62 63 64 |
# File 'lib/webgen/website.rb', line 62 def blackboard @blackboard end |
#cache ⇒ Object (readonly)
A cache to store information that should be available the next time the website gets generated.
66 67 68 |
# File 'lib/webgen/website.rb', line 66 def cache @cache end |
#config ⇒ Object (readonly)
The website configuration.
59 60 61 |
# File 'lib/webgen/website.rb', line 59 def config @config end |
#directory ⇒ Object (readonly)
The website directory.
80 81 82 |
# File 'lib/webgen/website.rb', line 80 def directory @directory end |
#ext ⇒ Object (readonly)
Access to all extension objects. An OpenStruct object.
69 70 71 |
# File 'lib/webgen/website.rb', line 69 def ext @ext end |
#logger ⇒ Object (readonly)
The Webgen::Logger used for logging.
77 78 79 |
# File 'lib/webgen/website.rb', line 77 def logger @logger end |
#tree ⇒ Object (readonly)
The internal data structure used to store information about individual nodes.
See Tree for more information
74 75 76 |
# File 'lib/webgen/website.rb', line 74 def tree @tree end |
Instance Method Details
#execute_task(task, *options) ⇒ Object
Execute the given task.
See Webgen::Task and the classes in its namespace for available classes.
208 209 210 |
# File 'lib/webgen/website.rb', line 208 def execute_task(task, *) @ext.task.execute(task, *) end |
#save_cache ⇒ Object
Save the cache
.
180 181 182 183 184 185 186 187 188 |
# File 'lib/webgen/website.rb', line 180 def save_cache return if config['website.dry_run'] cache_data = [@cache.dump, Webgen::VERSION] if config['website.cache'].first == 'file' File.open(cache_file(true), 'wb') {|f| Marshal.dump(cache_data, f)} else config['website.cache'][1] = Marshal.dump(cache_data) end end |
#tmpdir(path = '', create = false) ⇒ Object
Append the path to the website’s temporary directory and return the full path to it.
Note that the temporary directory is only created if the create
parameter is set to true.
199 200 201 202 203 |
# File 'lib/webgen/website.rb', line 199 def tmpdir(path = '', create = false) @_tmpdir = File.absolute_path(config['website.tmpdir'], @directory) unless defined?(@_tmpdir) FileUtils.mkdir_p(@_tmpdir) if create File.join(@_tmpdir, path) end |