Module: Bridgetown::Site::Extensible
- Included in:
- Bridgetown::Site
- Defined in:
- bridgetown-core/lib/bridgetown-core/concerns/site/extensible.rb
Instance Method Summary collapse
-
#find_converter_instance(klass) ⇒ Converter
Get the implementation for the given Converter class.
-
#generate ⇒ void
Run all Generators.
-
#instantiate_subclasses(klass) ⇒ Array<Converter, Generator>
Create an array of instances of the subclasses of the class passed in as argument.
-
#on(event, reloadable: false) {|site| ... } ⇒ Object
Shorthand for registering a site hook via Hooks.
-
#setup ⇒ void
Load necessary libraries, plugins, converters, and generators.
Instance Method Details
#find_converter_instance(klass) ⇒ Converter
Get the implementation for the given Converter class.
40 41 42 43 44 45 |
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/extensible.rb', line 40 def find_converter_instance(klass) @find_converter_instance ||= {} @find_converter_instance[klass] ||= converters.find do |converter| converter.instance_of?(klass) end || raise("No Converters found for #{klass}") end |
#generate ⇒ void
This method returns an undefined value.
Run all Generators.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/extensible.rb', line 21 def generate generators.each do |generator| start = Time.now generator.generate(self) next unless ENV["BRIDGETOWN_LOG_LEVEL"] == "debug" generator_name = generator.class.respond_to?(:custom_name) ? generator.class.custom_name : generator.class.name Bridgetown.logger.debug "Generating:", "#{generator_name} finished in #{Time.now - start} seconds." end end |
#instantiate_subclasses(klass) ⇒ Array<Converter, Generator>
Create an array of instances of the subclasses of the class passed in as argument.
52 53 54 55 56 |
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/extensible.rb', line 52 def instantiate_subclasses(klass) klass.descendants.sort.map do |c| c.new(config) end end |
#on(event, reloadable: false) {|site| ... } ⇒ Object
Shorthand for registering a site hook via Hooks
62 63 64 |
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/extensible.rb', line 62 def on(event, reloadable: false, &) Bridgetown::Hooks.register_one :site, event, reloadable:, & end |
#setup ⇒ void
This method returns an undefined value.
Load necessary libraries, plugins, converters, and generators. This is only ever run once for the lifecycle of the site object.
11 12 13 14 15 16 |
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/extensible.rb', line 11 def setup plugin_manager.require_plugin_files loaders_manager.setup_loaders self.converters = instantiate_subclasses(Bridgetown::Converter) self.generators = instantiate_subclasses(Bridgetown::Generator) end |