Module: Bridgetown::Builders::DSL::Generators
- Included in:
- PluginBuilder
- Defined in:
- lib/bridgetown-builder/dsl/generators.rb
Instance Method Summary collapse
-
#generator(method_name = nil, &block) ⇒ Object
Set up a new generator based on the block or method provided which will run alongside other generators during the build process.
Instance Method Details
#generator(method_name = nil, &block) ⇒ Object
Set up a new generator based on the block or method provided which will run alongside other generators during the build process
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bridgetown-builder/dsl/generators.rb', line 11 def generator(method_name = nil, &block) block = method(method_name) if method_name.is_a?(Symbol) local_name = name # pull the name method into a local variable builder_priority = self.class.instance_variable_get(:@priority) anon_generator = Class.new(Bridgetown::Generator) do define_method(:_builder_block) { block } define_singleton_method(:custom_name) { local_name } attr_reader :site priority builder_priority || :low def inspect "#<#{self.class.custom_name} (Generator)>" end def generate(_site) _builder_block.call end end site.generators << anon_generator.new(site.config) site.generators.sort! functions << { name:, generator: anon_generator } end |