temple 0.9.1 → 0.10.3
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 +21 -0
- data/Gemfile +0 -1
- data/Rakefile +0 -13
- 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/dynamic_merger.rb +69 -0
- 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 +9 -12
- 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 +2 -0
- data/temple.gemspec +1 -3
- metadata +4 -28
- data/spec/engine_spec.rb +0 -189
- data/spec/erb_spec.rb +0 -61
- data/spec/filter_spec.rb +0 -29
- data/spec/filters/code_merger_spec.rb +0 -38
- data/spec/filters/control_flow_spec.rb +0 -90
- data/spec/filters/dynamic_inliner_spec.rb +0 -95
- data/spec/filters/eraser_spec.rb +0 -55
- data/spec/filters/escapable_spec.rb +0 -49
- data/spec/filters/multi_flattener_spec.rb +0 -33
- data/spec/filters/static_analyzer_spec.rb +0 -35
- data/spec/filters/static_merger_spec.rb +0 -41
- data/spec/filters/string_splitter_spec.rb +0 -50
- data/spec/generator_spec.rb +0 -167
- data/spec/grammar_spec.rb +0 -47
- data/spec/html/attribute_merger_spec.rb +0 -76
- data/spec/html/attribute_remover_spec.rb +0 -43
- data/spec/html/attribute_sorter_spec.rb +0 -48
- data/spec/html/fast_spec.rb +0 -97
- data/spec/html/pretty_spec.rb +0 -55
- data/spec/map_spec.rb +0 -39
- data/spec/mixins/dispatcher_spec.rb +0 -70
- data/spec/mixins/grammar_dsl_spec.rb +0 -86
- data/spec/spec_helper.rb +0 -29
- data/spec/static_analyzer_spec.rb +0 -39
- data/spec/utils_spec.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2dfc92778763412687b4c4cefce7f8f01975463a4237b96e3931d246cfc9953
|
4
|
+
data.tar.gz: 782b6af3993bdb5179153a5eb6b12304de17f6d6b5661f64671a0aad52649dfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18269f8d2621a71d0eaf4050e56365cb1b734c4d14cda063503e308fe353808f81de4794b3226cbc0698327a8108d5c225500d19346bf04dce761783cd57374b
|
7
|
+
data.tar.gz: ddd93041cc83790c7c610a67401d8b10bad033bdeb1f209e3d87a056c67dc855d8f2861bb8d2dfceb087d787938020e91c4211539ae6b2da41eb2f0d36988caa
|
data/.github/workflows/test.yml
CHANGED
data/CHANGES
CHANGED
@@ -1,6 +1,27 @@
|
|
1
|
+
0.10.3
|
2
|
+
|
3
|
+
* Remove test files from the gem package (#146)
|
4
|
+
* Add DynamicMerger filter (#147)
|
5
|
+
|
6
|
+
0.10.2
|
7
|
+
|
8
|
+
* Fix Sinatra capture_generator problem (#145)
|
9
|
+
|
10
|
+
0.10.1
|
11
|
+
|
12
|
+
* Use specified :capture_generator for nested captures (#112, #144)
|
13
|
+
* Compatibility with frozen string literals
|
14
|
+
|
15
|
+
0.10.0
|
16
|
+
|
17
|
+
* Regression: Revert changes to :capture_generator since 0.8.2 (#112, #113, #137)
|
18
|
+
* Regression: Ensure that output buffer is not reused for capturing in Rails (#135)
|
19
|
+
* Drop support for Rails 4.x
|
20
|
+
|
1
21
|
0.9.1
|
2
22
|
|
3
23
|
* Fix Slim's error in AttributeMerger due to 0.9.0's :capture_generator (#137)
|
24
|
+
* Use specified :capture_generator for nested captures (#112)
|
4
25
|
* Fix Temple::ERB::Engine's <%= to not escape and <%== to escape expressions
|
5
26
|
|
6
27
|
0.9.0
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -3,16 +3,3 @@ require 'rspec/core/rake_task'
|
|
3
3
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
task default: :spec
|
6
|
-
|
7
|
-
begin
|
8
|
-
require 'rcov/rcovtask'
|
9
|
-
Rcov::RcovTask.new do |t|
|
10
|
-
t.libs << 'lib' << 'test'
|
11
|
-
t.pattern = 'test/**/test_*.rb'
|
12
|
-
t.verbose = false
|
13
|
-
end
|
14
|
-
rescue LoadError
|
15
|
-
task :rcov do
|
16
|
-
abort "RCov is not available. In order to run rcov, you must: gem install rcov"
|
17
|
-
end
|
18
|
-
end
|
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
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Temple
|
3
|
+
module Filters
|
4
|
+
# Compile [:multi, [:static, 'foo'], [:dynamic, 'bar']] to [:dynamic, '"foo#{bar}"']
|
5
|
+
class DynamicMerger < Filter
|
6
|
+
def on_multi(*exps)
|
7
|
+
exps = exps.dup
|
8
|
+
result = [:multi]
|
9
|
+
buffer = []
|
10
|
+
|
11
|
+
until exps.empty?
|
12
|
+
type, arg = exps.first
|
13
|
+
if type == :dynamic && arg.count("\n") == 0
|
14
|
+
buffer << exps.shift
|
15
|
+
elsif type == :static && exps.size > (count = arg.count("\n")) &&
|
16
|
+
exps[1, count].all? { |e| e == [:newline] }
|
17
|
+
(1 + count).times { buffer << exps.shift }
|
18
|
+
elsif type == :newline && exps.size > (count = count_newline(exps)) &&
|
19
|
+
exps[count].first == :static && count == exps[count].last.count("\n")
|
20
|
+
(count + 1).times { buffer << exps.shift }
|
21
|
+
else
|
22
|
+
result.concat(merge_dynamic(buffer))
|
23
|
+
buffer = []
|
24
|
+
result << compile(exps.shift)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
result.concat(merge_dynamic(buffer))
|
28
|
+
|
29
|
+
result.size == 2 ? result[1] : result
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def merge_dynamic(exps)
|
35
|
+
# Merge exps only when they have both :static and :dynamic
|
36
|
+
unless exps.any? { |type,| type == :static } && exps.any? { |type,| type == :dynamic }
|
37
|
+
return exps
|
38
|
+
end
|
39
|
+
|
40
|
+
strlit_body = String.new
|
41
|
+
exps.each do |type, arg|
|
42
|
+
case type
|
43
|
+
when :static
|
44
|
+
strlit_body << arg.dump.sub!(/\A"/, '').sub!(/"\z/, '').gsub('\n', "\n")
|
45
|
+
when :dynamic
|
46
|
+
strlit_body << "\#{#{arg}}"
|
47
|
+
when :newline
|
48
|
+
# newline is added by `gsub('\n', "\n")`
|
49
|
+
else
|
50
|
+
raise "unexpected type #{type.inspect} is given to #merge_dynamic"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
[[:dynamic, "%Q\0#{strlit_body}\0"]]
|
54
|
+
end
|
55
|
+
|
56
|
+
def count_newline(exps)
|
57
|
+
count = 0
|
58
|
+
exps.each do |exp|
|
59
|
+
if exp == [:newline]
|
60
|
+
count += 1
|
61
|
+
else
|
62
|
+
return count
|
63
|
+
end
|
64
|
+
end
|
65
|
+
return count
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -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('; ')
|
@@ -54,7 +55,9 @@ module Temple
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def on_capture(name, exp)
|
57
|
-
capture_generator.new(
|
58
|
+
capture_generator.new(capture_generator: options[:capture_generator],
|
59
|
+
freeze_static: options[:freeze_static],
|
60
|
+
buffer: name).call(exp)
|
58
61
|
end
|
59
62
|
|
60
63
|
def on_static(text)
|
@@ -76,15 +79,9 @@ module Temple
|
|
76
79
|
end
|
77
80
|
|
78
81
|
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
|
82
|
+
@capture_generator ||= Class === options[:capture_generator] ?
|
83
|
+
options[:capture_generator] :
|
84
|
+
Generators.const_get(options[:capture_generator])
|
88
85
|
end
|
89
86
|
|
90
87
|
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
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'temple/version'
|
2
3
|
|
3
4
|
module Temple
|
@@ -49,6 +50,7 @@ module Temple
|
|
49
50
|
autoload :StaticMerger, 'temple/filters/static_merger'
|
50
51
|
autoload :StringSplitter, 'temple/filters/string_splitter'
|
51
52
|
autoload :DynamicInliner, 'temple/filters/dynamic_inliner'
|
53
|
+
autoload :DynamicMerger, 'temple/filters/dynamic_merger'
|
52
54
|
autoload :Escapable, 'temple/filters/escapable'
|
53
55
|
autoload :Eraser, 'temple/filters/eraser'
|
54
56
|
autoload :Validator, 'temple/filters/validator'
|
data/temple.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
require File.dirname(__FILE__) + '/lib/temple/version'
|
3
2
|
require 'date'
|
4
3
|
|
@@ -13,8 +12,7 @@ Gem::Specification.new do |s|
|
|
13
12
|
s.summary = 'Template compilation framework in Ruby'
|
14
13
|
|
15
14
|
s.require_paths = %w(lib)
|
16
|
-
s.files = `git ls-files`.split("\
|
17
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec)/}) }
|
18
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
17
|
s.license = 'MIT'
|
20
18
|
|