serbea 0.11.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39a8f3905355c95bbf6cbfd93de278f06d12c0c653df17c4b008e80f4b076d80
4
- data.tar.gz: cc1c29fb0d3e4555177f0c34c22e2e1b21a525c0e7b28253699ca8f1b4175c4d
3
+ metadata.gz: a06fc22c4a790174a7d774b39eb7332bef7c78c328ed4582a77dc1fd2d79a968
4
+ data.tar.gz: e94abb8855965947238b8c3c32ce953d2ad13208425fba92c02ac97f76f70b81
5
5
  SHA512:
6
- metadata.gz: d63c852a2d6dee0ed422086d5fa4fec79bfc7807c6448b33d98d5ab8f8c344388fdc192f611eada6c8fabf22af53dd2f9642805591bbe448be3d505492d9fcc7
7
- data.tar.gz: e8b31b1791ec606bc712ed7663c5bb590631990738a941460d2f27c6aa5bfa5b1328561c7f346341a684fc45907a369e89c31c55f25ceed790a8115396ef9740
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
 
@@ -3,9 +3,7 @@ require "bridgetown-core"
3
3
 
4
4
  module Bridgetown
5
5
  class SerbeaView < ERBView
6
- alias_method :_erb_capture, :capture
7
6
  include Serbea::Helpers
8
- alias_method :capture, :_erb_capture
9
7
 
10
8
  def partial(partial_name, options = {}, &block)
11
9
  options.merge!(options[:locals]) if options[:locals]
@@ -10,9 +10,10 @@ module Serbea
10
10
  previous_buffer_state = @_erbout
11
11
  @_erbout = Serbea::OutputBuffer.new
12
12
  result = yield(*args)
13
+ result = @_erbout.presence || result
13
14
  @_erbout = previous_buffer_state
14
15
 
15
- result&.html_safe
16
+ Serbea::OutputBuffer === result ? result.html_safe : result
16
17
  end
17
18
 
18
19
  def pipeline(context, value)
@@ -20,17 +21,20 @@ module Serbea
20
21
  end
21
22
 
22
23
  def helper(name, &helper_block)
23
- self.class.define_method(name) do |*args, &block|
24
- previous_buffer_state = @_erbout
25
- @_erbout = Serbea::OutputBuffer.new
26
- result = helper_block.call(*args, &block)
27
- @_erbout = previous_buffer_state
28
-
29
- result.is_a?(String) ? result.html_safe : result
24
+ self.class.define_method(name) do |*args, **kwargs, &block|
25
+ capture { helper_block.call(*args, **kwargs, &block) }
30
26
  end
31
27
  end
32
28
  alias_method :macro, :helper
33
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
+
34
38
  def h(input)
35
39
  ERB::Util.h(input.to_s)
36
40
  end
@@ -3,6 +3,11 @@ require "active_support/core_ext/object/blank"
3
3
 
4
4
  module Serbea
5
5
  class Pipeline
6
+ # Exec the pipes!
7
+ # @param template [String]
8
+ # @param locals [Hash]
9
+ # @param include_helpers [Module]
10
+ # @param kwargs [Hash]
6
11
  def self.exec(template, locals = {}, include_helpers: nil, **kwargs)
7
12
  anon = Class.new do
8
13
  include Serbea::Helpers
@@ -24,9 +29,12 @@ module Serbea
24
29
  pipeline_obj.output
25
30
  end
26
31
 
32
+ # @param processor [Proc]
27
33
  def self.output_processor=(processor)
28
34
  @output_processor = processor
29
35
  end
36
+
37
+ # @return [Proc]
30
38
  def self.output_processor
31
39
  @output_processor ||= lambda do |input|
32
40
  (!input.html_safe? && self.autoescape) ? ERB::Util.h(input) : input.html_safe
@@ -42,9 +42,10 @@ end
42
42
  Serbea::TemplateEngine.directive :form, ->(code, buffer) do
43
43
  model_name, space, params = code.lstrip.partition(%r(\s)m)
44
44
  model_name.chomp!(",")
45
+ model_name = "#{model_name}," unless params.lstrip.start_with?("do", "{")
45
46
 
46
47
  buffer << "{%= form_with model: "
47
- buffer << model_name << ", " << params
48
+ buffer << model_name << " #{params}"
48
49
  buffer << " %}"
49
50
  end
50
51
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Serbea
2
- VERSION = "0.11.1"
2
+ VERSION = "0.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serbea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: '0.12'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-20 00:00:00.000000000 Z
11
+ date: 2021-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport