temple 0.9.1 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -1
- data/CHANGES +12 -0
- data/Gemfile +0 -1
- data/lib/temple/engine.rb +1 -0
- data/lib/temple/erb/engine.rb +3 -0
- data/lib/temple/erb/parser.rb +1 -0
- data/lib/temple/erb/template.rb +1 -0
- data/lib/temple/erb/trimming.rb +1 -0
- data/lib/temple/exceptions.rb +1 -0
- data/lib/temple/filter.rb +1 -0
- data/lib/temple/filters/ambles.rb +1 -0
- data/lib/temple/filters/code_merger.rb +1 -0
- data/lib/temple/filters/control_flow.rb +1 -0
- data/lib/temple/filters/dynamic_inliner.rb +2 -1
- data/lib/temple/filters/encoding.rb +1 -0
- data/lib/temple/filters/eraser.rb +1 -0
- data/lib/temple/filters/escapable.rb +1 -0
- data/lib/temple/filters/multi_flattener.rb +1 -0
- data/lib/temple/filters/remove_bom.rb +1 -0
- data/lib/temple/filters/static_analyzer.rb +1 -0
- data/lib/temple/filters/static_merger.rb +1 -0
- data/lib/temple/filters/string_splitter.rb +2 -1
- data/lib/temple/filters/validator.rb +1 -0
- data/lib/temple/generator.rb +6 -11
- data/lib/temple/generators/array.rb +1 -0
- data/lib/temple/generators/array_buffer.rb +1 -0
- data/lib/temple/generators/erb.rb +1 -0
- data/lib/temple/generators/rails_output_buffer.rb +7 -3
- data/lib/temple/generators/string_buffer.rb +2 -1
- data/lib/temple/grammar.rb +1 -0
- data/lib/temple/html/attribute_merger.rb +1 -0
- data/lib/temple/html/attribute_remover.rb +1 -0
- data/lib/temple/html/attribute_sorter.rb +1 -0
- data/lib/temple/html/dispatcher.rb +1 -0
- data/lib/temple/html/fast.rb +1 -0
- data/lib/temple/html/filter.rb +1 -0
- data/lib/temple/html/pretty.rb +1 -0
- data/lib/temple/html/safe.rb +1 -0
- data/lib/temple/map.rb +1 -0
- data/lib/temple/mixins/dispatcher.rb +1 -0
- data/lib/temple/mixins/engine_dsl.rb +1 -0
- data/lib/temple/mixins/grammar_dsl.rb +2 -1
- data/lib/temple/mixins/options.rb +1 -0
- data/lib/temple/mixins/template.rb +1 -0
- data/lib/temple/parser.rb +1 -0
- data/lib/temple/static_analyzer.rb +1 -0
- data/lib/temple/templates/rails.rb +3 -2
- data/lib/temple/templates/tilt.rb +1 -0
- data/lib/temple/templates.rb +1 -0
- data/lib/temple/utils.rb +3 -1
- data/lib/temple/version.rb +2 -1
- data/lib/temple.rb +1 -0
- data/spec/filters/string_splitter_spec.rb +1 -1
- data/spec/generator_spec.rb +22 -10
- data/temple.gemspec +0 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '068887942852fa7b2d423e0e182c2e3f181548615ffc2a7c7e920a0516fdaba7'
|
4
|
+
data.tar.gz: b71e5e33ac4b1fdac83bad09a0cd097063ae0e1128c9d1fcecc6b05031e0d7bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5b0fe64b446f461b6c9e8a2dfc7f2c51e0d6d25308ba8499c4b50468636388b1dd2b2cd4a1f5bc03d856475a75dd20bf67bc2302ae3b5d44fb51dab4260e91c
|
7
|
+
data.tar.gz: c8d81dde3332684457f7452ab4a086fcddcceb47996267d0dfed28035c09e0fabbb5b360cdc4e3f0c0a4116bd48501b614dae4cd840b38ab84399253d162cd70
|
data/.github/workflows/test.yml
CHANGED
data/CHANGES
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
+
0.10.1
|
2
|
+
|
3
|
+
* Use specified :capture_generator for nested captures (#112, #144)
|
4
|
+
* Compatibility with frozen string literals
|
5
|
+
|
6
|
+
0.10.0
|
7
|
+
|
8
|
+
* Regression: Revert changes to :capture_generator since 0.8.2 (#112, #113, #137)
|
9
|
+
* Regression: Ensure that output buffer is not reused for capturing in Rails (#135)
|
10
|
+
* Drop support for Rails 4.x
|
11
|
+
|
1
12
|
0.9.1
|
2
13
|
|
3
14
|
* Fix Slim's error in AttributeMerger due to 0.9.0's :capture_generator (#137)
|
15
|
+
* Use specified :capture_generator for nested captures (#112)
|
4
16
|
* Fix Temple::ERB::Engine's <%= to not escape and <%== to escape expressions
|
5
17
|
|
6
18
|
0.9.0
|
data/Gemfile
CHANGED
data/lib/temple/engine.rb
CHANGED
data/lib/temple/erb/engine.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module ERB
|
3
4
|
# Example ERB engine implementation
|
@@ -7,6 +8,8 @@ module Temple
|
|
7
8
|
use Temple::ERB::Parser
|
8
9
|
use Temple::ERB::Trimming
|
9
10
|
filter :Escapable
|
11
|
+
filter :StringSplitter
|
12
|
+
filter :StaticAnalyzer
|
10
13
|
filter :MultiFlattener
|
11
14
|
filter :StaticMerger
|
12
15
|
generator :ArrayBuffer
|
data/lib/temple/erb/parser.rb
CHANGED
data/lib/temple/erb/template.rb
CHANGED
data/lib/temple/erb/trimming.rb
CHANGED
data/lib/temple/exceptions.rb
CHANGED
data/lib/temple/filter.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module Filters
|
3
4
|
# Inlines several static/dynamic into a single dynamic.
|
@@ -36,7 +37,7 @@ module Temple
|
|
36
37
|
# another one, we add both then.
|
37
38
|
state = :single
|
38
39
|
prev = [exp]
|
39
|
-
curr = [:dynamic, '"']
|
40
|
+
curr = [:dynamic, '"'.dup]
|
40
41
|
when :single
|
41
42
|
# Yes! We found another one. Add the current dynamic to the result.
|
42
43
|
state = :several
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
begin
|
2
3
|
require 'ripper'
|
3
4
|
rescue LoadError
|
@@ -7,7 +8,7 @@ module Temple
|
|
7
8
|
module Filters
|
8
9
|
# Compile [:dynamic, "foo#{bar}"] to [:multi, [:static, 'foo'], [:dynamic, 'bar']]
|
9
10
|
class StringSplitter < Filter
|
10
|
-
if defined?(Ripper) &&
|
11
|
+
if defined?(Ripper) && Ripper.respond_to?(:lex)
|
11
12
|
class << self
|
12
13
|
# `code` param must be valid string literal
|
13
14
|
def compile(code)
|
data/lib/temple/generator.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
# Abstract generator base class
|
3
4
|
# Generators should inherit this class and
|
@@ -10,9 +11,9 @@ module Temple
|
|
10
11
|
include Mixins::Options
|
11
12
|
|
12
13
|
define_options :save_buffer,
|
13
|
-
capture_generator:
|
14
|
+
capture_generator: 'StringBuffer',
|
14
15
|
buffer: '_buf',
|
15
|
-
freeze_static:
|
16
|
+
freeze_static: true
|
16
17
|
|
17
18
|
def call(exp)
|
18
19
|
[preamble, compile(exp), postamble].flatten.compact.join('; ')
|
@@ -76,15 +77,9 @@ module Temple
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def capture_generator
|
79
|
-
@capture_generator ||=
|
80
|
-
|
81
|
-
|
82
|
-
self.class
|
83
|
-
when Class
|
84
|
-
options[:capture_generator]
|
85
|
-
else
|
86
|
-
Generators.const_get(options[:capture_generator])
|
87
|
-
end
|
80
|
+
@capture_generator ||= Class === options[:capture_generator] ?
|
81
|
+
options[:capture_generator] :
|
82
|
+
Generators.const_get(options[:capture_generator])
|
88
83
|
end
|
89
84
|
|
90
85
|
def concat(str)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module Generators
|
3
4
|
# Implements a rails output buffer.
|
@@ -9,10 +10,9 @@ module Temple
|
|
9
10
|
#
|
10
11
|
# @api public
|
11
12
|
class RailsOutputBuffer < StringBuffer
|
12
|
-
define_options :streaming,
|
13
|
+
define_options :streaming, # ignored
|
13
14
|
buffer_class: 'ActionView::OutputBuffer',
|
14
15
|
buffer: '@output_buffer',
|
15
|
-
# output_buffer is needed for Rails 3.1 Streaming support
|
16
16
|
capture_generator: RailsOutputBuffer
|
17
17
|
|
18
18
|
def call(exp)
|
@@ -20,7 +20,11 @@ module Temple
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def create_buffer
|
23
|
-
|
23
|
+
if buffer == '@output_buffer'
|
24
|
+
"#{buffer} = output_buffer || #{options[:buffer_class]}.new"
|
25
|
+
else
|
26
|
+
"#{buffer} = #{options[:buffer_class]}.new"
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
def concat(str)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module Generators
|
3
4
|
# Implements a string buffer.
|
@@ -10,7 +11,7 @@ module Temple
|
|
10
11
|
# @api public
|
11
12
|
class StringBuffer < ArrayBuffer
|
12
13
|
def create_buffer
|
13
|
-
"#{buffer} = ''"
|
14
|
+
"#{buffer} = ''.dup"
|
14
15
|
end
|
15
16
|
|
16
17
|
def return_buffer
|
data/lib/temple/grammar.rb
CHANGED
data/lib/temple/html/fast.rb
CHANGED
data/lib/temple/html/filter.rb
CHANGED
data/lib/temple/html/pretty.rb
CHANGED
data/lib/temple/html/safe.rb
CHANGED
data/lib/temple/map.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module Mixins
|
3
4
|
# @api private
|
@@ -67,7 +68,7 @@ module Temple
|
|
67
68
|
unmatched.reverse_each do |u|
|
68
69
|
entry = u if u.flatten.size < entry.flatten.size
|
69
70
|
end
|
70
|
-
raise(InvalidExpression, PP.pp(entry.last, "#{@grammar}::#{entry.first} did not match\n"))
|
71
|
+
raise(InvalidExpression, PP.pp(entry.last, "#{@grammar}::#{entry.first} did not match\n".dup))
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
data/lib/temple/parser.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Temple
|
2
3
|
module Templates
|
3
4
|
class Rails
|
@@ -18,8 +19,8 @@ module Temple
|
|
18
19
|
|
19
20
|
def self.register_as(*names)
|
20
21
|
raise 'Rails is not loaded - Temple::Templates::Rails cannot be used' unless defined?(::ActionView)
|
21
|
-
if ::ActiveSupport::VERSION::MAJOR <
|
22
|
-
raise "Temple supports only Rails
|
22
|
+
if ::ActiveSupport::VERSION::MAJOR < 5
|
23
|
+
raise "Temple supports only Rails 5 and greater, your Rails version is #{::ActiveSupport::VERSION::STRING}"
|
23
24
|
end
|
24
25
|
names.each do |name|
|
25
26
|
::ActionView::Template.register_template_handler name.to_sym, new
|
data/lib/temple/templates.rb
CHANGED
data/lib/temple/utils.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
begin
|
2
3
|
require 'cgi/escape'
|
3
4
|
rescue LoadError
|
@@ -14,7 +15,8 @@ module Temple
|
|
14
15
|
# @param html [String] The string to escape
|
15
16
|
# @return [String] The escaped string
|
16
17
|
def escape_html_safe(html)
|
17
|
-
|
18
|
+
s = html.to_s
|
19
|
+
s.html_safe? || html.html_safe? ? s : escape_html(s)
|
18
20
|
end
|
19
21
|
|
20
22
|
if defined?(CGI.escapeHTML)
|
data/lib/temple/version.rb
CHANGED
data/lib/temple.rb
CHANGED
data/spec/generator_spec.rb
CHANGED
@@ -22,6 +22,12 @@ class SimpleGenerator < Temple::Generator
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
class SimpleCaptureGenerator < SimpleGenerator
|
26
|
+
def preamble
|
27
|
+
"#{buffer} = CAPTURE_BUFFER"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
25
31
|
describe Temple::Generator do
|
26
32
|
it 'should compile simple expressions' do
|
27
33
|
gen = SimpleGenerator.new
|
@@ -62,13 +68,19 @@ describe Temple::Generator do
|
|
62
68
|
'foo << (D:dynamic); C:code; foo; VAR << (S:after); VAR')
|
63
69
|
end
|
64
70
|
|
65
|
-
it 'should compile nested
|
66
|
-
gen = SimpleGenerator.new(buffer: "VAR", capture_generator:
|
67
|
-
expect(gen.call(
|
68
|
-
[:capture, "
|
71
|
+
it 'should compile nested captures with the same capture_generator' do
|
72
|
+
gen = SimpleGenerator.new(buffer: "VAR", capture_generator: SimpleCaptureGenerator)
|
73
|
+
expect(gen.call(
|
74
|
+
[:capture, "foo", [:multi,
|
69
75
|
[:static, "a"],
|
70
|
-
[:
|
71
|
-
|
76
|
+
[:capture, "bar", [:multi,
|
77
|
+
[:static, "b"],
|
78
|
+
[:capture, "baz", [:multi,
|
79
|
+
[:static, "c"],
|
80
|
+
]]
|
81
|
+
]]
|
82
|
+
]]
|
83
|
+
)).to eq "VAR = BUFFER; foo = CAPTURE_BUFFER; foo << (S:a); bar = CAPTURE_BUFFER; bar << (S:b); baz = CAPTURE_BUFFER; baz << (S:c); baz; bar; foo; VAR"
|
72
84
|
end
|
73
85
|
|
74
86
|
it 'should compile newlines' do
|
@@ -124,16 +136,16 @@ describe Temple::Generators::StringBuffer do
|
|
124
136
|
gen = Temple::Generators::StringBuffer.new(freeze_static: false)
|
125
137
|
expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
|
126
138
|
expect(gen.call([:dynamic, 'test'])).to eq('_buf = (test).to_s')
|
127
|
-
expect(gen.call([:code, 'test'])).to eq('_buf = \'\'; test; _buf')
|
139
|
+
expect(gen.call([:code, 'test'])).to eq('_buf = \'\'.dup; test; _buf')
|
128
140
|
|
129
|
-
expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = \'\'; _buf << ("a"); _buf << ("b"); _buf')
|
130
|
-
expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = \'\'; _buf << ("a"); _buf << ((b).to_s); _buf')
|
141
|
+
expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = \'\'.dup; _buf << ("a"); _buf << ("b"); _buf')
|
142
|
+
expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = \'\'.dup; _buf << ("a"); _buf << ((b).to_s); _buf')
|
131
143
|
end
|
132
144
|
|
133
145
|
it 'should freeze static' do
|
134
146
|
gen = Temple::Generators::StringBuffer.new(freeze_static: true)
|
135
147
|
expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
|
136
|
-
expect(gen.call([:multi, [:dynamic, '1'], [:static, 'test']])).to eq('_buf = \'\'; _buf << ((1).to_s); _buf << ("test".freeze); _buf')
|
148
|
+
expect(gen.call([:multi, [:dynamic, '1'], [:static, 'test']])).to eq('_buf = \'\'.dup; _buf << ((1).to_s); _buf << ("test".freeze); _buf')
|
137
149
|
end
|
138
150
|
end
|
139
151
|
|
data/temple.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: temple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Holm
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tilt
|
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
178
|
- !ruby/object:Gem::Version
|
179
179
|
version: '0'
|
180
180
|
requirements: []
|
181
|
-
rubygems_version: 3.
|
181
|
+
rubygems_version: 3.2.5
|
182
182
|
signing_key:
|
183
183
|
specification_version: 4
|
184
184
|
summary: Template compilation framework in Ruby
|