pivotal-erector 0.5.1 → 0.6.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.
Files changed (32) hide show
  1. data/README.txt +5 -5
  2. data/VERSION.yml +2 -2
  3. data/bin/{erect → erector} +0 -0
  4. data/lib/erector/erect.rb +1 -1
  5. data/lib/erector/erected.rb +1 -1
  6. data/lib/erector/rails/extensions/action_controller.rb +25 -7
  7. data/lib/erector/rails/extensions/{widget.rb → rails_widget/helpers.rb} +2 -9
  8. data/lib/erector/rails/extensions/{widget/2.2.0/widget.rb → rails_widget.rb} +4 -2
  9. data/lib/erector/rails/rails_version.rb +6 -0
  10. data/lib/erector/rails/template_handlers/action_view_template_handler.rb +43 -11
  11. data/lib/erector/rails.rb +2 -1
  12. data/lib/erector/version.rb +1 -1
  13. data/lib/erector/widget.rb +213 -73
  14. data/lib/erector/widgets/table.rb +3 -3
  15. data/spec/erector/indentation_spec.rb +39 -24
  16. data/spec/erector/widget_spec.rb +197 -64
  17. data/spec/erector/widgets/table_spec.rb +3 -3
  18. data/spec/spec.opts +1 -0
  19. data/spec/spec_helper.rb +1 -4
  20. data/spec/spec_suite.rb +6 -12
  21. metadata +18 -30
  22. data/lib/erector/rails/extensions/action_controller/1.2.5/action_controller.rb +0 -17
  23. data/lib/erector/rails/extensions/action_controller/2.2.0/action_controller.rb +0 -26
  24. data/lib/erector/rails/extensions/widget/1.2.5/widget.rb +0 -18
  25. data/lib/erector/rails/supported_rails_versions.rb +0 -14
  26. data/lib/erector/rails/template_handlers/1.2.5/action_view_template_handler.rb +0 -32
  27. data/lib/erector/rails/template_handlers/2.0.0/action_view_template_handler.rb +0 -36
  28. data/lib/erector/rails/template_handlers/2.1.0/action_view_template_handler.rb +0 -31
  29. data/lib/erector/rails/template_handlers/2.2.0/action_view_template_handler.rb +0 -46
  30. data/spec/erect/erect_spec.rb +0 -145
  31. data/spec/erect/erected_spec.rb +0 -80
  32. data/spec/erect/rhtml_parser_spec.rb +0 -318
@@ -1,318 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
-
3
- module ParserTestHelper
4
- def assert_evals_to_self(input)
5
- assert_evals_to(input, input)
6
- end
7
-
8
- def parse(input)
9
- result = @parser.parse(input)
10
- if result
11
- result.set_indent(0) if result.respond_to? :set_indent
12
- else
13
- puts @parser.failure_reason
14
- puts @parser.terminal_failures.join("\n")
15
- result.should_not be_nil
16
- end
17
- result
18
- end
19
- end
20
-
21
- describe RhtmlParser do
22
- include ParserTestHelper
23
-
24
- before :each do
25
- @parser = RhtmlParser.new
26
- end
27
-
28
- it "converts text" do
29
- parse("hello").convert.should == "text 'hello'\n"
30
- parse("hello maude!").convert.should == "text 'hello maude!'\n"
31
- parse(" hello ").convert.should == "text 'hello'\n"
32
- end
33
-
34
- it "unescapes HTML entities in text" do
35
- parse("&lt;").convert.should == "text '<'\n"
36
- parse("5 &gt; 2").convert.should == "text '5 > 2'\n"
37
- end
38
-
39
- it "converts self-closing tags" do
40
- parse("<br/>").convert.should == "br\n"
41
- parse("<br />").convert.should == "br\n"
42
- end
43
-
44
- it "converts open tag" do
45
- parse("<div>").convert.should == "div do\n"
46
- parse("<h1>").convert.should == "h1 do\n"
47
- end
48
-
49
- it "converts close tag" do
50
- parse("</div>").convert.should == "end\n"
51
- parse("</h1>").convert.should == "end\n"
52
- end
53
-
54
- it "converts two nested divs" do
55
- parse("<div><div></div></div>").convert.should ==
56
- "div do\n" +
57
- " div do\n" +
58
- " end\n" +
59
- "end\n"
60
- end
61
-
62
- it "converts two nested divs with whitespace" do
63
- parse("<div> <div> </div> </div>").convert.should ==
64
- "div do\n" +
65
- " div do\n" +
66
- " end\n" +
67
- "end\n"
68
- end
69
-
70
- it "converts no open, text, and no close tag" do
71
- parse("hello</div>").convert.should == "text 'hello'\nend\n"
72
- end
73
-
74
- it "converts open, text, and no close tag" do
75
- parse("<div>hello").convert.should == "div do\n text 'hello'\n"
76
- end
77
-
78
- it "converts open, text, close" do
79
- parse("<div>hello</div>").convert.should == "div do\n text 'hello'\nend\n"
80
- end
81
-
82
- it "autocloses an img tag" do
83
- parse("<img src='foo'>").convert.should == "img :src => 'foo'\n"
84
- end
85
-
86
- it "converts a scriptlet" do
87
- parse("<% foo %>").convert.should == "foo\n"
88
- end
89
-
90
- it "converts open, text, scriptlet, text, close" do
91
- parse("<div>hello <% 5.times do %> very <% end %> much</div>").convert.should ==
92
- "div do\n" +
93
- " text 'hello'\n" +
94
- " 5.times do\n" +
95
- " text 'very'\n" +
96
- " end\n" +
97
- " text 'much'\n" +
98
- "end\n"
99
- end
100
-
101
- it "converts open, scriptlet, text, close" do
102
- parse("<div><% 5.times do %> very <% end %> much</div>").convert.should ==
103
- "div do\n" +
104
- " 5.times do\n" +
105
- " text 'very'\n" +
106
- " end\n" +
107
- " text 'much'\n" +
108
- "end\n"
109
- end
110
-
111
- it "converts open, text, scriptlet, close" do
112
- parse("<div>hello <% 5.times do %> very <% end %></div>").convert.should ==
113
- "div do\n" +
114
- " text 'hello'\n" +
115
- " 5.times do\n" +
116
- " text 'very'\n" +
117
- " end\n" +
118
- "end\n"
119
- end
120
-
121
- it "converts printlets into rawtext statements" do
122
- parse("<%= 1+1 %>").convert.should == "rawtext 1+1\n"
123
- parse("<%= link_to \"mom\" %>").convert.should == "rawtext link_to(\"mom\")\n"
124
- end
125
-
126
- it "converts h-printlets into text statements" do
127
- parse("<%=h foo %>").convert.should == "text foo\n"
128
- parse("<%= h \"mom\" %>").convert.should == "text \"mom\"\n"
129
- end
130
-
131
- it "allows naked percent signs inside scriptlets" do
132
- parse("<% x = 10 % 5 %>").convert.should == "x = 10 % 5\n"
133
- end
134
-
135
- it "indents" do
136
- i = Erector::Indenting.new(nil, nil)
137
- i.line("foo").should == "foo\n"
138
- i.line_in("bar").should == "bar\n"
139
- i.line_in("baz").should == " baz\n"
140
- i.line("baf").should == " baf\n"
141
- i.line_out("end").should == " end\n"
142
- i.line_out("end").should == "end\n"
143
- end
144
-
145
- it "indents extra when told to" do
146
- parse("<div>hello</div>").set_indent(2).convert.should ==
147
- " div do\n" +
148
- " text 'hello'\n" +
149
- " end\n"
150
- end
151
-
152
- it "indents scriptlets ending with do and end" do
153
- parse("<% form_for :foo do |x,y| %><% 5.times do %>hello<% end %><% end %>bye").convert.should ==
154
- "form_for :foo do |x,y|\n" +
155
- " 5.times do\n" +
156
- " text 'hello'\n" +
157
- " end\n" +
158
- "end\n" +
159
- "text 'bye'\n"
160
- end
161
-
162
- it "converts HTML attributes" do
163
- parse("<div id='foo'/>").convert.should == "div :id => 'foo'\n"
164
- parse("<div id='foo' class='bar'/>").convert.should == "div :id => 'foo', :class => 'bar'\n"
165
- parse("<div id='foo'>bar</div>").convert.should == "div :id => 'foo' do\n text 'bar'\nend\n"
166
- end
167
-
168
- it "escapes single quotes inside attribute values" do
169
- @parser.root = :attribute
170
- parse("a=\"don't worry\"").convert.should == ":a => 'don\\'t worry'"
171
- end
172
-
173
- it "allows newlines where whitespace is allowed" do
174
- parse("<img src='foo' \nalt='bar' />").convert.should == "img :src => 'foo', :alt => 'bar'\n"
175
- end
176
-
177
- it "treats tab characters the same as spaces" do
178
- parse("<div \t />").convert.should == "div\n"
179
- end
180
-
181
- it "deals with HTML entities in text" do
182
- parse("&lt;").convert.should == "text '<'\n"
183
- end
184
-
185
- it "deals with a naked less-than or greater-than sign inside text" do
186
- parse("if x > 2 or x< 5 then").convert.should == "text 'if x > 2 or x< 5 then'\n"
187
- end
188
-
189
- it "wraps printlets in parens if necessary, to avoid warning: parenthesize argument(s) for future version" do
190
- parse("<%= h \"mom\" %>").convert.should == "text \"mom\"\n"
191
- parse("<%= h hi \"mom\" %>").convert.should == "text hi(\"mom\")\n"
192
-
193
- parse("<%= \"mom\" %>").convert.should == "rawtext \"mom\"\n"
194
- parse("<%= \"hi mom\" %>").convert.should == "rawtext \"hi mom\"\n"
195
- parse("<%= hi \"mom\" %>").convert.should == "rawtext hi(\"mom\")\n"
196
-
197
- parse("<%= link_to blah %>").convert.should == "rawtext link_to(blah)\n"
198
- parse("<%= link_to blah blah %>").convert.should == "rawtext link_to(blah blah)\n"
199
- parse("<%= link_to blah(blah) %>").convert.should == "rawtext link_to(blah(blah))\n"
200
-
201
- parse("<%= link_to(blah) %>").convert.should == "rawtext link_to(blah)\n"
202
- end
203
-
204
- it "won't parenthesize expressions" do
205
- parse("<%= h foo / bar %>").convert.should == "text foo / bar\n"
206
- end
207
-
208
- it "converts yield so layouts work" do
209
- pending("easy enough to make this pass, but the result doesn't seem to work as a layout")
210
- parse("<%= yield %>").convert.should == "rawtext @content\n"
211
- parse("<%= \"yield\" %>").convert.should == "rawtext \"yield\"\n"
212
- parse("<%= \"the yield is good\" %>").convert.should == "rawtext \"the yield is good\"\n"
213
- end
214
-
215
- it "parses quoted strings" do
216
- @parser.root = :quoted
217
- parse("'foo'").value.should == "foo"
218
- parse("\"foo\"").value.should == "foo"
219
- end
220
-
221
- it "converts attributes in isolation" do
222
- @parser.root = :attribute
223
- parse("a='foo'").convert.should == ":a => 'foo'"
224
- parse("a=\"foo\"").convert.should == ":a => 'foo'"
225
- end
226
-
227
- it "parses a set of attributes" do
228
- @parser.root = :attributes
229
- parse("a='foo' b='bar'").convert.should == " :a => 'foo', :b => 'bar'"
230
- end
231
-
232
- it "works with namespaced attributes" do
233
- @parser.root = :attribute
234
- parse('xml:lang="en"').convert.should == "'xml:lang' => 'en'"
235
- end
236
-
237
- it "deals with HTML entities in attribute values" do
238
- @parser.root = :attribute
239
- parse("foo='b<r'").convert.should == ":foo => 'b<r'"
240
- parse("foo='b&lt;r'").convert.should == ":foo => 'b<r'"
241
- end
242
-
243
- it "converts DOCTYPEs" do
244
- html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
245
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
246
- parse(html).convert.should == "rawtext '#{html}'\n"
247
- end
248
-
249
- ## More functional-type specs below here
250
-
251
- it "ignores spaces, tabs and newlines" do
252
- parse(" <div>\t\n" + "\thello !" + "\n\t</div>").convert.should ==
253
- "div do\n" +
254
- " text 'hello !'\n" +
255
- "end\n"
256
- end
257
-
258
- it "parses some scaffolding" do
259
- parse("<p>
260
- <b>Name:</b>
261
- <%=h @foo.name %>
262
- </p>").convert.should ==
263
- "p do\n" +
264
- " b do\n" +
265
- " text 'Name:'\n" +
266
- " end\n" +
267
- " text @foo.name\n" +
268
- "end\n"
269
- end
270
-
271
- it "parses edit.erb.html" do
272
- parse("<h1>Editing foo</h1>
273
-
274
- <%= error_messages_for :foo %>
275
-
276
- <% form_for(@foo) do |f| %>
277
- <p>
278
- <b>Name</b><br />
279
- <%= f.text_field :name %>
280
- </p>
281
-
282
- <p>
283
- <b>Age</b><br />
284
- <%= f.text_field :age %>
285
- </p>
286
-
287
- <p>
288
- <%= f.submit \"Update\" %>
289
- </p>
290
- <% end %>
291
-
292
- <%= link_to 'Show', @foo %> |
293
- <%= link_to 'Back', foos_path %>
294
- ")
295
- end
296
-
297
- it "parses show.html.erb" do
298
- parse("<p>
299
- <b>Name:</b>
300
- <%=h @foo.name %>
301
- </p>
302
-
303
- <p>
304
- <b>Age:</b>
305
- <%=h @foo.age %>
306
- </p>
307
-
308
-
309
- <%= link_to 'Edit', edit_foo_path(@foo) %> |
310
- <%= link_to 'Back', foos_path %>
311
- ")
312
- end
313
-
314
- it "does meta" do
315
- parse('<meta http-equiv="content-type" content="text/html;charset=UTF-8" />').convert.should ==
316
- "meta 'http-equiv' => 'content-type', :content => 'text/html;charset=UTF-8'\n"
317
- end
318
- end