Class: Bridgetown::Builder

Inherits:
Bridgetown::Builders::PluginBuilder show all
Defined in:
bridgetown-builder/lib/bridgetown-builder/builder.rb

Overview

Superclass for a website’s SiteBuilder abstract class

Instance Attribute Summary

Attributes inherited from Bridgetown::Builders::PluginBuilder

#config, #functions, #name, #site

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Bridgetown::Builders::PluginBuilder

#initialize, plugin_registrations

Methods included from Bridgetown::Builders::DSL::Resources

#add_resource, #define_resource_method, #permalink_placeholder, #placeholder_processors, #resource

Methods included from Bridgetown::Builders::DSL::Liquid

#filters, #filters_context, #liquid_filter, #liquid_tag

Methods included from Bridgetown::Builders::DSL::HTTP

#connection, #get

Methods included from Bridgetown::Builders::DSL::Inspectors

#inspect_html, #inspect_xml, process_html, process_xml, setup_nokogiri, setup_nokolexbor

Methods included from Bridgetown::Builders::DSL::Hooks

#add_data, #hook

Methods included from Bridgetown::Builders::DSL::Helpers

#helper, #helpers

Methods included from Bridgetown::Builders::DSL::Generators

#generator

Methods included from Prioritizable

#<=>, included

Constructor Details

This class inherits a constructor from Bridgetown::Builders::PluginBuilder

Class Method Details

.add_callback(name, method_name = nil, &block) ⇒ Object



23
24
25
26
# File 'bridgetown-builder/lib/bridgetown-builder/builder.rb', line 23

def add_callback(name, method_name = nil, &block)
  callbacks[name] ||= []
  callbacks[name] << (block || proc { send(method_name) })
end

.after_buildObject



15
16
17
# File 'bridgetown-builder/lib/bridgetown-builder/builder.rb', line 15

def after_build(...)
  add_callback(:after, ...)
end

.before_buildObject



11
12
13
# File 'bridgetown-builder/lib/bridgetown-builder/builder.rb', line 11

def before_build(...)
  add_callback(:before, ...)
end

.callbacksObject



19
20
21
# File 'bridgetown-builder/lib/bridgetown-builder/builder.rb', line 19

def callbacks
  @callbacks ||= {}
end

.descendantsObject



40
41
42
43
# File 'bridgetown-builder/lib/bridgetown-builder/builder.rb', line 40

def self.descendants
  site_builder_name = "SiteBuilder"
  super.reject { |klass| [site_builder_name].include?(klass.name) }
end

.registerObject



7
8
9
# File 'bridgetown-builder/lib/bridgetown-builder/builder.rb', line 7

def register
  Bridgetown::Builders::PluginBuilder.plugin_registrations << self
end

Instance Method Details

#build_with_callbacksObject



29
30
31
32
33
34
# File 'bridgetown-builder/lib/bridgetown-builder/builder.rb', line 29

def build_with_callbacks
  self.class.callbacks[:before]&.each { instance_exec(&_1) }
  build
  self.class.callbacks[:after]&.each { instance_exec(&_1) }
  self
end

#inspectObject



36
37
38
# File 'bridgetown-builder/lib/bridgetown-builder/builder.rb', line 36

def inspect
  "#<#{name}>"
end