temple 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +4 -0
- data/lib/temple/engine.rb +5 -1
- data/lib/temple/erb/trimming.rb +11 -26
- data/lib/temple/mixins/engine_dsl.rb +12 -61
- data/lib/temple/version.rb +1 -1
- data/temple.gemspec +1 -0
- data/test/helper.rb +4 -0
- data/test/test_erb.rb +6 -7
- metadata +18 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a5698e0987714d41aa759069655a1c276a5aab1
|
4
|
+
data.tar.gz: 58ae7b8dca8c28264ae03e9136e017f8a6c2efbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b50a65d9d25973bf7470b3cc5d835bce94ff386e886570a3b6d9412b3aea312bf791bc70a6203025515a902dbe25a554d9ecf7f7ea81dcdf16322d6997e3b06a
|
7
|
+
data.tar.gz: c2e805cd2ba16d0a27af4686f0b50df4f2013b4ad146284ba952b1fe0146d4ff31d4c3954655d979ffb907b0c4eb1a4e1b81f966dbd96a5756ebc35115c80b49
|
data/CHANGES
CHANGED
data/lib/temple/engine.rb
CHANGED
@@ -57,7 +57,11 @@ module Temple
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def call_chain
|
60
|
-
@call_chain ||= @chain.map
|
60
|
+
@call_chain ||= @chain.map do |name, constructor|
|
61
|
+
f = constructor.call(self)
|
62
|
+
raise "Constructor #{name} must return callable object" if f && !f.respond_to?(:call)
|
63
|
+
f
|
64
|
+
end.compact
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
data/lib/temple/erb/trimming.rb
CHANGED
@@ -1,38 +1,23 @@
|
|
1
1
|
module Temple
|
2
2
|
module ERB
|
3
|
-
# ERB trimming
|
4
|
-
#
|
5
|
-
# <> - omit newline for lines starting with <% and ending in %>
|
6
|
-
# > - omit newline for lines ending in %>
|
7
|
-
#
|
3
|
+
# ERB trimming like in erubis
|
4
|
+
# Deletes spaces around '<% %>' and leave spaces around '<%= %>'.
|
8
5
|
# @api public
|
9
6
|
class Trimming < Filter
|
10
|
-
define_options :
|
7
|
+
define_options trim: true
|
11
8
|
|
12
9
|
def on_multi(*exps)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
exps = exps.each_with_index.map do |e,i|
|
11
|
+
if e.first == :static && i > 0 && exps[i-1].first == :code
|
12
|
+
[:static, e.last.lstrip]
|
13
|
+
elsif e.first == :static && i < exps.size-1 && exps[i+1].first == :code
|
14
|
+
[:static, e.last.rstrip]
|
15
|
+
else
|
16
|
+
e
|
19
17
|
end
|
20
|
-
|
21
|
-
i = 0
|
22
|
-
while i < exps.size
|
23
|
-
exps.delete_at(i + 1) if code?(exps[i]) && exps[i+1] == [:static, "\n"] &&
|
24
|
-
(!exps[i-1] || (exps[i-1] == [:newline]))
|
25
|
-
i += 1
|
26
|
-
end
|
27
|
-
end
|
18
|
+
end if options[:trim]
|
28
19
|
[:multi, *exps]
|
29
20
|
end
|
30
|
-
|
31
|
-
protected
|
32
|
-
|
33
|
-
def code?(exp)
|
34
|
-
exp[0] == :escape || exp[0] == :code
|
35
|
-
end
|
36
21
|
end
|
37
22
|
end
|
38
23
|
end
|
@@ -17,15 +17,7 @@ module Temple
|
|
17
17
|
|
18
18
|
def remove(name)
|
19
19
|
name = chain_name(name)
|
20
|
-
found
|
21
|
-
chain.reject! do |i|
|
22
|
-
if i.first == name
|
23
|
-
found = true
|
24
|
-
else
|
25
|
-
false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
raise "#{name} not found" unless found
|
20
|
+
raise "#{name} not found" unless chain.reject! {|i| i.first == name }
|
29
21
|
chain_modified!
|
30
22
|
end
|
31
23
|
|
@@ -34,47 +26,24 @@ module Temple
|
|
34
26
|
def before(name, *args, &block)
|
35
27
|
name = chain_name(name)
|
36
28
|
e = chain_element(args, block)
|
37
|
-
|
38
|
-
|
39
|
-
if chain[i].first == name
|
40
|
-
found = true
|
41
|
-
chain.insert(i, e)
|
42
|
-
i += 2
|
43
|
-
else
|
44
|
-
i += 1
|
45
|
-
end
|
46
|
-
end
|
47
|
-
raise "#{name} not found" unless found
|
29
|
+
chain.map! {|f| f.first == name ? [e, f] : [f] }.flatten!(1)
|
30
|
+
raise "#{name} not found" unless chain.include?(e)
|
48
31
|
chain_modified!
|
49
32
|
end
|
50
33
|
|
51
34
|
def after(name, *args, &block)
|
52
35
|
name = chain_name(name)
|
53
36
|
e = chain_element(args, block)
|
54
|
-
|
55
|
-
|
56
|
-
if chain[i].first == name
|
57
|
-
found = true
|
58
|
-
i += 1
|
59
|
-
chain.insert(i, e)
|
60
|
-
end
|
61
|
-
i += 1
|
62
|
-
end
|
63
|
-
raise "#{name} not found" unless found
|
37
|
+
chain.map! {|f| f.first == name ? [f, e] : [f] }.flatten!(1)
|
38
|
+
raise "#{name} not found" unless chain.include?(e)
|
64
39
|
chain_modified!
|
65
40
|
end
|
66
41
|
|
67
42
|
def replace(name, *args, &block)
|
68
43
|
name = chain_name(name)
|
69
44
|
e = chain_element(args, block)
|
70
|
-
|
71
|
-
|
72
|
-
if c.first == name
|
73
|
-
found = true
|
74
|
-
chain[i] = e
|
75
|
-
end
|
76
|
-
end
|
77
|
-
raise "#{name} not found" unless found
|
45
|
+
chain.map! {|f| f.first == name ? e : f }
|
46
|
+
raise "#{name} not found" unless chain.include?(e)
|
78
47
|
chain_modified!
|
79
48
|
end
|
80
49
|
|
@@ -108,28 +77,9 @@ module Temple
|
|
108
77
|
def chain_proc_constructor(name, filter)
|
109
78
|
raise(ArgumentError, 'Proc or blocks must have arity 0 or 1') if filter.arity > 1
|
110
79
|
method_name = "FILTER #{name}"
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
if filter.arity == 1
|
115
|
-
proc {|engine| filter.bind(engine) }
|
116
|
-
else
|
117
|
-
proc do |engine|
|
118
|
-
f = filter.bind(engine).call
|
119
|
-
raise 'Constructor must return callable object' unless f.respond_to?(:call)
|
120
|
-
f
|
121
|
-
end
|
122
|
-
end
|
123
|
-
else
|
124
|
-
(class << self; self; end).class_eval { define_method(method_name, &filter) }
|
125
|
-
filter = method(method_name)
|
126
|
-
proc {|engine| filter }
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def chain_callable_constructor(filter)
|
131
|
-
raise(ArgumentError, 'Class or callable argument is required') unless filter.respond_to?(:call)
|
132
|
-
proc {|engine| filter }
|
80
|
+
c = Class === self ? self : singleton_class
|
81
|
+
filter = c.class_eval { define_method(method_name, &filter); instance_method(method_name) }
|
82
|
+
proc {|engine| filter.arity == 1 ? filter.bind(engine) : filter.bind(engine).call }
|
133
83
|
end
|
134
84
|
|
135
85
|
def chain_element(args, block)
|
@@ -164,7 +114,8 @@ module Temple
|
|
164
114
|
# Other callable argument (e.g. Object of class which implements #call or Method)
|
165
115
|
# The callable has no access to the option hash of the engine.
|
166
116
|
raise(ArgumentError, 'Too many arguments') unless args.empty?
|
167
|
-
|
117
|
+
raise(ArgumentError, 'Class or callable argument is required') unless filter.respond_to?(:call)
|
118
|
+
[name, proc { filter }]
|
168
119
|
end
|
169
120
|
end
|
170
121
|
end
|
data/lib/temple/version.rb
CHANGED
data/temple.gemspec
CHANGED
data/test/helper.rb
CHANGED
data/test/test_erb.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
|
-
require '
|
3
|
-
require 'tilt'
|
2
|
+
require 'tilt/erubis'
|
4
3
|
|
5
4
|
describe Temple::ERB::Engine do
|
6
5
|
it 'should compile erb' do
|
@@ -12,7 +11,7 @@ describe Temple::ERB::Engine do
|
|
12
11
|
<% end %>
|
13
12
|
}
|
14
13
|
|
15
|
-
erb(src).should.equal
|
14
|
+
erb(src).should.equal erubis(src)
|
16
15
|
end
|
17
16
|
|
18
17
|
it 'should recognize comments' do
|
@@ -21,7 +20,7 @@ hello
|
|
21
20
|
<%# comment -- ignored -- useful in testing %>
|
22
21
|
world}
|
23
22
|
|
24
|
-
erb(src).should.equal
|
23
|
+
erb(src).should.equal erubis(src)
|
25
24
|
end
|
26
25
|
|
27
26
|
it 'should recognize <%% and %%>' do
|
@@ -32,7 +31,7 @@ world}
|
|
32
31
|
<% end %>
|
33
32
|
}
|
34
33
|
|
35
|
-
erb(src).should.equal "\n<%\n
|
34
|
+
erb(src).should.equal "\n<%\n %>\n"
|
36
35
|
end
|
37
36
|
|
38
37
|
it 'should escape automatically' do
|
@@ -56,7 +55,7 @@ world}
|
|
56
55
|
<% end %>
|
57
56
|
}
|
58
57
|
|
59
|
-
erb(src,
|
60
|
-
erb(src,
|
58
|
+
erb(src, trim: true).should.equal erubis(src, trim: true)
|
59
|
+
erb(src, trim: false).should.equal erubis(src, trim: false)
|
61
60
|
end
|
62
61
|
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.7.
|
4
|
+
version: 0.7.3
|
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: 2014-12-
|
12
|
+
date: 2014-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tilt
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: erubis
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
description:
|
57
71
|
email:
|
58
72
|
- judofyr@gmail.com
|
@@ -162,26 +176,5 @@ rubygems_version: 2.2.2
|
|
162
176
|
signing_key:
|
163
177
|
specification_version: 4
|
164
178
|
summary: Template compilation framework in Ruby
|
165
|
-
test_files:
|
166
|
-
|
167
|
-
- test/filters/test_control_flow.rb
|
168
|
-
- test/filters/test_dynamic_inliner.rb
|
169
|
-
- test/filters/test_eraser.rb
|
170
|
-
- test/filters/test_escapable.rb
|
171
|
-
- test/filters/test_multi_flattener.rb
|
172
|
-
- test/filters/test_static_merger.rb
|
173
|
-
- test/helper.rb
|
174
|
-
- test/html/test_attribute_merger.rb
|
175
|
-
- test/html/test_attribute_remover.rb
|
176
|
-
- test/html/test_attribute_sorter.rb
|
177
|
-
- test/html/test_fast.rb
|
178
|
-
- test/html/test_pretty.rb
|
179
|
-
- test/mixins/test_dispatcher.rb
|
180
|
-
- test/mixins/test_grammar_dsl.rb
|
181
|
-
- test/test_engine.rb
|
182
|
-
- test/test_erb.rb
|
183
|
-
- test/test_filter.rb
|
184
|
-
- test/test_generator.rb
|
185
|
-
- test/test_grammar.rb
|
186
|
-
- test/test_map.rb
|
187
|
-
- test/test_utils.rb
|
179
|
+
test_files: []
|
180
|
+
has_rdoc:
|