serbea 0.11.5 → 0.12
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/docs/src/index.md +12 -0
- data/lib/serbea/helpers.rb +10 -7
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a06fc22c4a790174a7d774b39eb7332bef7c78c328ed4582a77dc1fd2d79a968
|
4
|
+
data.tar.gz: e94abb8855965947238b8c3c32ce953d2ad13208425fba92c02ac97f76f70b81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb47116dbb72fd826be07dd8e6294b0f32536434b7012d4541c14929788cbc4ac635567a7579b254002645e8db9dc492b806ba6d040ff76043faa4e851833ea9
|
7
|
+
data.tar.gz: 436c2f51d6da3d047016de80dce01496fa4648d10a427512ddc4a5652bce63bc126e03d4902298f1b2f5b500910d04e80387cad213611d00fb46c4ddc0de0de3
|
data/docs/src/index.md
CHANGED
@@ -48,7 +48,19 @@ layout: home
|
|
48
48
|
* Built-in frontmatter support. Now you can access the variables written into a top YAML block within your templates. In any Rails view, including layouts, you'll have access to the `@frontmatter` ivar which is a merged `HashWithDotAccess::Hash` with data from any part of the view tree (partials, pages, layout).
|
49
49
|
|
50
50
|
For example, you could put `<title>{{ @frontmatter.title }}</title>` in your head partial, and then each page could define `title` frontmatter individually. You can even use Ruby string interpolation within the YAML so titles and other metadata can come from `t` language helpers.
|
51
|
+
* Define macros/helpers which can be imported and used within Serbea templates.
|
51
52
|
|
53
|
+
```serb
|
54
|
+
<!-- _macros.serb -->
|
55
|
+
{% macro :greet do |name:| %}
|
56
|
+
{{ name }}, my old friend!
|
57
|
+
{% end %}
|
58
|
+
|
59
|
+
<!-- tmpl.serb -->
|
60
|
+
{% import "macros" %}
|
61
|
+
|
62
|
+
Hello {{ greet(name: "darkness") }}
|
63
|
+
```
|
52
64
|
|
53
65
|
{% endraw %}
|
54
66
|
|
data/lib/serbea/helpers.rb
CHANGED
@@ -13,7 +13,7 @@ module Serbea
|
|
13
13
|
result = @_erbout.presence || result
|
14
14
|
@_erbout = previous_buffer_state
|
15
15
|
|
16
|
-
|
16
|
+
Serbea::OutputBuffer === result ? result.html_safe : result
|
17
17
|
end
|
18
18
|
|
19
19
|
def pipeline(context, value)
|
@@ -22,16 +22,19 @@ module Serbea
|
|
22
22
|
|
23
23
|
def helper(name, &helper_block)
|
24
24
|
self.class.define_method(name) do |*args, **kwargs, &block|
|
25
|
-
|
26
|
-
@_erbout = Serbea::OutputBuffer.new
|
27
|
-
result = helper_block.call(*args, **kwargs, &block)
|
28
|
-
@_erbout = previous_buffer_state
|
29
|
-
|
30
|
-
result.is_a?(String) ? result.html_safe : result
|
25
|
+
capture { helper_block.call(*args, **kwargs, &block) }
|
31
26
|
end
|
32
27
|
end
|
33
28
|
alias_method :macro, :helper
|
34
29
|
|
30
|
+
def import(*args, **kwargs, &block)
|
31
|
+
helper_names = %i(partial render)
|
32
|
+
available_helper = helper_names.find { |meth| respond_to?(meth) }
|
33
|
+
raise "Serbea error: no `render' helper is available in #{self.class}" unless available_helper
|
34
|
+
available_helper == :partial ? partial(*args, **kwargs, &block) : render(*args, **kwargs, &block)
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
35
38
|
def h(input)
|
36
39
|
ERB::Util.h(input.to_s)
|
37
40
|
end
|
data/lib/version.rb
CHANGED