hotcell 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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('').options.values.map(&:keys).should == [['include'], ['for']] }
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 == '&lt;h1&gt;Title&lt;/h1&gt;' }
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 == '&lt;h1&gt;Title&lt;/h1&gt;' }
126
+ specify { described_class.parse('{{ if true }}{{ title }}{{ end }}').render(
127
+ title: '<h1>Title</h1>'
128
+ ).should == '&lt;h1&gt;Title&lt;/h1&gt;' }
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
@@ -6,4 +6,5 @@ describe Hotcell do
6
6
  it { should respond_to :helpers }
7
7
  it { should respond_to :register_command }
8
8
  it { should respond_to :register_helpers }
9
+ it { should respond_to :escape_tags }
9
10
  end
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.1.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-04 00:00:00.000000000 Z
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