lifer 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e8681438caf9356526a0af22c91ec3470c3ccba625c7d6602adab532d89a4b2
4
- data.tar.gz: 9c2eefb99f760d50aac163f2dff6e0d06d3710d2a0682426ff45d75733be3640
3
+ metadata.gz: b4416a9edb890d8d98adc06d1baf7e58b695d85da827b48005d7285b6f5a1dbe
4
+ data.tar.gz: 0c45a40304601d473c946315ddea56860041339e029467f8bcecb603ca70a58a
5
5
  SHA512:
6
- metadata.gz: e4411e369a5fab2ec20c0a9c6835279ecc3b0a9c8d522c8ad9b2f5e06223b60ccd3604f576bc9a06f051a6a6e1d33d2990e6e601b1046488ef6812c9ca27182b
7
- data.tar.gz: 45697944e8bb0c378083db6b4ec2c5fe0df67c70a51a5dad87cb6d57fade3f58a98d5dbc07086bd231126f49802c47930490febc85aa1b313bbe372b1a70e13c
6
+ metadata.gz: b8aa3c53f350191b59ff5105ac1130c62c4a2f690aca83794877b933e7d7bfa23e501d2c91bd90dfc4954a4db9edf57b5db8ea4c4bf75fe78aa3e3e3e7e20e0c
7
+ data.tar.gz: f9b729936ec8ef025d9bc6dc8b6deab6d4d63c1d281da50e99df5932cd1f245c581c911378a703f1ddb7e6a5167f21fa746a780ac9e9ad72f29721d93bf34215
data/CHANGELOG.md CHANGED
@@ -1,4 +1,23 @@
1
1
  ## Next
2
+ ## v0.14.0
3
+
4
+ This release includes some really nice improvements and bug fixes:
5
+
6
+ - When returning a list of entries belonging to a `Lifer::Collection` or a
7
+ `Lifer::Tag`, the entries are now returned in reverse chronological order
8
+ by default. (But you can pass the argument `order: :oldest` to get them
9
+ in reverse, if you want.)
10
+ - We fixed a bug where entries in `.html.erb` format that attempted to render
11
+ view partials would error out due to the `render` method not having been
12
+ defined with the context of the entry being built yet. This bug was a bit
13
+ unpleasant to reason about, but it resolves a major defect with ERB building.
14
+ - The included Lifer configuration file template now enables the
15
+ JSON Feed builder by default.
16
+ - Every `Lifer::Selection` name is now automatically registered as a setting so
17
+ that you can configure it like you configure any other collection of entries.
18
+ - Lastly, this release removes `Lifer.manifest`. (A collection of absolute
19
+ paths to every entry file ended up not being incredibly useful. We get
20
+ the same-ish functionality from `Lifer.entry_manifest`.)
2
21
 
3
22
  ## v0.13.0
4
23
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lifer (0.13.0)
4
+ lifer (0.14.0)
5
5
  base64
6
6
  i18n (< 2)
7
7
  kramdown (~> 2.4)
data/lib/lifer/brain.rb CHANGED
@@ -94,17 +94,12 @@ class Lifer::Brain
94
94
  # @return [Lifer::Config] The Lifer configuration object.
95
95
  def config = (@config ||= Lifer::Config.build file: config_file_location)
96
96
 
97
- # Returns all entries that have been added to the manifest. If all is working
98
- # as intended, this should be every entry ever generated.
97
+ # Allows for getting the entry manifest or shovelling new entries to the
98
+ # entry manifest.
99
99
  #
100
100
  # @return [Set<Lifer::Entry>] All entries that currently exist.
101
101
  def entry_manifest = (@entry_manifest ||= Set.new)
102
102
 
103
- # A manifest of all Lifer project entries.
104
- #
105
- # @return [Set<Lifer::Entry>] A set of all entries.
106
- def manifest = (@manifest ||= Set.new)
107
-
108
103
  # Returns the build directory for the Lifer project's build output.
109
104
  #
110
105
  # @return [String] The Lifer build directory.
@@ -18,7 +18,7 @@ class Lifer::Builder
18
18
  # should be expected to.
19
19
  #
20
20
  # @raise [NotImplementedError]
21
- def render
21
+ def render(_path, _locals, _context)
22
22
  raise NotImplementedError,
23
23
  "subclasses must implement a custom `#render` method"
24
24
  end
@@ -11,7 +11,7 @@ class Lifer::Builder::HTML
11
11
  # </head>
12
12
  #
13
13
  # <body>
14
- # <%= partial "_layouts/header.html.erb" %>
14
+ # <%= render "_layouts/header.html.erb" %>
15
15
  #
16
16
  # <h1><%= my_collection.name %></h1>
17
17
  #
@@ -23,7 +23,7 @@ class Lifer::Builder::HTML
23
23
  # </section>
24
24
  # <% end %>
25
25
  #
26
- # <%= partial "_layouts/footer.html.erb" %>
26
+ # <%= render "_layouts/footer.html.erb" %>
27
27
  # </body>
28
28
  # </html>
29
29
  #
@@ -101,16 +101,20 @@ class Lifer::Builder::HTML
101
101
  collections = collection_context_class.new Lifer.collections
102
102
  tags = tag_context_class.new Lifer.tags
103
103
 
104
- binding.local_variable_set :collections, collections
105
- binding.local_variable_set :settings, Lifer.settings
106
- binding.local_variable_set :tags, tags
107
- binding.local_variable_set :content,
108
- ERB.new(entry.to_html).result(binding)
104
+ current_binding = binding
105
+ current_binding.local_variable_set :collections, collections
106
+ current_binding.local_variable_set :settings, Lifer.settings
107
+ current_binding.local_variable_set :tags, tags
109
108
 
110
109
  define_singleton_method :render,
111
110
  -> (relative_path_to_template, locals = {}) {
112
- partial_render_method relative_path_to_template, locals
111
+ partial_render_method relative_path_to_template,
112
+ locals,
113
+ current_binding
113
114
  }
115
+
116
+ current_binding.local_variable_set :content,
117
+ ERB.new(entry.to_html).result(binding)
114
118
  }
115
119
  end
116
120
 
@@ -130,21 +134,23 @@ class Lifer::Builder::HTML
130
134
  # available from entry and layout templates.
131
135
  #
132
136
  # @example Usage
133
- # <%= partial "_layouts/my_partial.html.erb", id: "123" %>
137
+ # <%= render "_layouts/my_partial.html.erb", id: "123" %>
134
138
  # @param relative_path_to_template [String] The path, from the Lifer root,
135
139
  # to the partial layout file.
136
140
  # @param locals [Hash] Additional data that should be passed along for
137
141
  # rendering the partial.
142
+ # @param source_binding [Binding] A binding object carrying context
143
+ # required to render the current partial layout.
138
144
  # @return [String] The rendered partial document.
139
- def partial_render_method(relative_path_to_template, locals)
145
+ def partial_render_method(relative_path_to_template, locals, source_binding)
140
146
  template_path = File.join(Lifer.root, relative_path_to_template)
141
147
 
142
148
  partial_binding = binding.tap { |binding|
143
- context.local_variables.each do |variable|
149
+ source_binding.local_variables.each do |variable|
144
150
  next if variable == :content
145
151
 
146
152
  binding.local_variable_set variable,
147
- context.local_variable_get(variable)
153
+ source_binding.local_variable_get(variable)
148
154
  end
149
155
 
150
156
  locals.each do |key, value|
@@ -116,7 +116,7 @@ class Lifer::Builder::HTML < Lifer::Builder
116
116
  # entry cannot be output to HTML. We should not care about this return
117
117
  # value.
118
118
  def generate_output_file_for(entry)
119
- return unless entry.class.output_extension == :html
119
+ return unless entry.output_extension == :html
120
120
 
121
121
  relative_path = output_file entry
122
122
  absolute_path = File.join(Lifer.output_directory, relative_path)
@@ -56,7 +56,7 @@ class Lifer::Builder::TXT < Lifer::Builder
56
56
  end
57
57
 
58
58
  def generate_output_file_for(entry)
59
- return unless entry.class.output_extension == :txt
59
+ return unless entry.output_extension == :txt
60
60
 
61
61
  relative_path = output_file entry
62
62
  absolute_path = File.join(Lifer.output_directory, relative_path)
@@ -32,12 +32,13 @@ class Lifer::Collection
32
32
  .select { |candidate| Lifer::Entry.supported? candidate }
33
33
 
34
34
  entries = entry_glob.select { |entry|
35
- if Lifer.manifest.include? entry
35
+ filenames = Lifer.entry_manifest.map(&:file)
36
+
37
+ if filenames.include? entry
36
38
  false
37
39
  elsif Lifer.ignoreable? entry.gsub("#{directory}/", "")
38
40
  false
39
41
  else
40
- Lifer.manifest << entry
41
42
  true
42
43
  end
43
44
  }.map { |entry| Lifer::Entry.generate file: entry, collection: }
data/lib/lifer/entry.rb CHANGED
@@ -205,6 +205,12 @@ module Lifer
205
205
  @full_text ||= File.readlines(file).join if file
206
206
  end
207
207
 
208
+ # The file extension to be used when at the entry's build time. For
209
+ # example, a Markdown file should be built to HTML.
210
+ #
211
+ # @return [String]
212
+ def output_extension = self.class.output_extension
213
+
208
214
  # Using the current Lifer configuration, we can calculate the expected
209
215
  # permalink for the entry. For example:
210
216
  #
@@ -6,7 +6,7 @@
6
6
  # detected Ruby files are dynamically loaded when `Lifer::Brain` is initialized.
7
7
  #
8
8
  # Implementing a selection is simple. Just implement the `#entries` method and
9
- # rovide a name. The `#entries` method can be used to filter down
9
+ # provide a name. The `#entries` method can be used to filter down
10
10
  # `Lifer.entry_manifest` in whichever way one needs. To see examples of this,
11
11
  # check out the source code of any of the included selections.
12
12
  #
@@ -25,7 +25,9 @@ class Lifer::Selection < Lifer::Collection
25
25
  #
26
26
  # @return [Lifer::Selection]
27
27
  def generate
28
- new(name: name, directory: nil)
28
+ selection = new(name: name, directory: nil)
29
+ Lifer.register_settings name
30
+ selection
29
31
  end
30
32
 
31
33
  private
data/lib/lifer/tag.rb CHANGED
@@ -43,11 +43,22 @@ module Lifer
43
43
 
44
44
  attr_accessor :name
45
45
 
46
- attr_reader :entries
47
-
48
46
  def initialize(name:, entries:)
49
47
  @name = name
50
48
  @entries = entries
51
49
  end
50
+
51
+ # Returns the tag's associated entries in order.
52
+ #
53
+ # @param order [Symbol] Either :latest (descending) or :oldest (ascending).
54
+ # @return [Array<Lifer::Entry>] The entries for the current tag.
55
+ def entries(order: :latest)
56
+ case order
57
+ when :latest
58
+ @entries.sort_by { |entry| entry.published_at }.reverse
59
+ when :oldest
60
+ @entries.sort_by { |entry| entry.published_at }
61
+ end
62
+ end
52
63
  end
53
64
  end
@@ -92,6 +92,7 @@ global:
92
92
  build:
93
93
  - html
94
94
  - rss
95
+ - json_feed
95
96
  - txt
96
97
  host: https://example.com
97
98
  output_directory: _build
@@ -59,7 +59,7 @@ class Lifer::URIStrategy
59
59
 
60
60
  private
61
61
 
62
- def file_extension(entry) = entry.class.output_extension
62
+ def file_extension(entry) = entry.output_extension
63
63
 
64
64
  self.name = :uri_strategy
65
65
  end
data/lib/lifer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lifer
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  end
data/lib/lifer.rb CHANGED
@@ -81,9 +81,21 @@ module Lifer
81
81
  # @return [Pathname] The path to the current Lifer config file.
82
82
  def config_file = brain.config.file
83
83
 
84
- # A set of all entries currently in the project.
85
- #
86
- # @fixme Do we need this as well as `Lifer.manifest`?
84
+ # Uses the entry manifest to return entries in the specified order.
85
+ #
86
+ # @param order [Symbol] Either :latest (descending) or :oldest (ascending).
87
+ # @return [Set] All entries in the specified order.
88
+ def entries(order: :latest)
89
+ case order
90
+ when :latest
91
+ entry_manifest.sort_by { |entry| entry.published_at }.reverse
92
+ when :oldest
93
+ entry_manifest.sort_by { |entry| entry.published_at }
94
+ end
95
+ end
96
+
97
+ # Allows for getting the entry manifest or shovelling new entries to the
98
+ # entry manifest.
87
99
  #
88
100
  # @return [Set] All entries.
89
101
  def entry_manifest = brain.entry_manifest
@@ -103,13 +115,6 @@ module Lifer
103
115
  directory_or_file.match?(/#{IGNORE_PATTERNS.join("|")}/)
104
116
  end
105
117
 
106
- # A set of all entries currently in the project.
107
- #
108
- # @fixme Do we need this as well as `Lifer.manifest`?
109
- #
110
- # @return [Set] All entries.
111
- def manifest = brain.manifest
112
-
113
118
  # The build directory for the Lifer project.
114
119
  #
115
120
  # @return [Pathname] The absolute path to the directory where the Lifer
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - benjamin wil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-30 00:00:00.000000000 Z
11
+ date: 2026-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -229,8 +229,8 @@ licenses:
229
229
  - MIT
230
230
  metadata:
231
231
  allowed_push_host: https://rubygems.org
232
- homepage_uri: https://github.com/benjaminwil/lifer/blob/v0.13.0/README.md
233
- source_code_uri: https://github.com/benjaminwil/lifer/tree/v0.13.0
232
+ homepage_uri: https://github.com/benjaminwil/lifer/blob/v0.14.0/README.md
233
+ source_code_uri: https://github.com/benjaminwil/lifer/tree/v0.14.0
234
234
  changelog_uri: https://github.com/benjaminwil/lifer/blob/main/CHANGELOG.md
235
235
  post_install_message:
236
236
  rdoc_options: []