temple 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +2 -1
  3. data/CHANGES +5 -0
  4. data/lib/temple/engine.rb +1 -0
  5. data/lib/temple/erb/engine.rb +1 -0
  6. data/lib/temple/erb/parser.rb +1 -0
  7. data/lib/temple/erb/template.rb +1 -0
  8. data/lib/temple/erb/trimming.rb +1 -0
  9. data/lib/temple/exceptions.rb +1 -0
  10. data/lib/temple/filter.rb +1 -0
  11. data/lib/temple/filters/ambles.rb +1 -0
  12. data/lib/temple/filters/code_merger.rb +1 -0
  13. data/lib/temple/filters/control_flow.rb +1 -0
  14. data/lib/temple/filters/dynamic_inliner.rb +2 -1
  15. data/lib/temple/filters/encoding.rb +1 -0
  16. data/lib/temple/filters/eraser.rb +1 -0
  17. data/lib/temple/filters/escapable.rb +1 -0
  18. data/lib/temple/filters/multi_flattener.rb +1 -0
  19. data/lib/temple/filters/remove_bom.rb +1 -0
  20. data/lib/temple/filters/static_analyzer.rb +1 -0
  21. data/lib/temple/filters/static_merger.rb +1 -0
  22. data/lib/temple/filters/string_splitter.rb +1 -0
  23. data/lib/temple/filters/validator.rb +1 -0
  24. data/lib/temple/generator.rb +2 -1
  25. data/lib/temple/generators/array.rb +1 -0
  26. data/lib/temple/generators/array_buffer.rb +1 -0
  27. data/lib/temple/generators/erb.rb +1 -0
  28. data/lib/temple/generators/rails_output_buffer.rb +1 -0
  29. data/lib/temple/generators/string_buffer.rb +2 -1
  30. data/lib/temple/grammar.rb +1 -0
  31. data/lib/temple/html/attribute_merger.rb +1 -0
  32. data/lib/temple/html/attribute_remover.rb +1 -0
  33. data/lib/temple/html/attribute_sorter.rb +1 -0
  34. data/lib/temple/html/dispatcher.rb +1 -0
  35. data/lib/temple/html/fast.rb +1 -0
  36. data/lib/temple/html/filter.rb +1 -0
  37. data/lib/temple/html/pretty.rb +1 -0
  38. data/lib/temple/html/safe.rb +1 -0
  39. data/lib/temple/map.rb +1 -0
  40. data/lib/temple/mixins/dispatcher.rb +1 -0
  41. data/lib/temple/mixins/engine_dsl.rb +1 -0
  42. data/lib/temple/mixins/grammar_dsl.rb +2 -1
  43. data/lib/temple/mixins/options.rb +1 -0
  44. data/lib/temple/mixins/template.rb +1 -0
  45. data/lib/temple/parser.rb +1 -0
  46. data/lib/temple/static_analyzer.rb +1 -0
  47. data/lib/temple/templates/rails.rb +1 -0
  48. data/lib/temple/templates/tilt.rb +1 -0
  49. data/lib/temple/templates.rb +1 -0
  50. data/lib/temple/utils.rb +1 -0
  51. data/lib/temple/version.rb +2 -1
  52. data/lib/temple.rb +1 -0
  53. data/spec/generator_spec.rb +25 -4
  54. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7475d628203a95d9ec067ac1388f8428cb213f4534a2fd2ed1b9cf0be7d3293
4
- data.tar.gz: d828006ab486aee65e70e8e321022d28191deba994d43c1141dccad2815f41f2
3
+ metadata.gz: '068887942852fa7b2d423e0e182c2e3f181548615ffc2a7c7e920a0516fdaba7'
4
+ data.tar.gz: b71e5e33ac4b1fdac83bad09a0cd097063ae0e1128c9d1fcecc6b05031e0d7bf
5
5
  SHA512:
6
- metadata.gz: d74cc956889989a4d65f6727d7f521cbcbf3d9c2de1a6abda92b4957a7e3992de2b7de6c7634b4dfafe9d4ce1a505f22b8f5af1ef9a217876d6d67f276e04557
7
- data.tar.gz: 1958e441fbab605e06f560db0f4c26e5fecf7c673a12a5aad843a3bd5bb4c0ce77e3c2ea13f46b22d962770898587b7f76bd0ad2b11377898e61924e7bc20c87
6
+ metadata.gz: c5b0fe64b446f461b6c9e8a2dfc7f2c51e0d6d25308ba8499c4b50468636388b1dd2b2cd4a1f5bc03d856475a75dd20bf67bc2302ae3b5d44fb51dab4260e91c
7
+ data.tar.gz: c8d81dde3332684457f7452ab4a086fcddcceb47996267d0dfed28035c09e0fabbb5b360cdc4e3f0c0a4116bd48501b614dae4cd840b38ab84399253d162cd70
@@ -22,10 +22,11 @@ jobs:
22
22
  - '2.7'
23
23
  - '3.0'
24
24
  - '3.1'
25
+ - '3.2'
25
26
  - jruby
26
27
  - truffleruby-head
27
28
  steps:
28
- - uses: actions/checkout@v2
29
+ - uses: actions/checkout@v3
29
30
  - name: Set up Ruby
30
31
  uses: ruby/setup-ruby@v1
31
32
  with:
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ 0.10.1
2
+
3
+ * Use specified :capture_generator for nested captures (#112, #144)
4
+ * Compatibility with frozen string literals
5
+
1
6
  0.10.0
2
7
 
3
8
  * Regression: Revert changes to :capture_generator since 0.8.2 (#112, #113, #137)
data/lib/temple/engine.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  # An engine is simply a chain of compilers (that often includes a parser,
3
4
  # some filters and a generator).
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module ERB
3
4
  # Example ERB engine implementation
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module ERB
3
4
  # Example ERB parser
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  # ERB example implementation
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module ERB
3
4
  # ERB trimming like in erubis
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  # Exception raised if invalid temple expression is found
3
4
  #
data/lib/temple/filter.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  # Temple base filter
3
4
  # @api public
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Filters
3
4
  class Ambles < Filter
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Filters
3
4
  # @api public
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Filters
3
4
  # Control flow filter which processes [:if, condition, yes-exp, no-exp]
@@ -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
  module Temple
2
3
  module Filters
3
4
  # Try to encode input string
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Filters
3
4
  # Erase expressions with a certain type
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Filters
3
4
  # Escape dynamic or static expressions.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Filters
3
4
  # Flattens nested multi expressions
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Filters
3
4
  # Remove BOM from input string
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Filters
3
4
  # Convert [:dynamic, code] to [:static, text] if code is static Ruby expression.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Filters
3
4
  # Merges several statics into a single static. Example:
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  begin
2
3
  require 'ripper'
3
4
  rescue LoadError
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Filters
3
4
  # Validates temple expression with given grammar
@@ -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
@@ -54,7 +55,7 @@ module Temple
54
55
  end
55
56
 
56
57
  def on_capture(name, exp)
57
- capture_generator.new(buffer: name).call(exp)
58
+ capture_generator.new(**options, buffer: name).call(exp)
58
59
  end
59
60
 
60
61
  def on_static(text)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Generators
3
4
  # Implements an array buffer.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Generators
3
4
  # Just like Array, but calls #join on the array.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Generators
3
4
  # Implements an ERB generator.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Generators
3
4
  # Implements a rails output buffer.
@@ -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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  # Temple expression grammar which can be used to validate Temple expressions.
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module HTML
3
4
  # This filter merges html attributes (e.g. used for id and class)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module HTML
3
4
  # This filter removes empty attributes
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module HTML
3
4
  # This filter sorts html attributes.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module HTML
3
4
  # @api private
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module HTML
3
4
  # @api public
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module HTML
3
4
  # @api public
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module HTML
3
4
  # @api public
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module HTML
3
4
  class SafeString < String
data/lib/temple/map.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  # Immutable map class which supports map merging
3
4
  # @api public
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Mixins
3
4
  # @api private
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Mixins
3
4
  # @api private
@@ -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
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Mixins
3
4
  # @api public
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Mixins
3
4
  # @api private
data/lib/temple/parser.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  # Temple base parser
3
4
  # @api public
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  begin
2
3
  require 'ripper'
3
4
  rescue LoadError
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  module Templates
3
4
  class Rails
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'tilt'
2
3
 
3
4
  module Temple
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
3
  # @api public
3
4
  module Templates
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Temple
2
- VERSION = '0.10.0'
3
+ VERSION = '0.10.1'
3
4
  end
data/lib/temple.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'temple/version'
2
3
 
3
4
  module Temple
@@ -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,6 +68,21 @@ describe Temple::Generator do
62
68
  'foo << (D:dynamic); C:code; foo; VAR << (S:after); VAR')
63
69
  end
64
70
 
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,
75
+ [:static, "a"],
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"
84
+ end
85
+
65
86
  it 'should compile newlines' do
66
87
  gen = SimpleGenerator.new(buffer: "VAR")
67
88
  expect(gen.call([:multi,
@@ -115,16 +136,16 @@ describe Temple::Generators::StringBuffer do
115
136
  gen = Temple::Generators::StringBuffer.new(freeze_static: false)
116
137
  expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
117
138
  expect(gen.call([:dynamic, 'test'])).to eq('_buf = (test).to_s')
118
- expect(gen.call([:code, 'test'])).to eq('_buf = \'\'; test; _buf')
139
+ expect(gen.call([:code, 'test'])).to eq('_buf = \'\'.dup; test; _buf')
119
140
 
120
- expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = \'\'; _buf << ("a"); _buf << ("b"); _buf')
121
- 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')
122
143
  end
123
144
 
124
145
  it 'should freeze static' do
125
146
  gen = Temple::Generators::StringBuffer.new(freeze_static: true)
126
147
  expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
127
- 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')
128
149
  end
129
150
  end
130
151
 
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.10.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: 2023-01-23 00:00:00.000000000 Z
12
+ date: 2023-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt