temple 0.2.0 → 0.3.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.
- data/.yardopts +2 -1
- data/CHANGES +63 -0
- data/EXPRESSIONS.md +250 -0
- data/README.md +24 -12
- data/lib/temple.rb +34 -18
- data/lib/temple/engine.rb +11 -7
- data/lib/temple/erb/engine.rb +5 -3
- data/lib/temple/erb/parser.rb +5 -2
- data/lib/temple/erb/template.rb +11 -0
- data/lib/temple/erb/trimming.rb +9 -1
- data/lib/temple/filter.rb +2 -0
- data/lib/temple/filters/control_flow.rb +43 -0
- data/lib/temple/filters/dynamic_inliner.rb +29 -32
- data/lib/temple/filters/eraser.rb +22 -0
- data/lib/temple/filters/escapable.rb +39 -0
- data/lib/temple/filters/multi_flattener.rb +4 -1
- data/lib/temple/filters/static_merger.rb +11 -10
- data/lib/temple/filters/validator.rb +15 -0
- data/lib/temple/generators.rb +41 -100
- data/lib/temple/grammar.rb +56 -0
- data/lib/temple/hash.rb +48 -0
- data/lib/temple/html/dispatcher.rb +10 -4
- data/lib/temple/html/fast.rb +50 -38
- data/lib/temple/html/filter.rb +8 -0
- data/lib/temple/html/pretty.rb +25 -14
- data/lib/temple/mixins/dispatcher.rb +103 -0
- data/lib/temple/{mixins.rb → mixins/engine_dsl.rb} +10 -95
- data/lib/temple/mixins/grammar_dsl.rb +166 -0
- data/lib/temple/mixins/options.rb +28 -0
- data/lib/temple/mixins/template.rb +25 -0
- data/lib/temple/templates.rb +2 -0
- data/lib/temple/utils.rb +11 -57
- data/lib/temple/version.rb +1 -1
- data/test/filters/test_control_flow.rb +92 -0
- data/test/filters/test_dynamic_inliner.rb +7 -7
- data/test/filters/test_eraser.rb +55 -0
- data/test/filters/{test_escape_html.rb → test_escapable.rb} +13 -6
- data/test/filters/test_multi_flattener.rb +1 -1
- data/test/filters/test_static_merger.rb +3 -3
- data/test/helper.rb +8 -0
- data/test/html/test_fast.rb +42 -57
- data/test/html/test_pretty.rb +10 -7
- data/test/mixins/test_dispatcher.rb +31 -0
- data/test/mixins/test_grammar_dsl.rb +86 -0
- data/test/test_engine.rb +73 -57
- data/test/test_erb.rb +0 -7
- data/test/test_filter.rb +26 -0
- data/test/test_generator.rb +57 -36
- data/test/test_grammar.rb +52 -0
- data/test/test_hash.rb +39 -0
- data/test/test_utils.rb +11 -38
- metadata +34 -10
- data/lib/temple/filters/debugger.rb +0 -26
- data/lib/temple/filters/escape_html.rb +0 -33
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Temple::Grammar do
|
4
|
+
it 'should match core expressions' do
|
5
|
+
Temple::Grammar.should.match [:multi]
|
6
|
+
Temple::Grammar.should.match [:multi, [:multi]]
|
7
|
+
Temple::Grammar.should.match [:static, 'Text']
|
8
|
+
Temple::Grammar.should.match [:dynamic, 'Text']
|
9
|
+
Temple::Grammar.should.match [:code, 'Text']
|
10
|
+
Temple::Grammar.should.match [:capture, 'Text', [:multi]]
|
11
|
+
Temple::Grammar.should.match [:newline]
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should not match invalid core expressions' do
|
15
|
+
Temple::Grammar.should.not.match [:multi, 'String']
|
16
|
+
Temple::Grammar.should.not.match [:static]
|
17
|
+
Temple::Grammar.should.not.match [:dynamic, 1]
|
18
|
+
Temple::Grammar.should.not.match [:code, :sym]
|
19
|
+
Temple::Grammar.should.not.match [:capture, [:multi]]
|
20
|
+
Temple::Grammar.should.not.match [:newline, [:multi]]
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should match control flow expressions' do
|
24
|
+
Temple::Grammar.should.match [:if, 'Condition', [:multi]]
|
25
|
+
Temple::Grammar.should.match [:if, 'Condition', [:multi], [:multi]]
|
26
|
+
Temple::Grammar.should.match [:block, 'Loop', [:multi]]
|
27
|
+
Temple::Grammar.should.match [:case, 'Arg', ['Cond1', [:multi]], ['Cond1', [:multi]], [:else, [:multi]]]
|
28
|
+
Temple::Grammar.should.not.match [:case, 'Arg', [:sym, [:multi]]]
|
29
|
+
Temple::Grammar.should.match [:cond, ['Cond1', [:multi]], ['Cond2', [:multi]], [:else, [:multi]]]
|
30
|
+
Temple::Grammar.should.not.match [:cond, [:sym, [:multi]]]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should match escape expression' do
|
34
|
+
Temple::Grammar.should.match [:escape, true, [:multi]]
|
35
|
+
Temple::Grammar.should.match [:escape, false, [:multi]]
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should match html expressions' do
|
39
|
+
Temple::Grammar.should.match [:html, :doctype, 'Doctype']
|
40
|
+
Temple::Grammar.should.match [:html, :comment, [:multi]]
|
41
|
+
Temple::Grammar.should.match [:html, :tag, 'Tag', [:multi]]
|
42
|
+
Temple::Grammar.should.match [:html, :tag, 'Tag', [:multi], [:multi]]
|
43
|
+
Temple::Grammar.should.match [:html, :tag, 'Tag', [:multi], [:static, 'Text']]
|
44
|
+
Temple::Grammar.should.match [:html, :tag, 'Tag', [:html, :attrs, [:html, :attr, 'id',
|
45
|
+
[:static, 'val']]], [:static, 'Text']]
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should not match lone html attributes' do
|
49
|
+
Temple::Grammar.should.not.match [:html, :attr, 'id', [:multi]]
|
50
|
+
Temple::Grammar.should.not.match [:html, :attrs]
|
51
|
+
end
|
52
|
+
end
|
data/test/test_hash.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Temple::ImmutableHash do
|
4
|
+
it 'has read accessor' do
|
5
|
+
hash = Temple::ImmutableHash.new({:a => 1},{:b => 2, :a => 3})
|
6
|
+
hash[:a].should.equal 1
|
7
|
+
hash[:b].should.equal 2
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'has include?' do
|
11
|
+
hash = Temple::ImmutableHash.new({:a => 1},{:b => 2, :a => 3})
|
12
|
+
hash.should.include :a
|
13
|
+
hash.should.include :b
|
14
|
+
hash.should.not.include :c
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has values' do
|
18
|
+
Temple::ImmutableHash.new({:a => 1},{:b => 2, :a => 3}).values.sort.should.equal [1,2]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'has keys' do
|
22
|
+
Temple::ImmutableHash.new({:a => 1},{:b => 2, :a => 3}).keys.should.equal [:a,:b]
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'has to_a' do
|
26
|
+
Temple::ImmutableHash.new({:a => 1},{:b => 2, :a => 3}).to_a.should.equal [[:a, 1], [:b, 2]]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe Temple::MutableHash do
|
31
|
+
it 'has write accessor' do
|
32
|
+
parent = {:a => 1}
|
33
|
+
hash = Temple::MutableHash.new(parent)
|
34
|
+
hash[:a].should.equal 1
|
35
|
+
hash[:a] = 2
|
36
|
+
hash[:a].should.equal 2
|
37
|
+
parent[:a].should.equal 1
|
38
|
+
end
|
39
|
+
end
|
data/test/test_utils.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
+
class UniqueTest
|
4
|
+
include Temple::Utils
|
5
|
+
end
|
6
|
+
|
3
7
|
describe Temple::Utils do
|
4
8
|
it 'has empty_exp?' do
|
5
9
|
Temple::Utils.empty_exp?([:multi]).should.be.true
|
@@ -10,6 +14,13 @@ describe Temple::Utils do
|
|
10
14
|
Temple::Utils.empty_exp?([:multi, [:newline], [:multi, [:dynamic, 'text']]]).should.be.false
|
11
15
|
end
|
12
16
|
|
17
|
+
it 'has unique_name' do
|
18
|
+
u = UniqueTest.new
|
19
|
+
u.unique_name.should.equal '_uniquetest1'
|
20
|
+
u.unique_name.should.equal '_uniquetest2'
|
21
|
+
UniqueTest.new.unique_name.should.equal '_uniquetest1'
|
22
|
+
end
|
23
|
+
|
13
24
|
it 'has escape_html' do
|
14
25
|
Temple::Utils.escape_html('<').should.equal '<'
|
15
26
|
end
|
@@ -26,41 +37,3 @@ describe Temple::Utils do
|
|
26
37
|
end
|
27
38
|
end
|
28
39
|
end
|
29
|
-
|
30
|
-
describe Temple::Utils::ImmutableHash do
|
31
|
-
it 'has read accessor' do
|
32
|
-
hash = Temple::Utils::ImmutableHash.new({:a => 1},{:b => 2, :a => 3})
|
33
|
-
hash[:a].should.equal 1
|
34
|
-
hash[:b].should.equal 2
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'has include?' do
|
38
|
-
hash = Temple::Utils::ImmutableHash.new({:a => 1},{:b => 2, :a => 3})
|
39
|
-
hash.should.include :a
|
40
|
-
hash.should.include :b
|
41
|
-
hash.should.not.include :c
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'has values' do
|
45
|
-
Temple::Utils::ImmutableHash.new({:a => 1},{:b => 2, :a => 3}).values.sort.should.equal [1,2]
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'has keys' do
|
49
|
-
Temple::Utils::ImmutableHash.new({:a => 1},{:b => 2, :a => 3}).keys.should.equal [:a,:b]
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'has to_a' do
|
53
|
-
Temple::Utils::ImmutableHash.new({:a => 1},{:b => 2, :a => 3}).to_a.should.equal [[:a, 1], [:b, 2]]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe Temple::Utils::MutableHash do
|
58
|
-
it 'has write accessor' do
|
59
|
-
parent = {:a => 1}
|
60
|
-
hash = Temple::Utils::MutableHash.new(parent)
|
61
|
-
hash[:a].should.equal 1
|
62
|
-
hash[:a] = 2
|
63
|
-
hash[:a].should.equal 2
|
64
|
-
parent[:a].should.equal 1
|
65
|
-
end
|
66
|
-
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: temple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Magnus Holm
|
@@ -11,8 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-
|
15
|
-
default_executable:
|
14
|
+
date: 2011-05-15 00:00:00 Z
|
16
15
|
dependencies:
|
17
16
|
- !ruby/object:Gem::Dependency
|
18
17
|
name: tilt
|
@@ -49,6 +48,8 @@ extra_rdoc_files: []
|
|
49
48
|
files:
|
50
49
|
- .gitignore
|
51
50
|
- .yardopts
|
51
|
+
- CHANGES
|
52
|
+
- EXPRESSIONS.md
|
52
53
|
- LICENSE
|
53
54
|
- README.md
|
54
55
|
- Rakefile
|
@@ -56,36 +57,52 @@ files:
|
|
56
57
|
- lib/temple/engine.rb
|
57
58
|
- lib/temple/erb/engine.rb
|
58
59
|
- lib/temple/erb/parser.rb
|
60
|
+
- lib/temple/erb/template.rb
|
59
61
|
- lib/temple/erb/trimming.rb
|
60
62
|
- lib/temple/filter.rb
|
61
|
-
- lib/temple/filters/
|
63
|
+
- lib/temple/filters/control_flow.rb
|
62
64
|
- lib/temple/filters/dynamic_inliner.rb
|
63
|
-
- lib/temple/filters/
|
65
|
+
- lib/temple/filters/eraser.rb
|
66
|
+
- lib/temple/filters/escapable.rb
|
64
67
|
- lib/temple/filters/multi_flattener.rb
|
65
68
|
- lib/temple/filters/static_merger.rb
|
69
|
+
- lib/temple/filters/validator.rb
|
66
70
|
- lib/temple/generators.rb
|
71
|
+
- lib/temple/grammar.rb
|
72
|
+
- lib/temple/hash.rb
|
67
73
|
- lib/temple/html/dispatcher.rb
|
68
74
|
- lib/temple/html/fast.rb
|
75
|
+
- lib/temple/html/filter.rb
|
69
76
|
- lib/temple/html/pretty.rb
|
70
|
-
- lib/temple/mixins.rb
|
77
|
+
- lib/temple/mixins/dispatcher.rb
|
78
|
+
- lib/temple/mixins/engine_dsl.rb
|
79
|
+
- lib/temple/mixins/grammar_dsl.rb
|
80
|
+
- lib/temple/mixins/options.rb
|
81
|
+
- lib/temple/mixins/template.rb
|
71
82
|
- lib/temple/templates.rb
|
72
83
|
- lib/temple/templates/rails.rb
|
73
84
|
- lib/temple/templates/tilt.rb
|
74
85
|
- lib/temple/utils.rb
|
75
86
|
- lib/temple/version.rb
|
76
87
|
- temple.gemspec
|
88
|
+
- test/filters/test_control_flow.rb
|
77
89
|
- test/filters/test_dynamic_inliner.rb
|
78
|
-
- test/filters/
|
90
|
+
- test/filters/test_eraser.rb
|
91
|
+
- test/filters/test_escapable.rb
|
79
92
|
- test/filters/test_multi_flattener.rb
|
80
93
|
- test/filters/test_static_merger.rb
|
81
94
|
- test/helper.rb
|
82
95
|
- test/html/test_fast.rb
|
83
96
|
- test/html/test_pretty.rb
|
97
|
+
- test/mixins/test_dispatcher.rb
|
98
|
+
- test/mixins/test_grammar_dsl.rb
|
84
99
|
- test/test_engine.rb
|
85
100
|
- test/test_erb.rb
|
101
|
+
- test/test_filter.rb
|
86
102
|
- test/test_generator.rb
|
103
|
+
- test/test_grammar.rb
|
104
|
+
- test/test_hash.rb
|
87
105
|
- test/test_utils.rb
|
88
|
-
has_rdoc: true
|
89
106
|
homepage: http://dojo.rubyforge.org/
|
90
107
|
licenses: []
|
91
108
|
|
@@ -109,19 +126,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
126
|
requirements: []
|
110
127
|
|
111
128
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.
|
129
|
+
rubygems_version: 1.8.2
|
113
130
|
signing_key:
|
114
131
|
specification_version: 3
|
115
132
|
summary: Template compilation framework in Ruby
|
116
133
|
test_files:
|
134
|
+
- test/filters/test_control_flow.rb
|
117
135
|
- test/filters/test_dynamic_inliner.rb
|
118
|
-
- test/filters/
|
136
|
+
- test/filters/test_eraser.rb
|
137
|
+
- test/filters/test_escapable.rb
|
119
138
|
- test/filters/test_multi_flattener.rb
|
120
139
|
- test/filters/test_static_merger.rb
|
121
140
|
- test/helper.rb
|
122
141
|
- test/html/test_fast.rb
|
123
142
|
- test/html/test_pretty.rb
|
143
|
+
- test/mixins/test_dispatcher.rb
|
144
|
+
- test/mixins/test_grammar_dsl.rb
|
124
145
|
- test/test_engine.rb
|
125
146
|
- test/test_erb.rb
|
147
|
+
- test/test_filter.rb
|
126
148
|
- test/test_generator.rb
|
149
|
+
- test/test_grammar.rb
|
150
|
+
- test/test_hash.rb
|
127
151
|
- test/test_utils.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Temple
|
2
|
-
module Filters
|
3
|
-
# Filter which prints Temple expression
|
4
|
-
class Debugger < Filter
|
5
|
-
default_options[:debug_pretty] = true
|
6
|
-
|
7
|
-
def initialize(opts = {})
|
8
|
-
super
|
9
|
-
require 'pp' if options[:debug_pretty]
|
10
|
-
end
|
11
|
-
|
12
|
-
def call(exp)
|
13
|
-
if options[:debug]
|
14
|
-
puts options[:debug_prefix] if options[:debug_prefix]
|
15
|
-
if options[:debug_pretty]
|
16
|
-
pp exp
|
17
|
-
else
|
18
|
-
p exp
|
19
|
-
end
|
20
|
-
puts
|
21
|
-
end
|
22
|
-
exp
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Temple
|
2
|
-
module Filters
|
3
|
-
class EscapeHTML < Filter
|
4
|
-
include Temple::HTML::Dispatcher
|
5
|
-
|
6
|
-
temple_dispatch :html
|
7
|
-
|
8
|
-
# Activate the usage of html_safe? if it is available (for Rails 3 for example)
|
9
|
-
default_options[:use_html_safe] = ''.respond_to?(:html_safe?)
|
10
|
-
|
11
|
-
def initialize(opts = {})
|
12
|
-
super
|
13
|
-
@escape = false
|
14
|
-
end
|
15
|
-
|
16
|
-
def on_escape(flag, exp)
|
17
|
-
old = @escape
|
18
|
-
@escape = flag
|
19
|
-
compile(exp)
|
20
|
-
ensure
|
21
|
-
@escape = old
|
22
|
-
end
|
23
|
-
|
24
|
-
def on_static(value)
|
25
|
-
[:static, @escape ? (options[:use_html_safe] ? escape_html_safe(value) : escape_html(value)) : value]
|
26
|
-
end
|
27
|
-
|
28
|
-
def on_dynamic(value)
|
29
|
-
[:dynamic, @escape ? "Temple::Utils.escape_html#{options[:use_html_safe] ? '_safe' : ''}((#{value}))" : value]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|