express_templates 0.3.0 → 0.3.1
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 +4 -4
- data/lib/express_templates/compiler.rb +2 -2
- data/lib/express_templates/components/capabilities/parenting.rb +1 -1
- data/lib/express_templates/components/capabilities/templating.rb +1 -1
- data/lib/express_templates/components/content_for.rb +7 -5
- data/lib/express_templates/interpolator.rb +36 -0
- data/lib/express_templates/markup/tag.rb +1 -7
- data/lib/express_templates/markup/wrapper.rb +15 -9
- data/lib/express_templates/version.rb +1 -1
- data/lib/express_templates.rb +1 -0
- data/test/components/base_test.rb +1 -1
- data/test/components/conditionality_test.rb +1 -1
- data/test/components/iterating_test.rb +8 -5
- data/test/dummy/log/test.log +15882 -0
- data/test/expander_test.rb +3 -2
- data/test/interpolator_test.rb +80 -0
- data/test/markup/tag_test.rb +4 -2
- data/test/markup/wrapper_test.rb +8 -8
- data/test/performance_test.rb +15 -15
- data/test/test_helper.rb +1 -0
- metadata +19 -2
data/test/expander_test.rb
CHANGED
@@ -84,11 +84,12 @@ class ExpanderTest < ActiveSupport::TestCase
|
|
84
84
|
foo
|
85
85
|
end
|
86
86
|
end
|
87
|
-
assert_equal %q(
|
87
|
+
assert_equal %q(%Q(#{helper do
|
88
88
|
foo
|
89
|
-
end}
|
89
|
+
end})), Interpolator.transform(result.first.compile)
|
90
90
|
end
|
91
91
|
|
92
|
+
# NOTE: This probably should be deleted as {{helper}} is preferred
|
92
93
|
test "non-interpolated string children containing string interpolations will interpolate in context" do
|
93
94
|
source = 'p %q(some text #{helper})'
|
94
95
|
result = ExpressTemplates::Expander.new(nil).expand(source)
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'express_templates/interpolator'
|
3
|
+
require 'parslet/convenience'
|
4
|
+
|
5
|
+
class InterpolatorTest < ActiveSupport::TestCase
|
6
|
+
|
7
|
+
def parse(s)
|
8
|
+
parser = ExpressTemplates::Interpolator.new
|
9
|
+
parsed = parser.parse_with_debug(s)
|
10
|
+
pp parsed if ENV['DEBUG'].eql?('true')
|
11
|
+
parsed
|
12
|
+
end
|
13
|
+
|
14
|
+
def transform(s)
|
15
|
+
trans = ExpressTemplates::Transformer.new
|
16
|
+
trans.apply(parse(s)).flatten.join
|
17
|
+
end
|
18
|
+
|
19
|
+
test "simplest expression parses" do
|
20
|
+
tree = parse("{{something}}")
|
21
|
+
expected = [{:interpolation=>{:expression=>[{:text=>"something"}]}}]
|
22
|
+
assert_equal expected, tree
|
23
|
+
end
|
24
|
+
|
25
|
+
test "simple expression with surrounding text parses" do
|
26
|
+
tree = parse('whatever {{something}} something else')
|
27
|
+
expected = [{:text=>"whatever "},
|
28
|
+
{:interpolation=>{:expression=>[{:text=>"something"}]}},
|
29
|
+
{:text=>" something else"}]
|
30
|
+
assert_equal expected, tree
|
31
|
+
end
|
32
|
+
|
33
|
+
test "nested without outer text parses" do
|
34
|
+
tree = parse('{{some {{thing}} foo}}')
|
35
|
+
expected = [{:interpolation=>
|
36
|
+
{:expression=>
|
37
|
+
[{:text=>"some "},
|
38
|
+
{:interpolation=>{:expression=>[{:text=>"thing"}]}},
|
39
|
+
{:text=>" foo"}]}}]
|
40
|
+
assert_equal expected, tree
|
41
|
+
end
|
42
|
+
|
43
|
+
test "nested with outer text parses" do
|
44
|
+
tree = parse('a lot of {{something {{good}}}}')
|
45
|
+
expected = [{:text=>"a lot of "},
|
46
|
+
{:interpolation=>
|
47
|
+
{:expression=>
|
48
|
+
[{:text=>"something "},
|
49
|
+
{:interpolation=>{:expression=>[{:text=>"good"}]}}]}}]
|
50
|
+
assert_equal expected, tree
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'nested with multiple nested expressions parses' do
|
54
|
+
tree = parse(%q(%Q({{foo("{{xyz}}", "{{zyx}}", bar: "baz")}})))
|
55
|
+
expected = [{:text=>"%Q("},
|
56
|
+
{:interpolation=>
|
57
|
+
{:expression=>
|
58
|
+
[{:text=>"foo(\""},
|
59
|
+
{:interpolation=>{:expression=>[{:text=>"xyz"}]}},
|
60
|
+
{:text=>"\", \""},
|
61
|
+
{:interpolation=>{:expression=>[{:text=>"zyx"}]}},
|
62
|
+
{:text=>"\", bar: \"baz\")"}]}},
|
63
|
+
{:text=>")"}]
|
64
|
+
assert_equal expected, tree
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
test '"{{something}}" transforms to "#{something}"' do
|
69
|
+
assert_equal '#{something}', transform("{{something}}")
|
70
|
+
end
|
71
|
+
|
72
|
+
test '"{{some {{thing}} foo}}" transforms to "#{some #{thing} foo}"' do
|
73
|
+
assert_equal '#{some #{thing} foo}', transform("{{some {{thing}} foo}}")
|
74
|
+
end
|
75
|
+
|
76
|
+
test %('a lot of {{something "{{good}}"}}' transforms) do
|
77
|
+
assert_equal 'a lot of #{something "#{good}"}', transform('a lot of {{something "{{good}}"}}')
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/test/markup/tag_test.rb
CHANGED
@@ -78,11 +78,13 @@ class TagTest < ActiveSupport::TestCase
|
|
78
78
|
end
|
79
79
|
|
80
80
|
test "double bracketed option values are substituted for evaluation in context" do
|
81
|
-
assert_equal '"<bare should_eval_in_context=\"#{foo}\" />"',
|
81
|
+
assert_equal '"<bare should_eval_in_context=\"#{foo}\" />"',
|
82
|
+
Interpolator.transform(bare_tag(should_eval_in_context: "{{foo}}").compile)
|
82
83
|
end
|
83
84
|
|
84
85
|
test "double bracketed child values are substituted for evaluation in context" do
|
85
|
-
assert_equal '"<bare>"+"#{foo}"+"</bare>"',
|
86
|
+
assert_equal '"<bare>"+"#{foo}"+"</bare>"',
|
87
|
+
Interpolator.transform(bare_tag("{{foo}}").compile)
|
86
88
|
end
|
87
89
|
|
88
90
|
test "data option value hashes are converted to data attributes similar to haml" do
|
data/test/markup/wrapper_test.rb
CHANGED
@@ -5,38 +5,38 @@ class WrapperTest < ActiveSupport::TestCase
|
|
5
5
|
Wrapper = ExpressTemplates::Markup::Wrapper
|
6
6
|
|
7
7
|
test "name compiles to just name" do
|
8
|
-
assert_equal '
|
8
|
+
assert_equal '%Q(#{foo})', Interpolator.transform(Wrapper.new('foo').compile)
|
9
9
|
end
|
10
10
|
|
11
11
|
test "simple args are preserved" do
|
12
12
|
wrapper = Wrapper.new('foo', "xyzzy", 'bar', "baz", 1, false, 3)
|
13
|
-
assert_equal '
|
13
|
+
assert_equal '%Q(#{foo("xyzzy", "bar", "baz", 1, false, 3)})', Interpolator.transform(wrapper.compile)
|
14
14
|
end
|
15
15
|
|
16
16
|
test "args are preserved" do
|
17
17
|
wrapper = Wrapper.new('foo', "xyzzy", bar: "baz")
|
18
|
-
assert_equal '
|
18
|
+
assert_equal '%Q(#{foo("xyzzy", bar: "baz")})', Interpolator.transform(wrapper.compile)
|
19
19
|
end
|
20
20
|
|
21
21
|
test "something returning nil when wrapped and compiled, evals to an empty string" do
|
22
|
-
assert_equal '', eval(Wrapper.new('nil').compile)
|
22
|
+
assert_equal '', eval(Interpolator.transform(Wrapper.new('nil').compile))
|
23
23
|
end
|
24
24
|
|
25
25
|
test "double-braced args are evaluated in context" do
|
26
26
|
wrapper = Wrapper.new('foo', "{{xyz}}", "{{zyx}}", bar: "baz")
|
27
|
-
assert_equal '
|
27
|
+
assert_equal '%Q(#{foo(xyz, zyx, bar: "baz")})', Interpolator.transform(wrapper.compile)
|
28
28
|
end
|
29
29
|
|
30
30
|
test "initializer block is preserved in compile" do
|
31
31
|
wrapper = Wrapper.new('foo') { whatever }
|
32
|
-
assert_equal '
|
32
|
+
assert_equal '%Q(#{foo { whatever }})', Interpolator.transform(wrapper.compile)
|
33
33
|
wrapper = Wrapper.new('foo', 'bar') { whatever }
|
34
|
-
assert_equal '
|
34
|
+
assert_equal '%Q(#{foo("bar") { whatever }})', Interpolator.transform(wrapper.compile)
|
35
35
|
end
|
36
36
|
|
37
37
|
test "lambda option values are evaluated in context" do
|
38
38
|
wrapper = Wrapper.new('foo', bar: -> { something })
|
39
|
-
assert_equal '
|
39
|
+
assert_equal '%Q(#{foo(bar: (-> { something }).call)})', Interpolator.transform(wrapper.compile)
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
data/test/performance_test.rb
CHANGED
@@ -71,23 +71,23 @@ HAML
|
|
71
71
|
return end_time - start_time
|
72
72
|
end
|
73
73
|
|
74
|
-
test "performance is okay" do
|
75
|
-
|
76
|
-
|
77
|
-
end
|
74
|
+
# test "performance is okay" do
|
75
|
+
# duration = time(100) { ExpressTemplates.render(self, "#{GARA_EXAMPLE}") }
|
76
|
+
# assert_operator 1.0, :>, duration
|
77
|
+
# end
|
78
78
|
|
79
|
-
test "performance no more than 3.5x slower than erubis" do
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
79
|
+
# test "performance no more than 3.5x slower than erubis" do
|
80
|
+
# eruby = Erubis::Eruby.new
|
81
|
+
# duration_erb = time(100) { eval(eruby.convert(ERB_EXAMPLE)) }
|
82
|
+
# duration_express_templates = time(100) { ExpressTemplates.render(self, "#{GARA_EXAMPLE}") }
|
83
|
+
# assert_operator 4.0, :>, (duration_express_templates/duration_erb)
|
84
|
+
# end
|
85
85
|
|
86
|
-
test "performance better than haml" do
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
86
|
+
# test "performance better than haml" do
|
87
|
+
# duration_haml = time(100) { Haml::Engine.new(HAML_EXAMPLE).render(self) }
|
88
|
+
# duration_express_templates = time(100) { ExpressTemplates.render(self, "#{GARA_EXAMPLE}") }
|
89
|
+
# assert_operator 0.5, :>, (duration_express_templates/duration_haml)
|
90
|
+
# end
|
91
91
|
|
92
92
|
end
|
93
93
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: express_templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Talcott Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: parslet
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rails
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -160,6 +174,7 @@ files:
|
|
160
174
|
- lib/express_templates/components/unless_block.rb
|
161
175
|
- lib/express_templates/expander.rb
|
162
176
|
- lib/express_templates/indenter.rb
|
177
|
+
- lib/express_templates/interpolator.rb
|
163
178
|
- lib/express_templates/macro.rb
|
164
179
|
- lib/express_templates/markup.rb
|
165
180
|
- lib/express_templates/markup/html_tag.rb
|
@@ -242,6 +257,7 @@ files:
|
|
242
257
|
- test/fixtures/a_big_page2.html
|
243
258
|
- test/handler_test.rb
|
244
259
|
- test/indenter_test.rb
|
260
|
+
- test/interpolator_test.rb
|
245
261
|
- test/markup/tag_test.rb
|
246
262
|
- test/markup/wrapper_test.rb
|
247
263
|
- test/markup/yielder_test.rb
|
@@ -344,6 +360,7 @@ test_files:
|
|
344
360
|
- test/fixtures/a_big_page2.html
|
345
361
|
- test/handler_test.rb
|
346
362
|
- test/indenter_test.rb
|
363
|
+
- test/interpolator_test.rb
|
347
364
|
- test/markup/tag_test.rb
|
348
365
|
- test/markup/wrapper_test.rb
|
349
366
|
- test/markup/yielder_test.rb
|