Class: Stic::Generator
- Inherits:
-
Object
- Object
- Stic::Generator
- Defined in:
- lib/stic/generator.rb
Overview
A Generator generates blobs or specific subclasses based on some input.
As an example see Stic::Generators::Static that generates blobs for static files.
A generator will be initialized by the system and it’s #run method will be invoked. The generator now can add blobs to the ‘site`. Subclass must override the #run method providing custom logic.
Direct Known Subclasses
Attributes collapse
-
#config ⇒ HashWithIndifferentAccess
readonly
The generator specific configuration.
-
#site ⇒ Site
readonly
The Site object.
Construction collapse
-
#initialize(site, config) ⇒ Generator
constructor
Initialize new Generator.
Accessors collapse
-
#disabled? ⇒ Boolean
Check if generator is disabled.
-
#name ⇒ String
Return generator name.
Actions collapse
-
#run ⇒ Object
Run this Generator.
Constructor Details
#initialize(site, config) ⇒ Generator
Initialize new Stic::Generator.
40 41 42 43 |
# File 'lib/stic/generator.rb', line 40 def initialize(site, config) @site = site @config = ::ActiveSupport::HashWithIndifferentAccess.new((config && config[name]) || {}) end |
Instance Attribute Details
#config ⇒ HashWithIndifferentAccess (readonly)
The generator specific configuration. The values are passed from Site and are loaded from ‘generators.<generator name>`.
29 30 31 |
# File 'lib/stic/generator.rb', line 29 def config @config end |
Instance Method Details
#disabled? ⇒ Boolean
Check if generator is disabled.
A generator can be disabled by setting the generator’s ‘disable` configuration key to either ’true’ or ‘yes’.
63 64 65 |
# File 'lib/stic/generator.rb', line 63 def disabled? %w(true yes).includes? config['disable'].to_s end |
#name ⇒ String
Return generator name. The name is derived from the class name as an underscore string with ‘_generator` striped from the end.
52 53 54 |
# File 'lib/stic/generator.rb', line 52 def name self.class.name.underscore.gsub(/_generator$/, '') end |
#run ⇒ Object
Run this Stic::Generator. This is the place to implement custom logic and add Blobs to the site.
The #run method must be implemented by a subclass.
74 75 76 |
# File 'lib/stic/generator.rb', line 74 def run raise NotImplementedError.new "#{self.class.name}#run not implemented." end |