Module: Lifer

Defined in:
lib/lifer.rb,
lib/lifer/cli.rb,
lib/lifer/tag.rb,
lib/lifer/entry.rb,
lib/lifer/version.rb

Overview

The root Lifer module is a great entrypoint into the system, with convenience methods to access global resources like collections and configuration settings.

Defined Under Namespace

Modules: Dev, Shared, Utilities Classes: Brain, Builder, CLI, Collection, Config, Entry, Message, Selection, Tag, URIStrategy

Constant Summary collapse

IGNORE_DIRECTORIES =

Lifer considers files and directories that have the following names or contain the following patterns special and ignoreable when they’re at the root of the Lifer project.

[
  "assets",
  "bin",
  "vendor"
]
IGNORE_PATTERNS =

Lifer projects ignore files and directories that contain particular patterns.

[
  "^(\\.)",     # Starts with a dot.
  "^(_)",       # Starts with an underscore.
  "(\\/\\.)+"   # Contains a dot directory.
] | IGNORE_DIRECTORIES.map { |d| "^(#{d})" }
FRONTMATTER_REGEX =

We expect frontmatter in any file to be provided in the following format.

/^---\n(.*)---\n/m
VERSION =
"0.10.1"

Class Method Summary collapse

Class Method Details

.brain(root: Dir.pwd, config_file: nil) ⇒ Lifer::Brain

The first time ‘Lifer.brain` is referenced, we build a new `Lifer::Brain` object that is used and reused until the current process has ended.

Parameters:

  • root (String) (defaults to: Dir.pwd)

    The absolute path to the Lifer project root.

  • config_file (String) (defaults to: nil)

    The absolute path to the Lifer project’s configuration file.

Returns:



39
40
41
# File 'lib/lifer.rb', line 39

def brain(root: Dir.pwd, config_file: nil)
  @@brain ||= Lifer::Brain.init root:, config_file:
end

.build!(environment: :build) ⇒ void

This method returns an undefined value.

Initiates the Lifer build process.

Parameters:

  • environment (Symbol) (defaults to: :build)

    The name of the current Lifer environment. Valid environments are ‘:build` or `:serve`.



48
# File 'lib/lifer.rb', line 48

def build!(environment: :build) = (brain.build! environment:)

.collections(without_selections: false) ⇒ Array<Lifer::Collection>

List all collections in the project. By default, selections are also included.

Parameters:

  • without_selections (boolean) (defaults to: false)

    Whether to include selections in the list. (Default: false.)

Returns:



56
57
58
59
60
# File 'lib/lifer.rb', line 56

def collections(without_selections: false)
  return brain.collections unless without_selections

  brain.collections.select { _1.class == Lifer::Collection }
end

.config_filePathname

Used to locate the configuration file being used by the current Lifer project.

Returns:

  • (Pathname)

    The path to the current Lifer config file.



66
# File 'lib/lifer.rb', line 66

def config_file = brain.config.file

.entry_manifestSet

A set of all entries currently in the project.

Returns:

  • (Set)

    All entries.



73
# File 'lib/lifer.rb', line 73

def entry_manifest = brain.entry_manifest

.gem_rootString

This convenience method locates the Ruby gem root, which is always distinct from the Lifer project root. This is helpful, for example, if default templates provided by the gem are required in the current project.

Returns:

  • (String)

    The absolute path to the installed Lifer gem root.



80
# File 'lib/lifer.rb', line 80

def gem_root = File.dirname(__dir__)

.ignoreable?(directory_or_file) ⇒ boolean

Check if the given path matches the Lifer ignore patterns.

Parameters:

  • directory_or_file (String)

    The path to a directory or file.

Returns:

  • (boolean)

    True if the directory of file is ignoreable.



86
87
88
# File 'lib/lifer.rb', line 86

def ignoreable?(directory_or_file)
  directory_or_file.match?(/#{IGNORE_PATTERNS.join("|")}/)
end

.manifestSet

A set of all entries currently in the project.

Returns:

  • (Set)

    All entries.



95
# File 'lib/lifer.rb', line 95

def manifest = brain.manifest

.output_directoryPathname

The build directory for the Lifer project.

Returns:

  • (Pathname)

    The absolute path to the directory where the Lifer project would be built to.



101
# File 'lib/lifer.rb', line 101

def output_directory = brain.output_directory

.parallelism_disabled?boolean

Returns false if the Lifer project will be built with parallelism. This should return false almost always–unless you’ve explicitly set the ‘LIFER_UNPARALLELIZED` environment variable before running the program.

This method is used internally by Lifer to determine whether features that would normally run in parallel should not run in parallel for some reason.

Returns:

  • (boolean)

    Returns whether parallelism is disabled.



111
# File 'lib/lifer.rb', line 111

def parallelism_disabled? = ENV["LIFER_UNPARALLELIZED"].is_a?(String)

.register_settings(setting, ...) ⇒ void

Register new settings so that they are “safe” and can be read from a Lifer configuration file. Unregistered settings are ignored.

Examples:

Usage

register_settings(
  :hidden,
  :birthday,
  jsonfeed: [:enabled, :url, :style]
)

This method returns an undefined value.

Parameters:

  • setting (Symbol, Hash)

    A setting or setting tree to be registered.

  • ... (Symbol, Hash)

    More settings or settings trees to be registered.



128
# File 'lib/lifer.rb', line 128

def register_settings(*settings) = brain.config.register_settings(*settings)

.rootLifer::Brain

The project brain.

Returns:



133
# File 'lib/lifer.rb', line 133

def root = brain.root

.setting(..., collection: nil, strict: false) ⇒ String, NilClass

Given a path to a setting, with or without a collection scope, get the current configured value for that setting.

Note that if a collection does not have a setting set, the setting returned will be the Lifer root collection setting or the default setting unless the ‘:strict` keyword argument is set to `true`.

Returns The value of the best in-scope setting.

Parameters:

  • ... (Symbol)

    A list of settings to traverse the settings tree with.

  • collection (Lifer::Collection) (defaults to: nil)

    The collection scope for the wanted setting.

  • strict (boolean) (defaults to: false)

    Choose whether to strictly return the collection setting or to fallback to the Lifer root and default settings. (Default: false.)

Returns:

  • (String, NilClass)

    The value of the best in-scope setting.



150
151
152
# File 'lib/lifer.rb', line 150

def setting(*name, collection: nil, strict: false)
  brain.setting *name, collection: collection, strict: strict
end

.settingsHash

The project’s current settings tree.

Returns:

  • (Hash)

    The ‘Lifer::Config#settings`.



157
# File 'lib/lifer.rb', line 157

def settings = brain.config.settings

.tag_manifestSet<Lifer::Tag>

A set of all tags added to the project. Prefer using the ‘#tags` method for tag queries.

Returns:



168
# File 'lib/lifer.rb', line 168

def tag_manifest = brain.tag_manifest

.tagsArray<Lifer::Tag>

All of the tags represented in Lifer entries for the current project.

Returns:

  • (Array<Lifer::Tag>)

    The complete list of tags.



162
# File 'lib/lifer.rb', line 162

def tags = brain.tags