temple 0.8.2 → 0.10.0

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 +5 -5
  2. data/.github/workflows/test.yml +34 -0
  3. data/.gitignore +1 -0
  4. data/CHANGES +25 -1
  5. data/Gemfile +0 -1
  6. data/README.md +1 -1
  7. data/Rakefile +4 -11
  8. data/lib/temple/erb/engine.rb +2 -0
  9. data/lib/temple/erb/parser.rb +1 -1
  10. data/lib/temple/filters/ambles.rb +21 -0
  11. data/lib/temple/filters/string_splitter.rb +12 -1
  12. data/lib/temple/generator.rb +1 -1
  13. data/lib/temple/generators/rails_output_buffer.rb +3 -4
  14. data/lib/temple/mixins/grammar_dsl.rb +2 -1
  15. data/lib/temple/templates/rails.rb +6 -2
  16. data/lib/temple/templates/tilt.rb +1 -9
  17. data/lib/temple/utils.rb +4 -15
  18. data/lib/temple/version.rb +1 -1
  19. data/lib/temple.rb +1 -0
  20. data/spec/engine_spec.rb +189 -0
  21. data/{test/test_erb.rb → spec/erb_spec.rb} +12 -12
  22. data/spec/filter_spec.rb +29 -0
  23. data/{test/filters/test_code_merger.rb → spec/filters/code_merger_spec.rb} +7 -7
  24. data/{test/filters/test_control_flow.rb → spec/filters/control_flow_spec.rb} +13 -13
  25. data/{test/filters/test_dynamic_inliner.rb → spec/filters/dynamic_inliner_spec.rb} +18 -18
  26. data/{test/filters/test_eraser.rb → spec/filters/eraser_spec.rb} +9 -9
  27. data/{test/filters/test_escapable.rb → spec/filters/escapable_spec.rb} +10 -10
  28. data/{test/filters/test_multi_flattener.rb → spec/filters/multi_flattener_spec.rb} +4 -4
  29. data/{test/filters/test_static_analyzer.rb → spec/filters/static_analyzer_spec.rb} +6 -8
  30. data/{test/filters/test_static_merger.rb → spec/filters/static_merger_spec.rb} +7 -7
  31. data/spec/filters/string_splitter_spec.rb +50 -0
  32. data/spec/generator_spec.rb +158 -0
  33. data/spec/grammar_spec.rb +47 -0
  34. data/{test/html/test_attribute_merger.rb → spec/html/attribute_merger_spec.rb} +11 -11
  35. data/{test/html/test_attribute_remover.rb → spec/html/attribute_remover_spec.rb} +7 -7
  36. data/{test/html/test_attribute_sorter.rb → spec/html/attribute_sorter_spec.rb} +7 -7
  37. data/{test/html/test_fast.rb → spec/html/fast_spec.rb} +23 -23
  38. data/{test/html/test_pretty.rb → spec/html/pretty_spec.rb} +7 -7
  39. data/spec/map_spec.rb +39 -0
  40. data/{test/mixins/test_dispatcher.rb → spec/mixins/dispatcher_spec.rb} +12 -12
  41. data/{test/mixins/test_grammar_dsl.rb → spec/mixins/grammar_dsl_spec.rb} +19 -19
  42. data/{test/helper.rb → spec/spec_helper.rb} +5 -6
  43. data/{test/test_static_analyzer.rb → spec/static_analyzer_spec.rb} +6 -6
  44. data/spec/utils_spec.rb +39 -0
  45. data/temple.gemspec +3 -4
  46. metadata +34 -59
  47. data/.travis.yml +0 -30
  48. data/test/filters/test_string_splitter.rb +0 -25
  49. data/test/test_engine.rb +0 -189
  50. data/test/test_filter.rb +0 -29
  51. data/test/test_generator.rb +0 -158
  52. data/test/test_grammar.rb +0 -47
  53. data/test/test_map.rb +0 -39
  54. data/test/test_utils.rb +0 -39
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: c7475d628203a95d9ec067ac1388f8428cb213f4534a2fd2ed1b9cf0be7d3293
4
+ data.tar.gz: d828006ab486aee65e70e8e321022d28191deba994d43c1141dccad2815f41f2
5
5
  SHA512:
6
- metadata.gz: 8a685000159a7f3e0ba41c4d7a6f8e7b8167755d020f05725020ce64dd2526aa19cf5007f78e071b9dd9521787756fee24cf30edc224cce701b6596020858dfc
7
- data.tar.gz: 71f2c6edfe191aa6ff7b90a245e2dbe8139fa03181a3d787236924b385c17a898dcad47a89e263cc2598769caf9b2767bdf32e6fcb4cac1d8d5421b1b8cf0562
6
+ metadata.gz: d74cc956889989a4d65f6727d7f521cbcbf3d9c2de1a6abda92b4957a7e3992de2b7de6c7634b4dfafe9d4ce1a505f22b8f5af1ef9a217876d6d67f276e04557
7
+ data.tar.gz: 1958e441fbab605e06f560db0f4c26e5fecf7c673a12a5aad843a3bd5bb4c0ce77e3c2ea13f46b22d962770898587b7f76bd0ad2b11377898e61924e7bc20c87
@@ -0,0 +1,34 @@
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
+ bundler-cache: true
34
+ - run: bundle exec rake spec
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ coverage
2
2
  .yardoc
3
3
  doc
4
4
  Gemfile.lock
5
+ /pkg/
data/CHANGES CHANGED
@@ -1,3 +1,27 @@
1
+ 0.10.0
2
+
3
+ * Regression: Revert changes to :capture_generator since 0.8.2 (#112, #113, #137)
4
+ * Regression: Ensure that output buffer is not reused for capturing in Rails (#135)
5
+ * Drop support for Rails 4.x
6
+
7
+ 0.9.1
8
+
9
+ * Fix Slim's error in AttributeMerger due to 0.9.0's :capture_generator (#137)
10
+ * Use specified :capture_generator for nested captures (#112)
11
+ * Fix Temple::ERB::Engine's <%= to not escape and <%== to escape expressions
12
+
13
+ 0.9.0
14
+
15
+ * Require Ruby 2.5+ (#131)
16
+ * Change default :capture_generator to self (#113)
17
+ * Improve compatibility with Rails 7.1 (#135)
18
+ * Support Rails 6.1's annotate_rendered_view_with_filenames
19
+ with Temple::Filters::Ambles (#134)
20
+ * Fix a crash in StringSplitter filter (#138)
21
+ * Fix a warning by Object#=~ since Ruby 2.6 (#129)
22
+ * Fix deprecated Tilt template mime type (#108)
23
+ * Stop using deprecated EscapeUtils from Temple::Utils (#136)
24
+
1
25
  0.8.2
2
26
 
3
27
  * Support TruffleRuby in Temple::Filters::StaticAnalyzer (#127)
@@ -16,7 +40,7 @@
16
40
 
17
41
  0.7.8
18
42
 
19
- * Fix an warning in StaticAnalyzer
43
+ * Fix a warning in StaticAnalyzer
20
44
 
21
45
  0.7.7
22
46
 
data/Gemfile CHANGED
@@ -1,3 +1,2 @@
1
1
  source 'https://rubygems.org/'
2
2
  gemspec
3
- gem 'escape_utils' if ENV['ESCAPE_UTILS']
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Temple
2
2
  ======
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/judofyr/temple.svg?branch=master)](http://travis-ci.org/judofyr/temple) [![Code Climate](https://codeclimate.com/github/judofyr/temple.svg)](https://codeclimate.com/github/judofyr/temple) [![Gem Version](https://badge.fury.io/rb/temple.svg)](https://rubygems.org/gems/temple)
4
+ [![test](https://github.com/judofyr/temple/actions/workflows/test.yml/badge.svg)](https://github.com/judofyr/temple/actions/workflows/test.yml) [![Code Climate](https://codeclimate.com/github/judofyr/temple.svg)](https://codeclimate.com/github/judofyr/temple) [![Gem Version](https://badge.fury.io/rb/temple.svg)](https://rubygems.org/gems/temple) [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/gems/temple/frames)
5
5
 
6
6
  Temple is an abstraction and a framework for compiling templates to pure Ruby.
7
7
  It's all about making it easier to experiment, implement and optimize template
data/Rakefile CHANGED
@@ -1,15 +1,8 @@
1
- require 'rake/testtask'
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
2
3
 
3
- task default: :test
4
- task :test do
5
- sh "bacon -Ilib -Itest --automatic --quiet"
6
- end
7
-
8
- #Rake::TestTask.new(:test) do |t|
9
- # t.libs << 'lib' << 'test'
10
- # t.pattern = 'test/**/test_*.rb'
11
- # t.verbose = false
12
- #end
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
13
6
 
14
7
  begin
15
8
  require 'rcov/rcovtask'
@@ -7,6 +7,8 @@ module Temple
7
7
  use Temple::ERB::Parser
8
8
  use Temple::ERB::Trimming
9
9
  filter :Escapable
10
+ filter :StringSplitter
11
+ filter :StaticAnalyzer
10
12
  filter :MultiFlattener
11
13
  filter :StaticMerger
12
14
  generator :ArrayBuffer
@@ -27,7 +27,7 @@ module Temple
27
27
  when '#'
28
28
  result << [:code, "\n" * code.count("\n")]
29
29
  when /=/
30
- result << [:escape, indicator.size <= 1, [:dynamic, code]]
30
+ result << [:escape, indicator.size == 2, [:dynamic, code]]
31
31
  else
32
32
  result << [:code, code]
33
33
  end
@@ -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
@@ -7,7 +7,7 @@ module Temple
7
7
  module Filters
8
8
  # Compile [:dynamic, "foo#{bar}"] to [:multi, [:static, 'foo'], [:dynamic, 'bar']]
9
9
  class StringSplitter < Filter
10
- if defined?(Ripper) && RUBY_VERSION >= "2.0.0" && Ripper.respond_to?(:lex)
10
+ if defined?(Ripper) && Ripper.respond_to?(:lex)
11
11
  class << self
12
12
  # `code` param must be valid string literal
13
13
  def compile(code)
@@ -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
@@ -12,7 +12,7 @@ module Temple
12
12
  define_options :save_buffer,
13
13
  capture_generator: 'StringBuffer',
14
14
  buffer: '_buf',
15
- freeze_static: RUBY_VERSION >= '2.1'
15
+ freeze_static: true
16
16
 
17
17
  def call(exp)
18
18
  [preamble, compile(exp), postamble].flatten.compact.join('; ')
@@ -9,10 +9,9 @@ module Temple
9
9
  #
10
10
  # @api public
11
11
  class RailsOutputBuffer < StringBuffer
12
- define_options :streaming,
13
- buffer_class: 'ActiveSupport::SafeBuffer',
12
+ define_options :streaming, # ignored
13
+ buffer_class: 'ActionView::OutputBuffer',
14
14
  buffer: '@output_buffer',
15
- # output_buffer is needed for Rails 3.1 Streaming support
16
15
  capture_generator: RailsOutputBuffer
17
16
 
18
17
  def call(exp)
@@ -20,7 +19,7 @@ module Temple
20
19
  end
21
20
 
22
21
  def create_buffer
23
- if options[:streaming] && options[:buffer] == '@output_buffer'
22
+ if buffer == '@output_buffer'
24
23
  "#{buffer} = output_buffer || #{options[:buffer_class]}.new"
25
24
  else
26
25
  "#{buffer} = #{options[:buffer_class]}.new"
@@ -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
 
@@ -14,8 +18,8 @@ module Temple
14
18
 
15
19
  def self.register_as(*names)
16
20
  raise 'Rails is not loaded - Temple::Templates::Rails cannot be used' unless defined?(::ActionView)
17
- if ::ActiveSupport::VERSION::MAJOR < 3 || ::ActiveSupport::VERSION::MAJOR == 3 && ::ActiveSupport::VERSION::MINOR < 1
18
- raise "Temple supports only Rails 3.1 and greater, your Rails version is #{::ActiveSupport::VERSION::STRING}"
21
+ if ::ActiveSupport::VERSION::MAJOR < 5
22
+ raise "Temple supports only Rails 5 and greater, your Rails version is #{::ActiveSupport::VERSION::STRING}"
19
23
  end
20
24
  names.each do |name|
21
25
  ::ActionView::Template.register_template_handler name.to_sym, new
@@ -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
@@ -18,18 +14,11 @@ module Temple
18
14
  # @param html [String] The string to escape
19
15
  # @return [String] The escaped string
20
16
  def escape_html_safe(html)
21
- html.html_safe? ? html : escape_html(html)
17
+ s = html.to_s
18
+ s.html_safe? || html.html_safe? ? s : escape_html(s)
22
19
  end
23
20
 
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)
21
+ if defined?(CGI.escapeHTML)
33
22
  # Returns an escaped copy of `html`.
34
23
  #
35
24
  # @param html [String] The string to escape
@@ -1,3 +1,3 @@
1
1
  module Temple
2
- VERSION = '0.8.2'
2
+ VERSION = '0.10.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'
@@ -0,0 +1,189 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ class Callable1
5
+ def call(exp)
6
+ exp
7
+ end
8
+ end
9
+
10
+ class Callable2
11
+ def call(exp)
12
+ exp
13
+ end
14
+ end
15
+
16
+ class MySpecialFilter
17
+ def initialize(opts = {})
18
+ end
19
+
20
+ def call(exp)
21
+ exp
22
+ end
23
+ end
24
+
25
+ class TestEngine < Temple::Engine
26
+ use(:Parser) do |input|
27
+ [:static, input]
28
+ end
29
+ use :MyFilter1, proc {|exp| exp }
30
+ use :MyFilter2, proc {|exp| exp }
31
+ use Temple::HTML::Pretty, pretty: true
32
+ filter :MultiFlattener
33
+ generator :ArrayBuffer
34
+ use(:BeforeBeforeLast) { MySpecialFilter }
35
+ use :BeforeLast, Callable1.new
36
+ use(:Last) { Callable2.new }
37
+ end
38
+
39
+ describe Temple::Engine do
40
+ it 'should build chain' do
41
+ expect(TestEngine.chain.size).to eq(9)
42
+
43
+ expect(TestEngine.chain[0].first).to eq(:Parser)
44
+ expect(TestEngine.chain[0].size).to eq(2)
45
+ expect(TestEngine.chain[0].last).to be_a(Proc)
46
+
47
+ expect(TestEngine.chain[1].first).to eq(:MyFilter1)
48
+ expect(TestEngine.chain[1].size).to eq(2)
49
+ expect(TestEngine.chain[1].last).to be_a(Proc)
50
+
51
+ expect(TestEngine.chain[2].first).to eq(:MyFilter2)
52
+ expect(TestEngine.chain[2].size).to eq(2)
53
+ expect(TestEngine.chain[2].last).to be_a(Proc)
54
+
55
+ expect(TestEngine.chain[3].first).to eq(:'Temple::HTML::Pretty')
56
+ expect(TestEngine.chain[3].size).to eq(2)
57
+ expect(TestEngine.chain[3].last).to be_a(Proc)
58
+
59
+ expect(TestEngine.chain[4].first).to eq(:MultiFlattener)
60
+ expect(TestEngine.chain[4].size).to eq(2)
61
+ expect(TestEngine.chain[4].last).to be_a(Proc)
62
+
63
+ expect(TestEngine.chain[5].first).to eq(:ArrayBuffer)
64
+ expect(TestEngine.chain[5].size).to eq(2)
65
+ expect(TestEngine.chain[5].last).to be_a(Proc)
66
+
67
+ expect(TestEngine.chain[6].first).to eq(:BeforeBeforeLast)
68
+ expect(TestEngine.chain[6].size).to eq(2)
69
+ expect(TestEngine.chain[6].last).to be_a(Proc)
70
+
71
+ expect(TestEngine.chain[7].first).to eq(:BeforeLast)
72
+ expect(TestEngine.chain[7].size).to eq(2)
73
+ expect(TestEngine.chain[7].last).to be_a(Proc)
74
+
75
+ expect(TestEngine.chain[8].first).to eq(:Last)
76
+ expect(TestEngine.chain[8].size).to eq(2)
77
+ expect(TestEngine.chain[8].last).to be_a(Proc)
78
+ end
79
+
80
+ it 'should instantiate chain' do
81
+ call_chain = TestEngine.new.send(:call_chain)
82
+ expect(call_chain[0]).to be_a(Method)
83
+ expect(call_chain[1]).to be_a(Method)
84
+ expect(call_chain[2]).to be_a(Method)
85
+ expect(call_chain[3]).to be_a(Temple::HTML::Pretty)
86
+ expect(call_chain[4]).to be_a(Temple::Filters::MultiFlattener)
87
+ expect(call_chain[5]).to be_a(Temple::Generators::ArrayBuffer)
88
+ expect(call_chain[6]).to be_a(MySpecialFilter)
89
+ expect(call_chain[7]).to be_a(Callable1)
90
+ expect(call_chain[8]).to be_a(Callable2)
91
+ end
92
+
93
+ it 'should have #append' do
94
+ engine = TestEngine.new
95
+ call_chain = engine.send(:call_chain)
96
+ expect(call_chain.size).to eq(9)
97
+
98
+ engine.append :MyFilter3 do |exp|
99
+ exp
100
+ end
101
+
102
+ expect(TestEngine.chain.size).to eq(9)
103
+ expect(engine.chain.size).to eq(10)
104
+ expect(engine.chain[9].first).to eq(:MyFilter3)
105
+ expect(engine.chain[9].size).to eq(2)
106
+ expect(engine.chain[9].last).to be_a(Proc)
107
+
108
+ call_chain = engine.send(:call_chain)
109
+ expect(call_chain.size).to eq(10)
110
+ expect(call_chain[9]).to be_a(Method)
111
+ end
112
+
113
+ it 'should have #prepend' do
114
+ engine = TestEngine.new
115
+ call_chain = engine.send(:call_chain)
116
+ expect(call_chain.size).to eq(9)
117
+
118
+ engine.prepend :MyFilter0 do |exp|
119
+ exp
120
+ end
121
+
122
+ expect(TestEngine.chain.size).to eq(9)
123
+ expect(engine.chain.size).to eq(10)
124
+ expect(engine.chain[0].first).to eq(:MyFilter0)
125
+ expect(engine.chain[0].size).to eq(2)
126
+ expect(engine.chain[0].last).to be_a(Proc)
127
+ expect(engine.chain[1].first).to eq(:Parser)
128
+
129
+ call_chain = engine.send(:call_chain)
130
+ expect(call_chain.size).to eq(10)
131
+ expect(call_chain[0]).to be_a(Method)
132
+ end
133
+
134
+ it 'should have #after' do
135
+ engine = TestEngine.new
136
+ engine.after :Parser, :MyFilter0 do |exp|
137
+ exp
138
+ end
139
+ expect(TestEngine.chain.size).to eq(9)
140
+ expect(engine.chain.size).to eq(10)
141
+ expect(engine.chain[0].first).to eq(:Parser)
142
+ expect(engine.chain[1].first).to eq(:MyFilter0)
143
+ expect(engine.chain[2].first).to eq(:MyFilter1)
144
+ end
145
+
146
+ it 'should have #before' do
147
+ engine = TestEngine.new
148
+ engine.before :MyFilter1, :MyFilter0 do |exp|
149
+ exp
150
+ end
151
+ expect(TestEngine.chain.size).to eq(9)
152
+ expect(engine.chain.size).to eq(10)
153
+ expect(engine.chain[0].first).to eq(:Parser)
154
+ expect(engine.chain[1].first).to eq(:MyFilter0)
155
+ expect(engine.chain[2].first).to eq(:MyFilter1)
156
+ end
157
+
158
+ it 'should have #remove' do
159
+ engine = TestEngine.new
160
+ engine.remove :MyFilter1
161
+ expect(TestEngine.chain.size).to eq(9)
162
+ expect(engine.chain.size).to eq(8)
163
+ expect(engine.chain[0].first).to eq(:Parser)
164
+ expect(engine.chain[1].first).to eq(:MyFilter2)
165
+
166
+ engine = TestEngine.new
167
+ engine.remove /Last/
168
+ expect(engine.chain.size).to eq(6)
169
+ end
170
+
171
+ it 'should have #replace' do
172
+ engine = TestEngine.new
173
+ engine.replace :Parser, :MyParser do |exp|
174
+ exp
175
+ end
176
+ expect(engine.chain.size).to eq(9)
177
+ expect(engine.chain[0].first).to eq(:MyParser)
178
+ end
179
+
180
+ it 'should work with inheritance' do
181
+ inherited_engine = Class.new(TestEngine)
182
+ expect(inherited_engine.chain.size).to eq(9)
183
+ inherited_engine.append :MyFilter3 do |exp|
184
+ exp
185
+ end
186
+ expect(inherited_engine.chain.size).to eq(10)
187
+ expect(TestEngine.chain.size).to eq(9)
188
+ end
189
+ end
@@ -1,5 +1,5 @@
1
- require 'helper'
2
- require 'tilt/erubis'
1
+ require 'spec_helper'
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
+ expect(erb(src)).to eq(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
+ expect(erb(src)).to eq(erubi(src))
24
24
  end
25
25
 
26
26
  it 'should recognize <%% and %%>' do
@@ -31,19 +31,19 @@ world}
31
31
  <% end %>
32
32
  }
33
33
 
34
- erb(src).should.equal "\n<%\n %>\n"
34
+ expect(erb(src)).to eq("\n<%\n %>\n")
35
35
  end
36
36
 
37
37
  it 'should escape automatically' do
38
- src = '<%= "<" %>'
38
+ src = '<%== "<" %>'
39
39
  ans = '&lt;'
40
- erb(src).should.equal ans
40
+ expect(erb(src)).to eq(ans)
41
41
  end
42
42
 
43
- it 'should support == to disable automatic escape' do
44
- src = '<%== "<" %>'
43
+ it 'should support = to disable automatic escape' do
44
+ src = '<%= "<" %>'
45
45
  ans = '<'
46
- erb(src).should.equal ans
46
+ expect(erb(src)).to eq(ans)
47
47
  end
48
48
 
49
49
  it 'should support trim mode' 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
+ expect(erb(src, trim: true)).to eq(erubi(src, trim: true))
59
+ expect(erb(src, trim: false)).to eq(erubi(src, trim: false))
60
60
  end
61
61
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ class SimpleFilter < Temple::Filter
4
+ define_options :key
5
+
6
+ def on_test(arg)
7
+ [:on_test, arg]
8
+ end
9
+ end
10
+
11
+ describe Temple::Filter do
12
+ it 'should support options' do
13
+ expect(Temple::Filter).to respond_to(:default_options)
14
+ expect(Temple::Filter).to respond_to(:set_default_options)
15
+ expect(Temple::Filter).to respond_to(:define_options)
16
+ expect(Temple::Filter.new.options).to be_a(Temple::ImmutableMap)
17
+ expect(SimpleFilter.new(key: 3).options[:key]).to eq(3)
18
+ end
19
+
20
+ it 'should implement call' do
21
+ expect(Temple::Filter.new.call([:exp])).to eq([:exp])
22
+ end
23
+
24
+ it 'should process expressions' do
25
+ filter = SimpleFilter.new
26
+ expect(filter.call([:unhandled])).to eq([:unhandled])
27
+ expect(filter.call([:test, 42])).to eq([:on_test, 42])
28
+ end
29
+ end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::Filters::CodeMerger do
4
4
  before do
@@ -6,21 +6,21 @@ describe Temple::Filters::CodeMerger do
6
6
  end
7
7
 
8
8
  it 'should merge serveral codes' do
9
- @filter.call([:multi,
9
+ expect(@filter.call([:multi,
10
10
  [:code, "a"],
11
11
  [:code, "b"],
12
12
  [:code, "c"]
13
- ]).should.equal [:code, "a; b; c"]
13
+ ])).to eq [:code, "a; b; c"]
14
14
  end
15
15
 
16
16
  it 'should merge serveral codes around static' do
17
- @filter.call([:multi,
17
+ expect(@filter.call([:multi,
18
18
  [:code, "a"],
19
19
  [:code, "b"],
20
20
  [:static, "123"],
21
21
  [:code, "a"],
22
22
  [:code, "b"]
23
- ]).should.equal [:multi,
23
+ ])).to eq [:multi,
24
24
  [:code, "a; b"],
25
25
  [:static, "123"],
26
26
  [:code, "a; b"]
@@ -28,11 +28,11 @@ describe Temple::Filters::CodeMerger do
28
28
  end
29
29
 
30
30
  it 'should merge serveral codes with newlines' do
31
- @filter.call([:multi,
31
+ expect(@filter.call([:multi,
32
32
  [:code, "a"],
33
33
  [:code, "b"],
34
34
  [:newline],
35
35
  [:code, "c"]
36
- ]).should.equal [:code, "a; b\nc"]
36
+ ])).to eq [:code, "a; b\nc"]
37
37
  end
38
38
  end