temple 0.8.2 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 95a7b68d7ea63e7673e183765ce0a64838ee4bdb
4
- data.tar.gz: 00e2072a5e6577a07a754bfe9c39bee365e87ebb
2
+ SHA256:
3
+ metadata.gz: 527609e09539e1854fc16e48ac864d23ce89584ec8c0cb3f3cf1f4ee4d6e8101
4
+ data.tar.gz: eee6b6dd3a38dde73365469c10b5cf7f8b6a35dd6797268b104e50cef27b4863
5
5
  SHA512:
6
- metadata.gz: 8a685000159a7f3e0ba41c4d7a6f8e7b8167755d020f05725020ce64dd2526aa19cf5007f78e071b9dd9521787756fee24cf30edc224cce701b6596020858dfc
7
- data.tar.gz: 71f2c6edfe191aa6ff7b90a245e2dbe8139fa03181a3d787236924b385c17a898dcad47a89e263cc2598769caf9b2767bdf32e6fcb4cac1d8d5421b1b8cf0562
6
+ metadata.gz: 17e8c7410950492aa3fdc41cb91f1ad40613324a411d77fcded2667ecb6ac137956e4bee64a9d0b038bb7cd9dc1098ae9e095ca59ba2a4a370e7a7a3cd62a4bd
7
+ data.tar.gz: 317d066d2e989072f0182d688845691573a74a31a7365883534c66571986bc2f0503df0a6a389d086cfba1eb0da69734a751a91691efa49772ebfb7a6c58f1b2
@@ -0,0 +1,40 @@
1
+ name: test
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ pull_request:
7
+ types:
8
+ - opened
9
+ - synchronize
10
+ - reopened
11
+ schedule:
12
+ - cron: "00 15 * * *"
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby:
20
+ - '2.5'
21
+ - '2.6'
22
+ - '2.7'
23
+ - '3.0'
24
+ - '3.1'
25
+ - jruby
26
+ - truffleruby-head
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+ - name: Set up Ruby
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby }}
33
+ - uses: actions/cache@v2
34
+ with:
35
+ path: vendor/bundle
36
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
37
+ restore-keys: ${{ runner.os }}-gems-
38
+ - name: bundle install
39
+ run: bundle config path vendor/bundle && bundle install -j$(nproc) --retry 3
40
+ - run: bundle exec rake test
data/CHANGES CHANGED
@@ -1,3 +1,15 @@
1
+ 0.9.0
2
+
3
+ * Require Ruby 2.5+ (#131)
4
+ * Change default :capture_generator to self (#113)
5
+ * Improve compatibility with Rails 7.1 (#135)
6
+ * Support Rails 6.1's annotate_rendered_view_with_filenames
7
+ with Temple::Filters::Ambles (#134)
8
+ * Fix a crash in StringSplitter filter (#138)
9
+ * Fix a warning by Object#=~ since Ruby 2.6 (#129)
10
+ * Fix deprecated Tilt template mime type (#108)
11
+ * Stop using deprecated EscapeUtils from Temple::Utils (#136)
12
+
1
13
  0.8.2
2
14
 
3
15
  * Support TruffleRuby in Temple::Filters::StaticAnalyzer (#127)
@@ -16,7 +28,7 @@
16
28
 
17
29
  0.7.8
18
30
 
19
- * Fix an warning in StaticAnalyzer
31
+ * Fix a warning in StaticAnalyzer
20
32
 
21
33
  0.7.7
22
34
 
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require 'bundler/gem_tasks'
1
2
  require 'rake/testtask'
2
3
 
3
4
  task default: :test
@@ -0,0 +1,21 @@
1
+ module Temple
2
+ module Filters
3
+ class Ambles < Filter
4
+ define_options :preamble, :postamble
5
+
6
+ def initialize(*)
7
+ super
8
+ @preamble = options[:preamble]
9
+ @postamble = options[:postamble]
10
+ end
11
+
12
+ def call(ast)
13
+ ret = [:multi]
14
+ ret << [:static, @preamble] if @preamble
15
+ ret << ast
16
+ ret << [:static, @postamble] if @postamble
17
+ ret
18
+ end
19
+ end
20
+ end
21
+ end
@@ -46,6 +46,7 @@ module Temple
46
46
 
47
47
  case type
48
48
  when :on_tstring_content
49
+ beg_str, end_str = escape_quotes(beg_str, end_str)
49
50
  exps << [:static, eval("#{beg_str}#{str}#{end_str}").to_s]
50
51
  when :on_embexpr_beg
51
52
  embedded = shift_balanced_embexpr(tokens)
@@ -54,6 +55,16 @@ module Temple
54
55
  end
55
56
  end
56
57
 
58
+ # Some quotes are split-unsafe. Replace such quotes with null characters.
59
+ def escape_quotes(beg_str, end_str)
60
+ case [beg_str[-1], end_str]
61
+ when ['(', ')'], ['[', ']'], ['{', '}']
62
+ [beg_str.sub(/.\z/) { "\0" }, "\0"]
63
+ else
64
+ [beg_str, end_str]
65
+ end
66
+ end
67
+
57
68
  def shift_balanced_embexpr(tokens)
58
69
  String.new.tap do |embedded|
59
70
  embexpr_open = 1
@@ -10,7 +10,7 @@ module Temple
10
10
  include Mixins::Options
11
11
 
12
12
  define_options :save_buffer,
13
- capture_generator: 'StringBuffer',
13
+ capture_generator: self,
14
14
  buffer: '_buf',
15
15
  freeze_static: RUBY_VERSION >= '2.1'
16
16
 
@@ -10,7 +10,7 @@ module Temple
10
10
  # @api public
11
11
  class RailsOutputBuffer < StringBuffer
12
12
  define_options :streaming,
13
- buffer_class: 'ActiveSupport::SafeBuffer',
13
+ buffer_class: 'ActionView::OutputBuffer',
14
14
  buffer: '@output_buffer',
15
15
  # output_buffer is needed for Rails 3.1 Streaming support
16
16
  capture_generator: RailsOutputBuffer
@@ -20,11 +20,7 @@ module Temple
20
20
  end
21
21
 
22
22
  def create_buffer
23
- if options[:streaming] && options[:buffer] == '@output_buffer'
24
- "#{buffer} = output_buffer || #{options[:buffer_class]}.new"
25
- else
26
- "#{buffer} = #{options[:buffer_class]}.new"
27
- end
23
+ "#{buffer} = output_buffer || #{options[:buffer_class]}.new"
28
24
  end
29
25
 
30
26
  def concat(str)
@@ -143,7 +143,8 @@ module Temple
143
143
  start = Or.new(self)
144
144
  curr = [start]
145
145
  rule.each do |elem|
146
- if elem =~ /^(.*)(\*|\?|\+)$/
146
+ case elem
147
+ when /^(.*)(\*|\?|\+)$/
147
148
  elem = Element.new(self, const_get($1))
148
149
  curr.each {|c| c << elem }
149
150
  elem << elem if $2 != '?'
@@ -5,6 +5,10 @@ module Temple
5
5
 
6
6
  def call(template, source = nil)
7
7
  opts = {}.update(self.class.options).update(file: template.identifier)
8
+ if ActionView::Base.try(:annotate_rendered_view_with_filenames) && template.format == :html
9
+ opts[:preamble] = "<!-- BEGIN #{template.short_identifier} -->\n"
10
+ opts[:postamble] = "<!-- END #{template.short_identifier} -->\n"
11
+ end
8
12
  self.class.compile((source || template.source), opts)
9
13
  end
10
14
 
@@ -7,14 +7,6 @@ module Temple
7
7
 
8
8
  define_options mime_type: 'text/html'
9
9
 
10
- def self.default_mime_type
11
- options[:mime_type]
12
- end
13
-
14
- def self.default_mime_type=(mime_type)
15
- options[:mime_type] = mime_type
16
- end
17
-
18
10
  # Prepare Temple template
19
11
  #
20
12
  # Called immediately after template data is loaded.
@@ -22,7 +14,7 @@ module Temple
22
14
  # @return [void]
23
15
  def prepare
24
16
  opts = {}.update(self.class.options).update(options).update(file: eval_file)
25
- opts.delete(:mime_type)
17
+ metadata[:mime_type] = opts.delete(:mime_type)
26
18
  if opts.include?(:outvar)
27
19
  opts[:buffer] = opts.delete(:outvar)
28
20
  opts[:save_buffer] = true
data/lib/temple/utils.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  begin
2
- require 'escape_utils'
2
+ require 'cgi/escape'
3
3
  rescue LoadError
4
- begin
5
- require 'cgi/escape'
6
- rescue LoadError
7
- end
8
4
  end
9
5
 
10
6
  module Temple
@@ -21,15 +17,7 @@ module Temple
21
17
  html.html_safe? ? html : escape_html(html)
22
18
  end
23
19
 
24
- if defined?(EscapeUtils)
25
- # Returns an escaped copy of `html`.
26
- #
27
- # @param html [String] The string to escape
28
- # @return [String] The escaped string
29
- def escape_html(html)
30
- EscapeUtils.escape_html(html.to_s, false)
31
- end
32
- elsif defined?(CGI.escapeHTML)
20
+ if defined?(CGI.escapeHTML)
33
21
  # Returns an escaped copy of `html`.
34
22
  #
35
23
  # @param html [String] The string to escape
@@ -1,3 +1,3 @@
1
1
  module Temple
2
- VERSION = '0.8.2'
2
+ VERSION = '0.9.0'
3
3
  end
data/lib/temple.rb CHANGED
@@ -41,6 +41,7 @@ module Temple
41
41
  end
42
42
 
43
43
  module Filters
44
+ autoload :Ambles, 'temple/filters/ambles'
44
45
  autoload :CodeMerger, 'temple/filters/code_merger'
45
46
  autoload :ControlFlow, 'temple/filters/control_flow'
46
47
  autoload :MultiFlattener, 'temple/filters/multi_flattener'
data/temple.gemspec CHANGED
@@ -18,12 +18,12 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.license = 'MIT'
20
20
 
21
- s.required_ruby_version = '>=1.9.2'
21
+ s.required_ruby_version = '>= 2.5.0'
22
22
 
23
23
  # Tilt is only development dependency because most parts of Temple
24
24
  # can be used without it.
25
25
  s.add_development_dependency('tilt')
26
26
  s.add_development_dependency('bacon')
27
27
  s.add_development_dependency('rake')
28
- s.add_development_dependency('erubis')
28
+ s.add_development_dependency('erubi')
29
29
  end
@@ -10,9 +10,30 @@ if defined?(Ripper) && RUBY_VERSION >= "2.0.0"
10
10
  @filter = Temple::Filters::StringSplitter.new
11
11
  end
12
12
 
13
- it 'should split :dynamic with string literal' do
14
- @filter.call([:dynamic, '"static#{dynamic}"']
15
- ).should.equal [:multi, [:static, 'static'], [:dynamic, 'dynamic']]
13
+ {
14
+ %q|''| => [:multi],
15
+ %q|""| => [:multi],
16
+ %q|"hello"| => [:multi, [:static, 'hello']],
17
+ %q|"hello #{}world"| => [:multi, [:static, 'hello '], [:static, 'world']],
18
+ %q|"#{hello}"| => [:multi, [:dynamic, 'hello']],
19
+ %q|"nya#{123}"| => [:multi, [:static, 'nya'], [:dynamic, '123']],
20
+ %q|"#{()}()"| => [:multi, [:dynamic, '()'], [:static, '()']],
21
+ %q|" #{ " #{ '#{}' } " }"| => [:multi, [:static, ' '], [:multi, [:static, ' '], [:multi, [:static, '#{}']], [:static, ' ']]],
22
+ %q|%Q[a#{b}c#{d}e]| => [:multi, [:static, 'a'], [:dynamic, 'b'], [:static, 'c'], [:dynamic, 'd'], [:static, 'e']],
23
+ %q|%q[a#{b}c#{d}e]| => [:multi, [:static, 'a#{b}c#{d}e']],
24
+ %q|"\#{}#{123}"| => [:multi, [:static, '#{}'], [:dynamic, '123']],
25
+ %q|"#{ '}' }"| => [:multi, [:multi, [:static, '}']]],
26
+ %q| "a" # hello | => [:multi, [:static, 'a']],
27
+ %q|"\""| => [:multi, [:static, '"']],
28
+ %q|"\\\\\\""| => [:multi, [:static, '\\"']],
29
+ %q|'\"'| => [:multi, [:static, '\"']],
30
+ %q|'\\\"'| => [:multi, [:static, '\\"']],
31
+ %q|"static#{dynamic}"| => [:multi, [:static, 'static'], [:dynamic, 'dynamic']],
32
+ }.each do |code, expected|
33
+ it "should split #{code}" do
34
+ actual = @filter.call([:dynamic, code])
35
+ actual.should.equal expected
36
+ end
16
37
  end
17
38
 
18
39
  describe '.compile' do
@@ -20,6 +41,11 @@ if defined?(Ripper) && RUBY_VERSION >= "2.0.0"
20
41
  lambda { Temple::Filters::StringSplitter.compile('1') }.
21
42
  should.raise(Temple::FilterError)
22
43
  end
44
+
45
+ it 'should compile strings quoted with parenthesis' do
46
+ tokens = Temple::Filters::StringSplitter.compile('%Q(href("#{1 + 1}");)')
47
+ tokens.should.equal [[:static, "href(\""], [:dynamic, "1 + 1"], [:static, "\");"]]
48
+ end
23
49
  end
24
50
  end
25
51
  end
data/test/helper.rb CHANGED
@@ -20,8 +20,8 @@ module TestHelper
20
20
  Temple::ERB::Template.new(options) { src }.render
21
21
  end
22
22
 
23
- def erubis(src, options = {})
24
- Tilt::ErubisTemplate.new(options) { src }.render
23
+ def erubi(src, options = {})
24
+ Tilt::ErubiTemplate.new(options) { src }.render
25
25
  end
26
26
  end
27
27
 
data/test/test_erb.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'helper'
2
- require 'tilt/erubis'
2
+ require 'tilt/erubi'
3
3
 
4
4
  describe Temple::ERB::Engine do
5
5
  it 'should compile erb' do
@@ -11,7 +11,7 @@ describe Temple::ERB::Engine do
11
11
  <% end %>
12
12
  }
13
13
 
14
- erb(src).should.equal erubis(src)
14
+ erb(src).should.equal erubi(src)
15
15
  end
16
16
 
17
17
  it 'should recognize comments' do
@@ -20,7 +20,7 @@ hello
20
20
  <%# comment -- ignored -- useful in testing %>
21
21
  world}
22
22
 
23
- erb(src).should.equal erubis(src)
23
+ erb(src).should.equal erubi(src)
24
24
  end
25
25
 
26
26
  it 'should recognize <%% and %%>' do
@@ -55,7 +55,7 @@ world}
55
55
  <% end %>
56
56
  }
57
57
 
58
- erb(src, trim: true).should.equal erubis(src, trim: true)
59
- erb(src, trim: false).should.equal erubis(src, trim: false)
58
+ erb(src, trim: true).should.equal erubi(src, trim: true)
59
+ erb(src, trim: false).should.equal erubi(src, trim: false)
60
60
  end
61
61
  end
@@ -143,16 +143,16 @@ end
143
143
  describe Temple::Generators::RailsOutputBuffer do
144
144
  it 'should compile simple expressions' do
145
145
  gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: false)
146
- gen.call([:static, 'test']).should.equal '@output_buffer = ActiveSupport::SafeBuffer.new; ' +
146
+ gen.call([:static, 'test']).should.equal '@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
147
147
  '@output_buffer.safe_concat(("test")); @output_buffer'
148
- gen.call([:dynamic, 'test']).should.equal '@output_buffer = ActiveSupport::SafeBuffer.new; ' +
148
+ gen.call([:dynamic, 'test']).should.equal '@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
149
149
  '@output_buffer.safe_concat(((test).to_s)); @output_buffer'
150
- gen.call([:code, 'test']).should.equal '@output_buffer = ActiveSupport::SafeBuffer.new; ' +
150
+ gen.call([:code, 'test']).should.equal '@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
151
151
  'test; @output_buffer'
152
152
  end
153
153
 
154
154
  it 'should freeze static' do
155
155
  gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: true)
156
- gen.call([:static, 'test']).should.equal '@output_buffer = ActiveSupport::SafeBuffer.new; @output_buffer.safe_concat(("test".freeze)); @output_buffer'
156
+ gen.call([:static, 'test']).should.equal '@output_buffer = output_buffer || ActionView::OutputBuffer.new; @output_buffer.safe_concat(("test".freeze)); @output_buffer'
157
157
  end
158
158
  end
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.8.2
4
+ version: 0.9.0
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: 2019-09-12 00:00:00.000000000 Z
12
+ date: 2022-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: erubis
57
+ name: erubi
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
@@ -75,8 +75,8 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
+ - ".github/workflows/test.yml"
78
79
  - ".gitignore"
79
- - ".travis.yml"
80
80
  - ".yardopts"
81
81
  - CHANGES
82
82
  - EXPRESSIONS.md
@@ -92,6 +92,7 @@ files:
92
92
  - lib/temple/erb/trimming.rb
93
93
  - lib/temple/exceptions.rb
94
94
  - lib/temple/filter.rb
95
+ - lib/temple/filters/ambles.rb
95
96
  - lib/temple/filters/code_merger.rb
96
97
  - lib/temple/filters/control_flow.rb
97
98
  - lib/temple/filters/dynamic_inliner.rb
@@ -170,41 +171,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
171
  requirements:
171
172
  - - ">="
172
173
  - !ruby/object:Gem::Version
173
- version: 1.9.2
174
+ version: 2.5.0
174
175
  required_rubygems_version: !ruby/object:Gem::Requirement
175
176
  requirements:
176
177
  - - ">="
177
178
  - !ruby/object:Gem::Version
178
179
  version: '0'
179
180
  requirements: []
180
- rubyforge_project:
181
- rubygems_version: 2.6.11
181
+ rubygems_version: 3.3.7
182
182
  signing_key:
183
183
  specification_version: 4
184
184
  summary: Template compilation framework in Ruby
185
- test_files:
186
- - test/filters/test_code_merger.rb
187
- - test/filters/test_control_flow.rb
188
- - test/filters/test_dynamic_inliner.rb
189
- - test/filters/test_eraser.rb
190
- - test/filters/test_escapable.rb
191
- - test/filters/test_multi_flattener.rb
192
- - test/filters/test_static_analyzer.rb
193
- - test/filters/test_static_merger.rb
194
- - test/filters/test_string_splitter.rb
195
- - test/helper.rb
196
- - test/html/test_attribute_merger.rb
197
- - test/html/test_attribute_remover.rb
198
- - test/html/test_attribute_sorter.rb
199
- - test/html/test_fast.rb
200
- - test/html/test_pretty.rb
201
- - test/mixins/test_dispatcher.rb
202
- - test/mixins/test_grammar_dsl.rb
203
- - test/test_engine.rb
204
- - test/test_erb.rb
205
- - test/test_filter.rb
206
- - test/test_generator.rb
207
- - test/test_grammar.rb
208
- - test/test_map.rb
209
- - test/test_static_analyzer.rb
210
- - test/test_utils.rb
185
+ test_files: []
data/.travis.yml DELETED
@@ -1,30 +0,0 @@
1
- language: ruby
2
- dist: trusty
3
-
4
- cache: bundler
5
-
6
- rvm:
7
- - 1.9.3
8
- - 2.0.0
9
- - 2.1.10
10
- - 2.2.6
11
- - 2.3.3
12
- - ruby-head
13
- - jruby-19mode
14
- - rbx-3
15
-
16
- sudo: false
17
-
18
- env:
19
- - ESCAPE_UTILS=1
20
- - ""
21
-
22
- matrix:
23
- allow_failures:
24
- - rvm: ruby-head
25
- - rvm: rbx-3
26
- exclude:
27
- - rvm: jruby-19mode
28
- env: ESCAPE_UTILS=1
29
- - rvm: rbx-3
30
- env: ESCAPE_UTILS=1