lifer 0.11.0 → 0.12.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 +4 -4
- data/CHANGELOG.md +12 -1
- data/Gemfile.lock +3 -3
- data/lib/lifer/builder/html/from_any.rb +1 -1
- data/lib/lifer/builder/html/from_erb.rb +52 -3
- data/lib/lifer/builder/html/from_liquid.rb +4 -4
- data/lib/lifer/builder/html.rb +16 -3
- data/lib/lifer/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f018de3a46e9674b5d0da11bb7d0dd5e111c7f8119d4c901fa2fb5d2458a9ab
|
4
|
+
data.tar.gz: a17f6d9a91115594caa0f786f4bbecb01b4f3afc2925864ed62cf8ead11de457
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d2f01b4f70b947cba613f7bf23be66d777f23d9188d055a453586b1bca8ef46ef818faccb108d909ce2d809c9a4e15a162c0822f6a6e0d340682bbd525e436e
|
7
|
+
data.tar.gz: d3cfc16e8436ff73cfc0c01deb2e5f78574f202b8160b2dca64288980f1ea0c75699176150c87acaf24010cdedaddfa7f98871dadacad5fa2f16293ecdfe3e7c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
## Next
|
2
2
|
|
3
|
+
## v0.12.0
|
4
|
+
|
5
|
+
This release adds a new `#render` method that can be used in any ERB files being
|
6
|
+
built into HTML documents. It matches the functionality of Liquid's builtiin
|
7
|
+
`render` functionality. So:
|
8
|
+
|
9
|
+
{% render "my_partial.html.liquid" with local_variable: "some-value" %}
|
10
|
+
|
11
|
+
is equivalent to:
|
12
|
+
|
13
|
+
<%= render "my_partial.html.erb", local_variable: "some-value" %>
|
14
|
+
|
3
15
|
## v0.11.0
|
4
16
|
|
5
17
|
This release adds new functionality to our URI strategies, adding
|
@@ -36,7 +48,6 @@ trash.
|
|
36
48
|
The summary is meant to be ideal for things like `<meta>` description tags,
|
37
49
|
which should only contain plain text.
|
38
50
|
|
39
|
-
|
40
51
|
## v0.10.0
|
41
52
|
|
42
53
|
This release lets all layout files (either Liquid or ERB files) provide a
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lifer (0.
|
4
|
+
lifer (0.12.0)
|
5
5
|
i18n (< 2)
|
6
6
|
kramdown (~> 2.4)
|
7
7
|
liquid (~> 5.6, < 6)
|
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
specs:
|
17
17
|
addressable (2.8.7)
|
18
18
|
public_suffix (>= 2.0.2, < 7.0)
|
19
|
-
bigdecimal (3.
|
19
|
+
bigdecimal (3.2.2)
|
20
20
|
bump (0.10.0)
|
21
21
|
capybara (3.40.0)
|
22
22
|
addressable
|
@@ -44,7 +44,7 @@ GEM
|
|
44
44
|
kramdown (2.5.1)
|
45
45
|
rexml (>= 3.3.9)
|
46
46
|
language_server-protocol (3.17.0.3)
|
47
|
-
liquid (5.8.
|
47
|
+
liquid (5.8.7)
|
48
48
|
bigdecimal
|
49
49
|
strscan (>= 3.1.1)
|
50
50
|
listen (3.9.0)
|
@@ -11,6 +11,8 @@ class Lifer::Builder::HTML
|
|
11
11
|
# </head>
|
12
12
|
#
|
13
13
|
# <body>
|
14
|
+
# <%= partial "_layouts/header.html.erb" %>
|
15
|
+
#
|
14
16
|
# <h1><%= my_collection.name %></h1>
|
15
17
|
#
|
16
18
|
# <% my_collection.entries.each do |entry| %>
|
@@ -20,22 +22,31 @@ class Lifer::Builder::HTML
|
|
20
22
|
# <a href="<%= entry.permalink %>">Read more</a>
|
21
23
|
# </section>
|
22
24
|
# <% end %>
|
25
|
+
#
|
26
|
+
# <%= partial "_layouts/footer.html.erb" %>
|
23
27
|
# </body>
|
24
28
|
# </html>
|
25
29
|
#
|
26
30
|
class FromERB < FromAny
|
27
31
|
# Reads the entry as ERB, given our renderer context (see the documentation
|
28
|
-
# for `#build_binding_context`) and
|
32
|
+
# for `#build_binding_context`) and builds the production-ready entry.
|
29
33
|
#
|
30
|
-
# @return [String] The
|
31
|
-
def
|
34
|
+
# @return [String] The resulting HTML entry.
|
35
|
+
def build
|
32
36
|
document = ERB.new(layout_file_contents).result context
|
33
37
|
|
34
38
|
return document unless (relative_layout_path = frontmatter[:layout])
|
35
39
|
|
36
40
|
document_binding = binding.tap { |binding|
|
41
|
+
context.local_variables.each do |variable|
|
42
|
+
next if variable == :content
|
43
|
+
|
44
|
+
binding.local_variable_set variable,
|
45
|
+
context.local_variable_get(variable)
|
46
|
+
end
|
37
47
|
binding.local_variable_set :content, document
|
38
48
|
}
|
49
|
+
|
39
50
|
layout_path = "%s/%s" % [Lifer.root, relative_layout_path]
|
40
51
|
ERB.new(File.read layout_path).result(document_binding)
|
41
52
|
end
|
@@ -95,6 +106,11 @@ class Lifer::Builder::HTML
|
|
95
106
|
binding.local_variable_set :tags, tags
|
96
107
|
binding.local_variable_set :content,
|
97
108
|
ERB.new(entry.to_html).result(binding)
|
109
|
+
|
110
|
+
define_singleton_method :render,
|
111
|
+
-> (relative_path_to_template, locals = {}) {
|
112
|
+
partial_render_method relative_path_to_template, locals
|
113
|
+
}
|
98
114
|
}
|
99
115
|
end
|
100
116
|
|
@@ -105,5 +121,38 @@ class Lifer::Builder::HTML
|
|
105
121
|
def tag_context_class
|
106
122
|
@tag_context_class ||= Class.new(Array) do end
|
107
123
|
end
|
124
|
+
|
125
|
+
# @private
|
126
|
+
# If the end user should want to render a partial from an entry or a layout
|
127
|
+
# file, this method provides the functionality for the `#partial` method
|
128
|
+
# provided to the ERB template context, complete with all of the information
|
129
|
+
# one might want want about the entry, project collections, and so on, that's
|
130
|
+
# available from entry and layout templates.
|
131
|
+
#
|
132
|
+
# @example Usage
|
133
|
+
# <%= partial "_layouts/my_partial.html.erb", id: "123" %>
|
134
|
+
# @param relative_path_to_template [String] The path, from the Lifer root,
|
135
|
+
# to the partial layout file.
|
136
|
+
# @param locals [Hash] Additional data that should be passed along for
|
137
|
+
# rendering the partial.
|
138
|
+
# @return [String] The rendered partial document.
|
139
|
+
def partial_render_method(relative_path_to_template, locals)
|
140
|
+
template_path = File.join(Lifer.root, relative_path_to_template)
|
141
|
+
|
142
|
+
partial_binding = binding.tap { |binding|
|
143
|
+
context.local_variables.each do |variable|
|
144
|
+
next if variable == :content
|
145
|
+
|
146
|
+
binding.local_variable_set variable,
|
147
|
+
context.local_variable_get(variable)
|
148
|
+
end
|
149
|
+
|
150
|
+
locals.each do |key, value|
|
151
|
+
binding.local_variable_set key.to_sym, value
|
152
|
+
end
|
153
|
+
}
|
154
|
+
|
155
|
+
ERB.new(File.read template_path).result(partial_binding)
|
156
|
+
end
|
108
157
|
end
|
109
158
|
end
|
@@ -28,11 +28,11 @@ class Lifer::Builder::HTML
|
|
28
28
|
require_relative "from_liquid/filters"
|
29
29
|
require_relative "from_liquid/liquid_env"
|
30
30
|
|
31
|
-
# Reads the entry
|
32
|
-
#
|
31
|
+
# Reads the Liquid entry, given our document context, and builds an HTML
|
32
|
+
# document.
|
33
33
|
#
|
34
|
-
# @return [String] The
|
35
|
-
def
|
34
|
+
# @return [String] The resulting HTML entry.
|
35
|
+
def build
|
36
36
|
document_context = context.merge!(
|
37
37
|
"content" => Liquid::Template
|
38
38
|
.parse(entry.to_html, **parse_options)
|
data/lib/lifer/builder/html.rb
CHANGED
@@ -7,9 +7,22 @@ require "fileutils"
|
|
7
7
|
# ERB[1] or Liquid[2] template files. The layout file yields entry contents
|
8
8
|
# via a `content` call that is parsed by ERB or Liquid.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
10
|
+
# It is normal to have templates that render other templates. So normal, in
|
11
|
+
# fact, that Liquid provides a built-in `render` function that allows us to render
|
12
|
+
# partials from other Liquid files:
|
13
|
+
#
|
14
|
+
# {% render "path/to/my/partial.html.liquid" with local_variable: "value" %}
|
15
|
+
#
|
16
|
+
# And we've ensured a similar `render` function exists for our ERB HTML builder:
|
17
|
+
#
|
18
|
+
# <%= render "path/to/my/partial.html.erb", local_variable: "value" %>
|
19
|
+
#
|
20
|
+
# The entry being built will include contextual data about the current project,
|
21
|
+
# so that the user can build out normal website features like navigation links,
|
22
|
+
# indexes, and so on. Note that with the current Liquid implementation, you may
|
23
|
+
# need to explicitly pass context from layouts to the partials that require it via
|
24
|
+
# `with`. Meanwhile, the ERB implementation provides a bunch of context globally.
|
25
|
+
# Context includes:
|
13
26
|
#
|
14
27
|
# - `my_collection_name`: Or, any collection by name.
|
15
28
|
#
|
data/lib/lifer/version.rb
CHANGED
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.
|
4
|
+
version: 0.12.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: 2025-
|
11
|
+
date: 2025-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -210,8 +210,8 @@ licenses:
|
|
210
210
|
- MIT
|
211
211
|
metadata:
|
212
212
|
allowed_push_host: https://rubygems.org
|
213
|
-
homepage_uri: https://github.com/benjaminwil/lifer/blob/v0.
|
214
|
-
source_code_uri: https://github.com/benjaminwil/lifer/tree/v0.
|
213
|
+
homepage_uri: https://github.com/benjaminwil/lifer/blob/v0.12.0/README.md
|
214
|
+
source_code_uri: https://github.com/benjaminwil/lifer/tree/v0.12.0
|
215
215
|
changelog_uri: https://github.com/benjaminwil/lifer/blob/main/CHANGELOG.md
|
216
216
|
post_install_message:
|
217
217
|
rdoc_options: []
|