Class: Lifer::Builder

Inherits:
Object
  • Object
show all
Includes:
Shared::FinderMethods
Defined in:
lib/lifer/builder.rb,
lib/lifer/builder/html/from_any.rb

Overview

Builders are a core part of Lifer. Builders are configured by users in the configuration file and take the content of a Lifer project and turn it into built stuff. That could be feeds, HTML documents, or other weird files.

This base class includes some special functionality for running all builders when a Lifer build is executed. But it also sets in stone the public API for implementing builder classes. (In short: an ‘.execute` class method and an `#execute` instance method.)

Direct Known Subclasses

HTML, RSS, TXT

Defined Under Namespace

Modules: InitializeBuilder Classes: HTML, RSS, TXT

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/lifer/builder.rb', line 16

def name
  @name
end

.settingsObject

Returns the value of attribute settings.



16
17
18
# File 'lib/lifer/builder.rb', line 16

def settings
  @settings
end

Class Method Details

.build!(*builder_names, root:) ⇒ void

This method returns an undefined value.

Given a list of builder names, we execute every builder based on the configured Lifer project root.

Parameters:

  • builder_names (Array<string>)

    A list of builder names.

  • root (string)

    The absolute path to the Lifer root directory.



33
34
35
36
37
# File 'lib/lifer/builder.rb', line 33

def build!(*builder_names, root:)
  builder_names.each do |builder|
    Lifer::Builder.find(builder).execute root: root
  end
end

.execute(root:) ⇒ NotImplementedError

Every builder class must have execute method. This is the entrypoint for instantiating and executing any builder.

Parameters:

  • root (string)

    An absolute path to the Lifer project root directory.

Returns:

  • (NotImplementedError)

    A builder subclass must implement this method.



25
# File 'lib/lifer/builder.rb', line 25

def execute(root:) = (raise NotImplementedError)

.prebuild!(*commands, root:) ⇒ void

This method returns an undefined value.

Given a list of prebuild commands, execute each one in the shell. This is meant to be run once before ‘.build!` is run once.

Parameters:

  • commands (Array<string>)

    A list of executable commands.

  • root (string)

    The absolute path to the Lifer root directory.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lifer/builder.rb', line 45

def prebuild!(*commands, root:)
  commands.each do |command|
    puts command

    _stdin, stdout, stderr, _wait_thread = Open3.popen3(command)

    if (error_messages = stderr.readlines).any?
      raise error_messages.join("\n")
    end

    stdout.readlines.each { puts _1 }
  end
rescue => exception
  raise I18n.t("builder.prebuild_failure", exception:)
end

Instance Method Details

#executeNotImplementedError

Every builder class must have execute instance method. This is where the core logic of the builder runs from after initialization.

Returns:

  • (NotImplementedError)

    A builder subclass must implement this method.



83
# File 'lib/lifer/builder.rb', line 83

def execute = (raise NotImplementedError)