tilt 2.8.0 → 2.9.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tilt/herb.rb +110 -0
  3. data/lib/tilt.rb +4 -3
  4. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4277574fbcafae6077fd4e64a6528e3117cae4aa653a471ab9179942a1440a3a
4
- data.tar.gz: 0ebc6d611b50d8ef82eb91b6b09a5184788909716c4f6961dac770537b02aae6
3
+ metadata.gz: 07376d5da37cfc37ba1364a962859139ab42e2c6453aea4bd5610c2daccee019
4
+ data.tar.gz: dc64be5c7fbf26c8f6def8e40c143a61de7e46ed69157d0b0a0c1a558b9e4d93
5
5
  SHA512:
6
- metadata.gz: 0c1b60402b38beff691e96630126af11e12a596df74923718e5ef99e66b2961218456d2dc0e7b87af1d2256603cee8cc0dba6823c8e39613fd790ebe39bd9b58
7
- data.tar.gz: a55b63755285f279625ccc296fd637e22f3931c46549712ec8105c312e2bf537fac38882492691d6c1ad788f76e418ded62cbd6e6b2e54e3f3819cfc2f61b045
6
+ metadata.gz: 20bc55f1b6cdceb99068e2a40ac0df35006b6f61c27a66f31606ee79e32df7431bef7e2d37ca6ecef5cc30ef131f7f19f340258d12a1836ce4aee2a1ad0a4b23
7
+ data.tar.gz: 409ef4a5ba49ec95425d810987b892d694aa3794ce937256c7673caea67dc9ef93f64fb1b5b399de0a0ada44d13424d305d63f3e9b96a6f346739f8a7491c2b3
data/lib/tilt/herb.rb ADDED
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ # = Herb (<tt>herb</tt>, <tt>html.erb</tt>)
4
+ #
5
+ # {Herb}[https://herb-tools.dev] is an HTML-aware ERB implementation, which parses the
6
+ # HTML in the template in addition to the embedded Ruby.
7
+ #
8
+ # Herb's engine is API compatible with the Erubi engine, so all the documentation of
9
+ # {Erubi}[rdoc-ref:lib/tilt/erubi.rb] applies in addition to the following:
10
+ #
11
+ # === Differences from Erubi
12
+ #
13
+ # Herb parses the HTML in the template, and raises <tt>Herb::Engine::CompilationError</tt>
14
+ # when creating the template if the HTML is invalid (such as unclosed or mismatched tags),
15
+ # or if the embedded Ruby has invalid syntax. Erubi inspects neither the HTML nor the Ruby;
16
+ # with Erubi, invalid Ruby syntax instead raises a SyntaxError when Tilt compiles the
17
+ # template, which by default does not happen until the template is first rendered.
18
+ #
19
+ # Herb escapes interpolated values based on where they appear in the document, using a
20
+ # separate escape function for attribute values, <tt><script></tt> content, and
21
+ # <tt><style></tt> content. Erubi uses a single escape function everywhere.
22
+ #
23
+ # Herb accepts additional engine options. As with the Erubi engine options, these are
24
+ # passed through to the engine class. See
25
+ # {Herb::Engine}[https://herb-tools.dev/projects/engine] for the full list.
26
+ #
27
+ # === Usage
28
+ #
29
+ # The <tt>Tilt::HerbTemplate</tt> class is registered for all files ending in <tt>.herb</tt> or
30
+ # <tt>.html.erb</tt> by default. Unlike {Erubi}[rdoc-ref:lib/tilt/erubi.rb], it is not
31
+ # registered for <tt>.erb</tt> or <tt>.rhtml</tt>, since that would change which engine is
32
+ # used for existing templates. To use Herb for those as well, use:
33
+ #
34
+ # Tilt.register Tilt::HerbTemplate, 'erb', 'rhtml'
35
+ #
36
+ # __NOTE:__ It's suggested that your program <tt>require 'herb'</tt> at load time when
37
+ # using this template engine within a threaded environment.
38
+ #
39
+ # === Options
40
+ #
41
+ # ==== <tt>:engine_class => Herb::Engine</tt>
42
+ #
43
+ # Allows you to specify a custom engine class to use instead of the
44
+ # default which is <tt>Herb::Engine</tt>.
45
+ #
46
+ # ==== Other
47
+ #
48
+ # Other options are passed to the constructor of the engine class.
49
+ #
50
+ # === See also
51
+ #
52
+ # * {Herb Home}[https://herb-tools.dev]
53
+ # * {Herb::Engine}[https://herb-tools.dev/projects/engine]
54
+ # * {Herb Source}[https://github.com/marcoroth/herb]
55
+ #
56
+ # === Related module
57
+ #
58
+ # * Tilt::HerbTemplate
59
+
60
+ require_relative 'template'
61
+ require 'herb'
62
+ require 'herb/engine'
63
+
64
+ module Tilt
65
+ class HerbTemplate < Template
66
+ def prepare
67
+ @options[:preamble] = false
68
+ @options[:postamble] = false
69
+ @options[:ensure] = true
70
+
71
+ # Unlike Erubi, Herb uses the filename when reporting errors, so pass
72
+ # the file Tilt loaded the template from if the caller did not set one.
73
+ @options[:filename] ||= file
74
+
75
+ engine_class = @options[:engine_class] || Herb::Engine
76
+
77
+ # If :freeze option is given, the intent is to setup frozen string
78
+ # literals in the template. So enable frozen string literals in the
79
+ # code Tilt generates if the :freeze option is given.
80
+ if @freeze_string_literals = !!@options[:freeze]
81
+ # Passing the :freeze option to Herb sets the
82
+ # frozen-string-literal magic comment, which doesn't have an effect
83
+ # with Tilt as Tilt wraps the resulting code. Worse, the magic
84
+ # comment appearing not at the top of the file can cause a warning.
85
+ # So remove the :freeze option before passing to Herb.
86
+ @options.delete(:freeze)
87
+
88
+ # Herb by default appends .freeze to template literals, but that is
89
+ # not necessary and slows down code when Tilt is using frozen string
90
+ # literals, so pass the :freeze_template_literals option to not
91
+ # append .freeze.
92
+ @options[:freeze_template_literals] = false
93
+ end
94
+
95
+ @engine = engine_class.new(@data, @options)
96
+ @outvar = @engine.bufvar
97
+ @src = @engine.src
98
+
99
+ @engine
100
+ end
101
+
102
+ def precompiled_template(locals)
103
+ @src
104
+ end
105
+
106
+ def freeze_string_literals?
107
+ @freeze_string_literals
108
+ end
109
+ end
110
+ end
data/lib/tilt.rb CHANGED
@@ -5,7 +5,7 @@ require_relative 'tilt/template'
5
5
  # Namespace for Tilt. This module is not intended to be included anywhere.
6
6
  module Tilt
7
7
  # Current version.
8
- VERSION = '2.8.0'
8
+ VERSION = '2.9.0'
9
9
 
10
10
  EMPTY_ARRAY = [].freeze
11
11
  private_constant :EMPTY_ARRAY
@@ -146,8 +146,9 @@ module Tilt
146
146
  # Template Implementations ================================================
147
147
 
148
148
  # ERB
149
- register_lazy :ERBTemplate, 'tilt/erb', 'erb', 'rhtml'
150
- register_lazy :ErubiTemplate, 'tilt/erubi', 'erb', 'rhtml', 'erubi'
149
+ register_lazy :ERBTemplate, 'tilt/erb', 'erb', 'rhtml', 'html.erb'
150
+ register_lazy :ErubiTemplate, 'tilt/erubi', 'erb', 'rhtml', 'erubi', 'html.erb'
151
+ register_lazy :HerbTemplate, 'tilt/herb', 'herb', 'html.erb'
151
152
 
152
153
  # Markdown
153
154
  register_lazy :KramdownTemplate, 'tilt/kramdown', 'markdown', 'mkd', 'md'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tilt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
@@ -36,6 +36,7 @@ files:
36
36
  - lib/tilt/erubi.rb
37
37
  - lib/tilt/etanni.rb
38
38
  - lib/tilt/haml.rb
39
+ - lib/tilt/herb.rb
39
40
  - lib/tilt/kramdown.rb
40
41
  - lib/tilt/liquid.rb
41
42
  - lib/tilt/livescript.rb
@@ -87,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
90
  requirements: []
90
- rubygems_version: 4.0.10
91
+ rubygems_version: 4.0.16
91
92
  specification_version: 4
92
93
  summary: Generic interface to multiple Ruby template engines
93
94
  test_files: []