Class: Lifer::Collection
- Inherits:
-
Object
- Object
- Lifer::Collection
- Defined in:
- lib/lifer/collection.rb
Overview
A collection collects entries. Every entry can only be included in a single collection. Collections let the user group entries together into logical units. For example, if the user wants to present blog posts in one way and wiki pages in a different way, it would make sense to create separate “blog” and “wiki” collections.
Each collection can have its own feeds and settings. The only special collection is the “root” collection, which is where all entries that don’t fall into other collections end up.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.generate(name:, directory:) ⇒ Lifer::Collection
Generate a new collection.
Instance Method Summary collapse
-
#entries(order: :latest) ⇒ Array<Lifer::Entry>
Each collection has a collection of entries.
-
#layout_file ⇒ String
To allow for flexible configuration, a layout file may be set by users to either an absolute path or a path relative to the configuration file’s location.
-
#root? ⇒ boolean
Check whether the current collection is the root collection.
-
#setting(*name, strict: false) ⇒ String, Nil
Gets a Lifer setting, scoped to the current collection.
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/lifer/collection.rb', line 12 def name @name end |
Class Method Details
.generate(name:, directory:) ⇒ Lifer::Collection
Generate a new collection.
21 22 23 24 25 |
# File 'lib/lifer/collection.rb', line 21 def generate(name:, directory:) collection = new(name: name, directory:) build_collection_entries!(collection, directory:) collection end |
Instance Method Details
#entries(order: :latest) ⇒ Array<Lifer::Entry>
Each collection has a collection of entries. An entry only belongs to one collection.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/lifer/collection.rb', line 53 def entries(order: :latest) cached_entries_variable = "@collection_entries_#{order}" instance_variable_get(cached_entries_variable) || instance_variable_set( cached_entries_variable, case order when :latest @entries_collection.sort_by { |entry| entry.published_at }.reverse when :oldest @entries_collection.sort_by { |entry| entry.published_at } end ) end |
#layout_file ⇒ String
To allow for flexible configuration, a layout file may be set by users to either an absolute path or a path relative to the configuration file’s location. This method, though, always returns the absolute path.
72 73 74 75 76 77 78 79 |
# File 'lib/lifer/collection.rb', line 72 def layout_file return setting :layout_file if setting(:layout_file).include?(Lifer.gem_root) return setting :layout_file if setting(:layout_file).include?(Lifer.root) config_directory = File.dirname Lifer.config_file [config_directory, setting(:layout_file)].join "/" end |
#root? ⇒ boolean
Check whether the current collection is the root collection.
84 85 86 |
# File 'lib/lifer/collection.rb', line 84 def root? name == :root end |