hotcell 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +102 -84
- data/Rakefile +2 -2
- data/ext/lexerc/lexerc.c +350 -308
- data/ext/lexerc/lexerc.h +2 -7
- data/ext/lexerc/lexerc.rl +9 -90
- data/lib/hotcell/commands/for.rb +7 -2
- data/lib/hotcell/config.rb +2 -1
- data/lib/hotcell/extensions.rb +13 -1
- data/lib/hotcell/lexer.rb +5 -10
- data/lib/hotcell/lexer.rl +95 -0
- data/lib/hotcell/lexerr.rb +256 -215
- data/lib/hotcell/lexerr.rl +7 -91
- data/lib/hotcell/manipulator.rb +20 -2
- data/lib/hotcell/node/{calculator.rb → expression.rb} +4 -2
- data/lib/hotcell/node/tag.rb +5 -3
- data/lib/hotcell/node.rb +1 -1
- data/lib/hotcell/parser.rb +565 -514
- data/lib/hotcell/parser.y +46 -24
- data/lib/hotcell/template.rb +3 -2
- data/lib/hotcell/version.rb +1 -1
- data/lib/hotcell.rb +1 -1
- data/spec/lib/hotcell/commands/for_spec.rb +3 -0
- data/spec/lib/hotcell/config_spec.rb +6 -0
- data/spec/lib/hotcell/lexer_spec.rb +28 -17
- data/spec/lib/hotcell/manipulator_spec.rb +16 -11
- data/spec/lib/hotcell/node/block_spec.rb +2 -2
- data/spec/lib/hotcell/parser_spec.rb +113 -30
- data/spec/lib/hotcell/template_spec.rb +51 -1
- data/spec/lib/hotcell_spec.rb +1 -0
- metadata +4 -3
@@ -8,7 +8,8 @@ describe Hotcell::Template do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
specify { described_class.parse('').should be_a described_class }
|
11
|
-
specify { described_class.parse(''
|
11
|
+
specify { described_class.parse(''
|
12
|
+
).options.slice(:commands, :blocks).values.map(&:keys).should == [['include'], ['for']] }
|
12
13
|
end
|
13
14
|
|
14
15
|
describe '#syntax' do
|
@@ -80,5 +81,54 @@ describe Hotcell::Template do
|
|
80
81
|
{{ end for }}
|
81
82
|
SOURCE
|
82
83
|
).render.gsub(/[\s\n]+/, ' ').strip.should == '4 3 2 1 8 6 4 2 12 9 6 3 16 12 8 4' }
|
84
|
+
|
85
|
+
context 'method invokation' do
|
86
|
+
specify { described_class.parse("{{ [1, 2, 3][1] }}").render.should == '2' }
|
87
|
+
specify { described_class.parse("{{ [1, 2, 3][1..2] }}").render.should == '[2, 3]' }
|
88
|
+
specify { described_class.parse("{{ [1, 2, 3].last }}").render.should == '3' }
|
89
|
+
specify { described_class.parse("{{ [1, 2, 3]['last'] }}").render.should =~ /TypeError/ }
|
90
|
+
specify { described_class.parse("{{ { a: 1, b: 2 }['b'] }}").render.should == '2' }
|
91
|
+
specify { described_class.parse("{{ { count: 5, b: 7 }.count }}").render.should == '2' }
|
92
|
+
specify { described_class.parse("{{ { count: 5, b: 7 }.b }}").render.should == '7' }
|
93
|
+
specify { described_class.parse("{{ { count: 5, b: 7 }['count'] }}").render.should == '5' }
|
94
|
+
specify { described_class.parse("{{ { count: 5, b: 7 }['b'] }}").render.should == '7' }
|
95
|
+
specify { described_class.parse("{{ { count: 5, b: 7 }['size'] }}").render.should == '' }
|
96
|
+
specify { described_class.parse("{{ 'string'[1] }}").render.should == 't' }
|
97
|
+
specify { described_class.parse("{{ 'string'[1, 3] }}").render.should == 'tri' }
|
98
|
+
specify { described_class.parse("{{ 'string'.size }}").render.should == '6' }
|
99
|
+
specify { described_class.parse("{{ 'string'['size'] }}").render.should == '' }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'escaping' do
|
104
|
+
specify { described_class.parse('{{ title }}').render(
|
105
|
+
title: '<h1>Title</h1>'
|
106
|
+
).should == '<h1>Title</h1>' }
|
107
|
+
specify { described_class.parse('{{~ title }}').render(
|
108
|
+
title: '<h1>Title</h1>'
|
109
|
+
).should == '<h1>Title</h1>' }
|
110
|
+
specify { described_class.parse('{{ if true }}<h1>Title</h1>{{ end }}').render(
|
111
|
+
title: '<h1>Title</h1>'
|
112
|
+
).should == '<h1>Title</h1>' }
|
113
|
+
specify { described_class.parse('{{^ if true }}<h1>Title</h1>{{ end }}').render(
|
114
|
+
title: '<h1>Title</h1>'
|
115
|
+
).should == '<h1>Title</h1>' }
|
116
|
+
specify { described_class.parse('{{ if true }}{{ title }}{{ end }}').render(
|
117
|
+
title: '<h1>Title</h1>'
|
118
|
+
).should == '<h1>Title</h1>' }
|
119
|
+
|
120
|
+
context 'escape_tags' do
|
121
|
+
before { Hotcell.stub(:escape_tags) { true } }
|
122
|
+
|
123
|
+
specify { described_class.parse('{{ title }}').render(
|
124
|
+
title: '<h1>Title</h1>'
|
125
|
+
).should == '<h1>Title</h1>' }
|
126
|
+
specify { described_class.parse('{{ if true }}{{ title }}{{ end }}').render(
|
127
|
+
title: '<h1>Title</h1>'
|
128
|
+
).should == '<h1>Title</h1>' }
|
129
|
+
specify { described_class.parse('{{ if true }}<h1>Title</h1>{{ end }}').render(
|
130
|
+
title: '<h1>Title</h1>'
|
131
|
+
).should == '<h1>Title</h1>' }
|
132
|
+
end
|
83
133
|
end
|
84
134
|
end
|
data/spec/lib/hotcell_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotcell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pyromaniac
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: racc
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/hotcell/errors.rb
|
75
75
|
- lib/hotcell/extensions.rb
|
76
76
|
- lib/hotcell/lexer.rb
|
77
|
+
- lib/hotcell/lexer.rl
|
77
78
|
- lib/hotcell/lexerr.rb
|
78
79
|
- lib/hotcell/lexerr.rl
|
79
80
|
- lib/hotcell/manipulator.rb
|
@@ -81,8 +82,8 @@ files:
|
|
81
82
|
- lib/hotcell/node/arrayer.rb
|
82
83
|
- lib/hotcell/node/assigner.rb
|
83
84
|
- lib/hotcell/node/block.rb
|
84
|
-
- lib/hotcell/node/calculator.rb
|
85
85
|
- lib/hotcell/node/command.rb
|
86
|
+
- lib/hotcell/node/expression.rb
|
86
87
|
- lib/hotcell/node/hasher.rb
|
87
88
|
- lib/hotcell/node/joiner.rb
|
88
89
|
- lib/hotcell/node/sequencer.rb
|