Module: Lifer
- Defined in:
- lib/lifer.rb,
lib/lifer/cli.rb,
lib/lifer/tag.rb,
lib/lifer/entry.rb,
lib/lifer/author.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: Asset, Author, 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", "node_modules", "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.15.2"
Class Method Summary collapse
-
.asset_manifest ⇒ Array<Lifer::Asset>
All of the assets represented in Lifer entries for the current project.
-
.author_manifest ⇒ Set<Lifer::Author>
A set of all authors added to the project.
-
.authors ⇒ Array<Lifer::Author>
All of the authors represented in Lifer entries for the current project.
-
.brain(root: Dir.pwd, config_file: nil) ⇒ Lifer::Brain
The first time
Lifer.brainis referenced, we build a newLifer::Brainobject that is used and reused until the current process has ended. -
.build!(environment: :build) ⇒ void
Initiates the Lifer build process.
-
.collections(without_selections: false) ⇒ Array<Lifer::Collection>
List all collections in the project.
-
.config_file ⇒ Pathname
Used to locate the configuration file being used by the current Lifer project.
-
.entries(order: :latest) ⇒ Set
Uses the entry manifest to return entries in the specified order.
-
.entry_manifest ⇒ Set
Allows for getting the entry manifest or shovelling new entries to the entry manifest.
-
.gem_root ⇒ String
This convenience method locates the Ruby gem root, which is always distinct from the Lifer project root.
-
.ignoreable?(directory_or_file) ⇒ boolean
Check if the given path matches the Lifer ignore patterns.
-
.output_directory ⇒ Pathname
The build directory for the Lifer project.
-
.parallelism_disabled? ⇒ boolean
Returns false if the Lifer project will be built with parallelism.
-
.register_settings(setting, ...) ⇒ void
Register new settings so that they are "safe" and can be read from a Lifer configuration file.
-
.root ⇒ Lifer::Brain
The project brain.
-
.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.
-
.settings ⇒ Hash
The project's current settings tree.
-
.tag_manifest ⇒ Set<Lifer::Tag>
A set of all tags added to the project.
-
.tags ⇒ Array<Lifer::Tag>
All of the tags represented in Lifer entries for the current project.
Class Method Details
.asset_manifest ⇒ Array<Lifer::Asset>
All of the assets represented in Lifer entries for the current project.
36 |
# File 'lib/lifer.rb', line 36 def asset_manifest = brain.asset_manifest |
.author_manifest ⇒ Set<Lifer::Author>
A set of all authors added to the project. Prefer using the #authors
method for author queries.
47 |
# File 'lib/lifer.rb', line 47 def = brain. |
.authors ⇒ Array<Lifer::Author>
All of the authors represented in Lifer entries for the current project.
41 |
# File 'lib/lifer.rb', line 41 def = brain. |
.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.
56 57 58 |
# File 'lib/lifer.rb', line 56 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.
65 |
# File 'lib/lifer.rb', line 65 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.
73 74 75 76 77 |
# File 'lib/lifer.rb', line 73 def collections(without_selections: false) return brain.collections unless without_selections brain.collections.select { _1.class == Lifer::Collection } end |
.config_file ⇒ Pathname
Used to locate the configuration file being used by the current Lifer project.
83 |
# File 'lib/lifer.rb', line 83 def config_file = brain.config.file |
.entries(order: :latest) ⇒ Set
Uses the entry manifest to return entries in the specified order.
89 90 91 92 93 94 95 96 |
# File 'lib/lifer.rb', line 89 def entries(order: :latest) case order when :latest entry_manifest.sort_by { |entry| entry.published_at }.reverse when :oldest entry_manifest.sort_by { |entry| entry.published_at } end end |
.entry_manifest ⇒ Set
Allows for getting the entry manifest or shovelling new entries to the entry manifest.
102 |
# File 'lib/lifer.rb', line 102 def entry_manifest = brain.entry_manifest |
.gem_root ⇒ String
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.
109 |
# File 'lib/lifer.rb', line 109 def gem_root = File.dirname(__dir__) |
.ignoreable?(directory_or_file) ⇒ boolean
Check if the given path matches the Lifer ignore patterns.
115 116 117 |
# File 'lib/lifer.rb', line 115 def ignoreable?(directory_or_file) directory_or_file.match?(/#{IGNORE_PATTERNS.join("|")}/) end |
.output_directory ⇒ Pathname
The build directory for the Lifer project.
123 |
# File 'lib/lifer.rb', line 123 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.
133 |
# File 'lib/lifer.rb', line 133 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.
150 |
# File 'lib/lifer.rb', line 150 def register_settings(*settings) = brain.config.register_settings(*settings) |
.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.
172 173 174 |
# File 'lib/lifer.rb', line 172 def setting(*name, collection: nil, strict: false) brain.setting *name, collection: collection, strict: strict end |
.settings ⇒ Hash
The project's current settings tree.
179 |
# File 'lib/lifer.rb', line 179 def settings = brain.config.settings |
.tag_manifest ⇒ Set<Lifer::Tag>
A set of all tags added to the project. Prefer using the #tags method
for tag queries.
190 |
# File 'lib/lifer.rb', line 190 def tag_manifest = brain.tag_manifest |
.tags ⇒ Array<Lifer::Tag>
All of the tags represented in Lifer entries for the current project.
184 |
# File 'lib/lifer.rb', line 184 def = brain. |