serbea 0.11.5 → 0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1b5a4aac5a9230d11e68a3b58c75363f644fef35b9328ac35c7d9cc4d9995d9
4
- data.tar.gz: 49c2eaf825d3547cc13815071dce83b35bb7c7f31db72f3523e5c96bb13eacc9
3
+ metadata.gz: a06fc22c4a790174a7d774b39eb7332bef7c78c328ed4582a77dc1fd2d79a968
4
+ data.tar.gz: e94abb8855965947238b8c3c32ce953d2ad13208425fba92c02ac97f76f70b81
5
5
  SHA512:
6
- metadata.gz: 984de9e83b3daba448203b3a7cc834bbe4bd5d6262311293a6e507b9416be73ea442a33127fef9706dbda07f19a63c6b45625fcdd4532eef9753dd0118885898
7
- data.tar.gz: 324f24744d74d315c7e950d230dd5cfd901b70648e236e75b11c60c504695c79ee9c9ba637d56544d3c8c4820ac700259cbd7c57ab2cd0c94641a35086df042f
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
 
@@ -13,7 +13,7 @@ module Serbea
13
13
  result = @_erbout.presence || result
14
14
  @_erbout = previous_buffer_state
15
15
 
16
- safe(result)
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
- previous_buffer_state = @_erbout
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
@@ -1,3 +1,3 @@
1
1
  module Serbea
2
- VERSION = "0.11.5"
2
+ VERSION = "0.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serbea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.5
4
+ version: '0.12'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team