module Bridgetown::Builders::DSL::Generators

Public Instance Methods

generate(_site) click to toggle source
# File lib/bridgetown-builder/dsl/generators.rb, line 21
def generate(_site)
  _builder_block.call
end
generator(method_name = nil, &block) click to toggle source
# File lib/bridgetown-builder/dsl/generators.rb, line 7
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

  new_gen = Class.new(Bridgetown::Generator) do
    define_method(:_builder_block) { block }
    define_singleton_method(:custom_name) { local_name }

    attr_reader :site

    def inspect
      "#{self.class.custom_name} (Generator)"
    end

    def generate(_site)
      _builder_block.call
    end
  end

  first_low_priority_index = site.generators.find_index { |gen| gen.class.priority == :low }
  site.generators.insert(first_low_priority_index || 0, new_gen.new(site.config))

  functions << { name: name, generator: new_gen }
end
inspect() click to toggle source
# File lib/bridgetown-builder/dsl/generators.rb, line 17
def inspect
  "#{self.class.custom_name} (Generator)"
end