erector 0.6.7 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 6
4
- :patch: 7
3
+ :minor: 7
4
+ :patch: 0
data/lib/erector.rb CHANGED
@@ -7,6 +7,7 @@ require "active_support/inflections"
7
7
  require "#{dir}/erector/extensions/object"
8
8
  require "#{dir}/erector/raw_string"
9
9
  require "#{dir}/erector/widget"
10
+ require "#{dir}/erector/inline"
10
11
  require "#{dir}/erector/unicode"
11
12
  require "#{dir}/erector/widgets"
12
13
  require "#{dir}/erector/version"
@@ -0,0 +1,36 @@
1
+ module Erector
2
+ def self.inline(*args, &block)
3
+ InlineWidget.new(*args, &block)
4
+ end
5
+
6
+ module Inline
7
+ # Evaluates its block (the one that was passed in the constructor) as a new widget's
8
+ # content method.
9
+ # Since "self" is pointing to the new widget, it can get access
10
+ # to parent widget methods via method_missing. Since it executes inside the
11
+ # widget it does not
12
+ # have access to instance variables of the caller, although it does
13
+ # have access to bound variables.
14
+ def content
15
+ if @block
16
+ instance_eval(&@block)
17
+ end
18
+ end
19
+
20
+ private
21
+ # This is part of the sub-widget/parent feature (see #widget method).
22
+ def method_missing(name, *args, &block)
23
+ block ||= lambda {} # captures self HERE
24
+ if @parent
25
+ @parent.send(name, *args, &block)
26
+ else
27
+ super
28
+ end
29
+ end
30
+ end
31
+
32
+ class InlineWidget < Erector::Widget
33
+ include Inline
34
+ end
35
+
36
+ end
data/lib/erector/mixin.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  module Erector
2
2
  module Mixin
3
+ # Executes the block as if it were the content body of a fresh Erector::Inline,
4
+ # and returns the #to_s value. Since it executes inside the new widget it does not
5
+ # have access to instance variables of the caller, although it does
6
+ # have access to bound variables.
3
7
  def erector(options = {}, &block)
4
- Erector::Widget.new(&block).to_s(options)
8
+ Erector.inline(&block).to_s(options)
5
9
  end
6
10
  end
7
11
  end
@@ -1,5 +1,9 @@
1
1
  module Erector
2
2
  class RailsWidget < Widget
3
+ def self.inline(*args, &block)
4
+ InlineRailsWidget.new(*args, &block)
5
+ end
6
+
3
7
  def output
4
8
  process_output_buffer || @output
5
9
  end
@@ -33,6 +37,11 @@ module Erector
33
37
  end
34
38
  end
35
39
  end
40
+
41
+ class InlineRailsWidget < RailsWidget
42
+ include Inline
43
+ end
44
+
36
45
  end
37
46
 
38
47
  require "#{File.dirname(__FILE__)}/rails_widget/helpers"
@@ -51,6 +51,7 @@ module Erector
51
51
  'b', 'bdo', 'big', 'blockquote', 'body', 'button',
52
52
  'caption', 'center', 'cite', 'code', 'colgroup',
53
53
  'dd', 'del', 'dfn', 'div', 'dl', 'dt', 'em',
54
+ 'embed',
54
55
  'fieldset', 'form', 'frameset',
55
56
  'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'html', 'i',
56
57
  'iframe', 'ins', 'kbd', 'label', 'legend', 'li', 'map',
@@ -226,16 +227,6 @@ module Erector
226
227
  def assign_local(name, value)
227
228
  raise ArgumentError, "Sorry, #{name} is a reserved variable name for Erector. Please choose a different name." if RESERVED_INSTANCE_VARS.include?(name)
228
229
  instance_variable_set("@#{name}", value)
229
- if any_are_needed?
230
- raise ArgumentError, "Sorry, #{name} is a reserved method name for Erector. Please choose a different name." if respond_to?(name)
231
- metaclass.module_eval do
232
- attr_reader name
233
- end
234
- end
235
- end
236
-
237
- def any_are_needed?
238
- !self.class.get_needs.empty?
239
230
  end
240
231
 
241
232
  # Render (like to_s) but adding newlines and indentation.
@@ -294,11 +285,11 @@ module Erector
294
285
  # Inside this method you call the magic #element methods which emit HTML
295
286
  # and text to the output string. If you call "super" (or don't override
296
287
  # +content+) then your widget will render any block that was passed into
297
- # its constructor (in the current instance context so it can get access
298
- # to parent widget methods via method_missing).
288
+ # its constructor. If you want this block to have access to Erector methods
289
+ # then see Erector::Inline#content.
299
290
  def content
300
291
  if @block
301
- instance_eval(&@block)
292
+ @block.call
302
293
  end
303
294
  end
304
295
 
@@ -576,16 +567,6 @@ module Erector
576
567
 
577
568
  protected
578
569
 
579
- # This is part of the sub-widget/parent feature (see #widget method).
580
- def method_missing(name, *args, &block)
581
- block ||= lambda {} # captures self HERE
582
- if @parent
583
- @parent.send(name, *args, &block)
584
- else
585
- super
586
- end
587
- end
588
-
589
570
  def __element__(tag_name, *args, &block)
590
571
  if args.length > 2
591
572
  raise ArgumentError, "Cannot accept more than three arguments"
@@ -1,7 +1,7 @@
1
1
  require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
-
3
2
  require "erector/rails"
4
3
 
4
+
5
5
  # Note: this is *not* inside the rails_root since we're not testing
6
6
  # Erector inside a rails app. We're testing that we can use the command-line
7
7
  # converter tool on a newly generated scaffold app (like we brag about in the
@@ -21,21 +21,30 @@ module Erector
21
21
  describe "Erect in a Rails app" do
22
22
 
23
23
  def run(cmd)
24
- puts cmd
25
- stdout = `#{cmd}`
26
- if $? != 0
27
- raise "Command #{cmd} failed, returning '#{stdout}', current dir '#{Dir.getwd}'"
24
+ puts "Running #{cmd}"
25
+ stderr_file = Dir.tmpdir + "/stderr.txt"
26
+ stdout = IO.popen(cmd + " 2>#{stderr_file}") do |pipe|
27
+ pipe.read
28
+ end
29
+ stderr = File.open(stderr_file) {|f| f.read}
30
+ FileUtils.rm_f(stderr_file)
31
+ if $?.exitstatus != 0
32
+ raise "Command #{cmd} failed\nDIR:\n #{Dir.getwd}\nSTDOUT:\n#{indent stdout}\nSTDERR:\n#{indent stderr}"
28
33
  else
29
34
  return stdout
30
35
  end
31
36
  end
32
37
 
38
+ def indent(s)
39
+ s.gsub(/^/, ' ')
40
+ end
41
+
33
42
  def run_rails(app_dir)
34
43
  # To ensure we're working with the right version of Rails we use "gem 'rails', 1.2.3"
35
44
  # in a "ruby -e" command line invocation of the rails executable to generate an
36
45
  # app called explode.
37
46
  #
38
- puts "Generating fresh rails #{Erector::Rails::RAILS_VERSION} app"
47
+ puts "Generating fresh rails #{Erector::Rails::RAILS_VERSION} app in #{app_dir}"
39
48
  run "ruby -e \"require 'rubygems'; gem 'rails', '#{Erector::Rails::RAILS_VERSION}'; load 'rails'\" #{app_dir}"
40
49
  end
41
50
 
@@ -45,12 +54,16 @@ module Erector
45
54
 
46
55
  FileUtils.mkdir_p(app_dir)
47
56
  run_rails app_dir
48
- FileUtils.cd(app_dir, :verbose => true) do
57
+
58
+ FileUtils.mkdir_p(app_dir + "/vendor/gems")
59
+ FileUtils.cp_r("#{File.dirname __FILE__}/../..", "#{app_dir}/vendor/gems/erector")
60
+
61
+ FileUtils.cd(app_dir) do
49
62
  run "script/generate scaffold post title:string body:text published:boolean"
50
63
  run "#{erector_bin}/erector app/views/posts"
51
64
  FileUtils.rm_f("app/views/posts/*.erb")
52
- run "(echo ''; echo \"require 'erector'\") >> config/environment.rb"
53
- run "rake db:migrate"
65
+ # run "(echo ''; echo \"require 'erector'\") >> config/environment.rb"
66
+ run "rake --trace db:migrate"
54
67
  # run "script/server" # todo: launch in background; use mechanize or something to crawl it; then kill it
55
68
  # perhaps use open4?
56
69
  # open http://localhost:3000/posts
@@ -3,7 +3,7 @@ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
3
3
  describe "indentation" do
4
4
 
5
5
  it "can detect newliney tags" do
6
- widget = ::Erector::Widget.new
6
+ widget = ::Erector.inline
7
7
  widget.instance_eval do
8
8
  @prettyprint = true
9
9
  end
@@ -12,28 +12,28 @@ describe "indentation" do
12
12
  end
13
13
 
14
14
  it "should not add newline for non-newliney tags" do
15
- Erector::Widget.new() do
15
+ Erector.inline do
16
16
  text "Hello, "
17
17
  b "World"
18
18
  end.to_pretty.should == "Hello, <b>World</b>"
19
19
  end
20
20
 
21
21
  it "should add newlines before open newliney tags" do
22
- Erector::Widget.new() do
22
+ Erector.inline do
23
23
  p "foo"
24
24
  p "bar"
25
25
  end.to_pretty.should == "<p>foo</p>\n<p>bar</p>\n"
26
26
  end
27
27
 
28
28
  it "should add newlines between text and open newliney tag" do
29
- Erector::Widget.new() do
29
+ Erector.inline do
30
30
  text "One"
31
31
  p "Two"
32
32
  end.to_pretty.should == "One\n<p>Two</p>\n"
33
33
  end
34
34
 
35
35
  it "should add newlines after end newliney tags" do
36
- Erector::Widget.new() do
36
+ Erector.inline do
37
37
  tr do
38
38
  td "cell"
39
39
  end
@@ -41,7 +41,7 @@ describe "indentation" do
41
41
  end
42
42
 
43
43
  it "should treat empty elements as start and end" do
44
- Erector::Widget.new() do
44
+ Erector.inline do
45
45
  p "before"
46
46
  br
47
47
  p "after"
@@ -49,7 +49,7 @@ describe "indentation" do
49
49
  end
50
50
 
51
51
  it "empty elements sets at_start_of_line" do
52
- Erector::Widget.new() do
52
+ Erector.inline do
53
53
  text "before"
54
54
  br
55
55
  p "after"
@@ -59,7 +59,7 @@ describe "indentation" do
59
59
  it "will not insert extra space before/after input element" do
60
60
  # If dim memory serves, the reason for not adding spaces here is
61
61
  # because it affects/affected the rendering in browsers.
62
- Erector::Widget.new() do
62
+ Erector.inline do
63
63
  text 'Name'
64
64
  input :type => 'text'
65
65
  text 'after'
@@ -67,7 +67,7 @@ describe "indentation" do
67
67
  end
68
68
 
69
69
  it "will indent" do
70
- Erector::Widget.new() do
70
+ Erector.inline do
71
71
  html do
72
72
  head do
73
73
  title "hi"
@@ -93,12 +93,12 @@ END
93
93
  end
94
94
 
95
95
  it "preserves indentation for sub-rendered widgets" do
96
- tea = Erector::Widget.new do
96
+ tea = Erector.inline do
97
97
  div do
98
98
  p "oolong"
99
99
  end
100
100
  end
101
- cup = Erector::Widget.new do
101
+ cup = Erector.inline do
102
102
  div do
103
103
  p "fine china"
104
104
  tea.write_via(self)
@@ -116,14 +116,14 @@ END
116
116
  end
117
117
 
118
118
  it "can turn off newlines" do
119
- Erector::Widget.new() do
119
+ Erector.inline do
120
120
  text "One"
121
121
  p "Two"
122
122
  end.to_s.should == "One<p>Two</p>"
123
123
  end
124
124
 
125
125
  it "can turn newlines on and off" do
126
- widget = Erector::Widget.new() do
126
+ widget = Erector.inline do
127
127
  text "One"
128
128
  p "Two"
129
129
  end
@@ -133,18 +133,18 @@ END
133
133
  end
134
134
 
135
135
  it "can turn on newlines via to_pretty" do
136
- widget = Erector::Widget.new() do
136
+ widget = Erector.inline do
137
137
  text "One"
138
138
  p "Two"
139
139
  end.to_pretty.should == "One\n<p>Two</p>\n"
140
140
  end
141
141
 
142
142
  it "can turn newlines on/off via global variable" do
143
- Erector::Widget.new { br }.to_s.should == "<br />"
143
+ Erector.inline { br }.to_s.should == "<br />"
144
144
  Erector::Widget.prettyprint_default = true
145
- Erector::Widget.new { br }.to_s.should == "<br />\n"
145
+ Erector.inline { br }.to_s.should == "<br />\n"
146
146
  Erector::Widget.prettyprint_default = false
147
- Erector::Widget.new { br }.to_s.should == "<br />"
147
+ Erector.inline { br }.to_s.should == "<br />"
148
148
  end
149
149
 
150
150
  end
@@ -0,0 +1,51 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+ require 'benchmark'
3
+
4
+ describe "passing in a block" do
5
+ describe Erector::Widget do
6
+ it "'s block is evaluated in the calling object's context" do
7
+
8
+ @sample_instance_variable = "yum"
9
+ sample_bound_variable = "yay"
10
+ Erector::Widget.new do
11
+ @sample_instance_variable.should == "yum"
12
+ sample_bound_variable.should == "yay"
13
+ lambda {text "you can't call Erector methods from in here"}.should raise_error(NoMethodError)
14
+ # puts "uncomment this to prove this is being executed"
15
+ end.to_s
16
+
17
+ end
18
+ end
19
+
20
+ describe Erector::Inline do
21
+ it "'s block is evaluated in the widget's context" do
22
+
23
+ @sample_instance_variable = "yum"
24
+ sample_bound_variable = "yay"
25
+ Erector.inline do
26
+ @sample_instance_variable.should be_nil
27
+ sample_bound_variable.should == "yay"
28
+ text "you can call Erector methods from in here"
29
+ # puts "uncomment this to prove this is being executed"
30
+ end.to_s
31
+
32
+ end
33
+ end
34
+
35
+ describe Erector::Mixin do
36
+ include Erector::Mixin
37
+ it "'s block is evaluated in the parent widget's context" do
38
+
39
+ @sample_instance_variable = "yum"
40
+ sample_bound_variable = "yay"
41
+ erector do
42
+ @sample_instance_variable.should be_nil
43
+ sample_bound_variable.should == "yay"
44
+ text "you can call Erector methods from in here"
45
+ # puts "uncomment this to prove this is being executed"
46
+ end
47
+
48
+ end
49
+ end
50
+
51
+ end
@@ -14,7 +14,7 @@ module WidgetSpec
14
14
  class << self
15
15
  define_method("invokes #content and returns the string representation of the rendered widget") do
16
16
  it "invokes #content and returns the string representation of the rendered widget" do
17
- widget = Erector::Widget.new do
17
+ widget = Erector.inline do
18
18
  div "Hello"
19
19
  end
20
20
  mock.proxy(widget).content
@@ -54,7 +54,7 @@ module WidgetSpec
54
54
 
55
55
  describe "#to_a" do
56
56
  it "returns an array" do
57
- widget = Erector::Widget.new do
57
+ widget = Erector.inline do
58
58
  div "Hello"
59
59
  end
60
60
  widget.to_a.should == ["<div>", "Hello", "</div>"]
@@ -63,7 +63,7 @@ module WidgetSpec
63
63
  # removing this, since oddly, when i run this test solo it works, but when
64
64
  # i run it as part of a rake suite, i get the opposite result -Alex
65
65
  # it "runs faster than using a string as the output" do
66
- # widget = Erector::Widget.new do
66
+ # widget = Erector.inline do
67
67
  # 1000.times do |i|
68
68
  # div "Lorem ipsum dolor sit amet #{i}, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est #{i} laborum."
69
69
  # end
@@ -84,7 +84,7 @@ module WidgetSpec
84
84
 
85
85
  describe "#instruct" do
86
86
  it "when passed no arguments; returns an XML declaration with version 1 and utf-8" do
87
- html = Erector::Widget.new do
87
+ html = Erector.inline do
88
88
  instruct
89
89
  # version must precede encoding, per XML 1.0 4th edition (section 2.8)
90
90
  end.to_s.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
@@ -131,7 +131,7 @@ module WidgetSpec
131
131
 
132
132
  context "when passed a class" do
133
133
  it "renders it" do
134
- Erector::Widget.new do
134
+ Erector.inline do
135
135
  div do
136
136
  widget Orphan, :name => "Annie"
137
137
  end
@@ -141,7 +141,7 @@ module WidgetSpec
141
141
 
142
142
  context "when passed an instance" do
143
143
  it "renders it" do
144
- Erector::Widget.new do
144
+ Erector.inline do
145
145
  div do
146
146
  widget Orphan.new(:name => "Oliver")
147
147
  end
@@ -167,20 +167,28 @@ module WidgetSpec
167
167
  end
168
168
  end
169
169
 
170
- widget = Class.new(Erector::Widget) do
170
+ grandchild = Class.new(Erector::InlineWidget) do
171
171
  needs :parent_widget, :child_widget
172
172
  def content
173
- widget(parent_widget) do
174
- widget(child_widget) do
175
- super
173
+ widget(@parent_widget) do
174
+ widget(@child_widget) do
175
+ div :id => "grandchild"
176
176
  end
177
177
  end
178
178
  end
179
179
  end
180
180
 
181
- widget.new(:parent_widget => parent_widget, :child_widget => child_widget) do
182
- div :id => "widget"
183
- end.to_s.should == '<div id="parent_widget"><div id="child_widget"><div id="widget"></div></div></div>'
181
+ grandchild.new(:parent_widget => parent_widget, :child_widget => child_widget).to_s.should == '<div id="parent_widget"><div id="child_widget"><div id="grandchild"></div></div></div>'
182
+
183
+ pending "pretty-print indentation is messed up with nesting" do
184
+ grandchild.new(:parent_widget => parent_widget, :child_widget => child_widget).to_pretty.should ==
185
+ "<div id=\"parent_widget\">\n" +
186
+ " <div id=\"child_widget\">\n" +
187
+ " <div id=\"grandchild\"></div>\n" +
188
+ " </div>\n" +
189
+ "</div>"
190
+ end
191
+
184
192
  end
185
193
  end
186
194
  end
@@ -188,7 +196,7 @@ module WidgetSpec
188
196
  describe "#element" do
189
197
  context "when receiving one argument" do
190
198
  it "returns an empty element" do
191
- Erector::Widget.new do
199
+ Erector.inline do
192
200
  element('div')
193
201
  end.to_s.should == "<div></div>"
194
202
  end
@@ -196,7 +204,7 @@ module WidgetSpec
196
204
 
197
205
  context "with a attribute hash" do
198
206
  it "returns an empty element with the attributes" do
199
- html = Erector::Widget.new do
207
+ html = Erector.inline do
200
208
  element(
201
209
  'div',
202
210
  :class => "foo bar",
@@ -214,7 +222,7 @@ module WidgetSpec
214
222
 
215
223
  context "with an array of CSS classes" do
216
224
  it "returns a tag with the classes separated" do
217
- Erector::Widget.new do
225
+ Erector.inline do
218
226
  element('div', :class => [:foo, :bar])
219
227
  end.to_s.should == "<div class=\"foo bar\"></div>";
220
228
  end
@@ -222,16 +230,15 @@ module WidgetSpec
222
230
 
223
231
  context "with an array of CSS classes as strings" do
224
232
  it "returns a tag with the classes separated" do
225
- Erector::Widget.new do
233
+ Erector.inline do
226
234
  element('div', :class => ['foo', 'bar'])
227
235
  end.to_s.should == "<div class=\"foo bar\"></div>";
228
236
  end
229
237
  end
230
238
 
231
-
232
239
  context "with a CSS class which is a string" do
233
240
  it "just use that as the attribute value" do
234
- Erector::Widget.new do
241
+ Erector.inline do
235
242
  element('div', :class => "foo bar")
236
243
  end.to_s.should == "<div class=\"foo bar\"></div>";
237
244
  end
@@ -239,7 +246,7 @@ module WidgetSpec
239
246
 
240
247
  context "with many attributes" do
241
248
  it "alphabetize them" do
242
- Erector::Widget.new do
249
+ Erector.inline do
243
250
  empty_element('foo', :alpha => "", :betty => "5", :aardvark => "tough",
244
251
  :carol => "", :demon => "", :erector => "", :pi => "3.14", :omicron => "", :zebra => "", :brain => "")
245
252
  end.to_s.should == "<foo aardvark=\"tough\" alpha=\"\" betty=\"5\" brain=\"\" carol=\"\" demon=\"\" " \
@@ -249,7 +256,7 @@ module WidgetSpec
249
256
 
250
257
  context "with inner tags" do
251
258
  it "returns nested tags" do
252
- widget = Erector::Widget.new do
259
+ widget = Erector.inline do
253
260
  element 'div' do
254
261
  element 'div'
255
262
  end
@@ -260,7 +267,7 @@ module WidgetSpec
260
267
 
261
268
  context "with text" do
262
269
  it "returns element with inner text" do
263
- Erector::Widget.new do
270
+ Erector.inline do
264
271
  element 'div', 'test text'
265
272
  end.to_s.should == "<div>test text</div>"
266
273
  end
@@ -269,7 +276,7 @@ module WidgetSpec
269
276
  context "with object other than hash" do
270
277
  it "returns element with inner text == object.to_s" do
271
278
  object = ['a', 'b']
272
- Erector::Widget.new do
279
+ Erector.inline do
273
280
  element 'div', object
274
281
  end.to_s.should == "<div>#{object.to_s}</div>"
275
282
  end
@@ -277,7 +284,7 @@ module WidgetSpec
277
284
 
278
285
  context "with parameters and block" do
279
286
  it "returns element with inner html and attributes" do
280
- Erector::Widget.new do
287
+ Erector.inline do
281
288
  element 'div', 'class' => "foobar" do
282
289
  element 'span', 'style' => 'display: none;'
283
290
  end
@@ -287,7 +294,7 @@ module WidgetSpec
287
294
 
288
295
  context "with content and parameters" do
289
296
  it "returns element with content as inner html and attributes" do
290
- Erector::Widget.new do
297
+ Erector.inline do
291
298
  element 'div', 'test text', :style => "display: none;"
292
299
  end.to_s.should == '<div style="display: none;">test text</div>'
293
300
  end
@@ -296,7 +303,7 @@ module WidgetSpec
296
303
  context "with more than three arguments" do
297
304
  it "raises ArgumentError" do
298
305
  proc do
299
- Erector::Widget.new do
306
+ Erector.inline do
300
307
  element 'div', 'foobar', {}, 'fourth'
301
308
  end.to_s
302
309
  end.should raise_error(ArgumentError)
@@ -306,7 +313,7 @@ module WidgetSpec
306
313
  it "renders the proper full tags" do
307
314
  Erector::Widget.full_tags.each do |tag_name|
308
315
  expected = "<#{tag_name}></#{tag_name}>"
309
- actual = Erector::Widget.new do
316
+ actual = Erector.inline do
310
317
  send(tag_name)
311
318
  end.to_s
312
319
  begin
@@ -321,7 +328,7 @@ module WidgetSpec
321
328
  describe "quoting" do
322
329
  context "when outputting text" do
323
330
  it "quotes it" do
324
- Erector::Widget.new do
331
+ Erector.inline do
325
332
  element 'div', 'test &<>text'
326
333
  end.to_s.should == "<div>test &amp;&lt;&gt;text</div>"
327
334
  end
@@ -329,7 +336,7 @@ module WidgetSpec
329
336
 
330
337
  context "when outputting text via text" do
331
338
  it "quotes it" do
332
- Erector::Widget.new do
339
+ Erector.inline do
333
340
  element 'div' do
334
341
  text "test &<>text"
335
342
  end
@@ -339,7 +346,7 @@ module WidgetSpec
339
346
 
340
347
  context "when outputting attribute value" do
341
348
  it "quotes it" do
342
- Erector::Widget.new do
349
+ Erector.inline do
343
350
  element 'a', :href => "foo.cgi?a&b"
344
351
  end.to_s.should == "<a href=\"foo.cgi?a&amp;b\"></a>"
345
352
  end
@@ -347,7 +354,7 @@ module WidgetSpec
347
354
 
348
355
  context "with raw text" do
349
356
  it "does not quote it" do
350
- Erector::Widget.new do
357
+ Erector.inline do
351
358
  element 'div' do
352
359
  text raw("<b>bold</b>")
353
360
  end
@@ -357,7 +364,7 @@ module WidgetSpec
357
364
 
358
365
  context "with raw text and no block" do
359
366
  it "does not quote it" do
360
- Erector::Widget.new do
367
+ Erector.inline do
361
368
  element 'div', raw("<b>bold</b>")
362
369
  end.to_s.should == "<div><b>bold</b></div>"
363
370
  end
@@ -365,7 +372,7 @@ module WidgetSpec
365
372
 
366
373
  context "with raw attribute" do
367
374
  it "does not quote it" do
368
- Erector::Widget.new do
375
+ Erector.inline do
369
376
  element 'a', :href => raw("foo?x=&nbsp;")
370
377
  end.to_s.should == "<a href=\"foo?x=&nbsp;\"></a>"
371
378
  end
@@ -373,7 +380,7 @@ module WidgetSpec
373
380
 
374
381
  context "with quote in attribute" do
375
382
  it "quotes it" do
376
- Erector::Widget.new do
383
+ Erector.inline do
377
384
  element 'a', :onload => "alert(\"foo\")"
378
385
  end.to_s.should == "<a onload=\"alert(&quot;foo&quot;)\"></a>"
379
386
  end
@@ -382,7 +389,7 @@ module WidgetSpec
382
389
 
383
390
  context "with a non-string, non-raw" do
384
391
  it "calls to_s and quotes" do
385
- Erector::Widget.new do
392
+ Erector.inline do
386
393
  element 'a' do
387
394
  text [7, "foo&bar"]
388
395
  end
@@ -394,7 +401,7 @@ module WidgetSpec
394
401
  describe "#empty_element" do
395
402
  context "when receiving attributes" do
396
403
  it "renders an empty element with the attributes" do
397
- Erector::Widget.new do
404
+ Erector.inline do
398
405
  empty_element 'input', :name => 'foo[bar]'
399
406
  end.to_s.should == '<input name="foo[bar]" />'
400
407
  end
@@ -402,7 +409,7 @@ module WidgetSpec
402
409
 
403
410
  context "when not receiving attributes" do
404
411
  it "renders an empty element without attributes" do
405
- Erector::Widget.new do
412
+ Erector.inline do
406
413
  empty_element 'br'
407
414
  end.to_s.should == '<br />'
408
415
  end
@@ -411,7 +418,7 @@ module WidgetSpec
411
418
  it "renders the proper empty-element tags" do
412
419
  Erector::Widget.empty_tags.each do |tag_name|
413
420
  expected = "<#{tag_name} />"
414
- actual = Erector::Widget.new do
421
+ actual = Erector.inline do
415
422
  send(tag_name)
416
423
  end.to_s
417
424
  begin
@@ -426,13 +433,13 @@ module WidgetSpec
426
433
 
427
434
  describe "#nbsp" do
428
435
  it "turns consecutive spaces into consecutive non-breaking spaces" do
429
- Erector::Widget.new do
436
+ Erector.inline do
430
437
  text nbsp("a b")
431
438
  end.to_s.should == "a&#160;&#160;b"
432
439
  end
433
440
 
434
441
  it "works in text context" do
435
- Erector::Widget.new do
442
+ Erector.inline do
436
443
  element 'a' do
437
444
  text nbsp("&<> foo")
438
445
  end
@@ -440,13 +447,13 @@ module WidgetSpec
440
447
  end
441
448
 
442
449
  it "works in attribute value context" do
443
- Erector::Widget.new do
450
+ Erector.inline do
444
451
  element 'a', :href => nbsp("&<> foo")
445
452
  end.to_s.should == "<a href=\"&amp;&lt;&gt;&#160;foo\"></a>"
446
453
  end
447
454
 
448
455
  it "defaults to a single non-breaking space if given no argument" do
449
- Erector::Widget.new do
456
+ Erector.inline do
450
457
  text nbsp
451
458
  end.to_s.should == "&#160;"
452
459
  end
@@ -455,26 +462,26 @@ module WidgetSpec
455
462
 
456
463
  describe "#character" do
457
464
  it "renders a character given the codepoint number" do
458
- Erector::Widget.new do
465
+ Erector.inline do
459
466
  text character(160)
460
467
  end.to_s.should == "&#xa0;"
461
468
  end
462
469
 
463
470
  it "renders a character given the unicode name" do
464
- Erector::Widget.new do
471
+ Erector.inline do
465
472
  text character(:right_arrow)
466
473
  end.to_s.should == "&#x2192;"
467
474
  end
468
475
 
469
476
  it "renders a character above 0xffff" do
470
- Erector::Widget.new do
477
+ Erector.inline do
471
478
  text character(:old_persian_sign_ka)
472
479
  end.to_s.should == "&#x103a3;"
473
480
  end
474
481
 
475
482
  it "throws an exception if a name is not recognized" do
476
483
  lambda {
477
- Erector::Widget.new do
484
+ Erector.inline do
478
485
  text character(:no_such_character_name)
479
486
  end.to_s
480
487
  }.should raise_error("Unrecognized character no_such_character_name")
@@ -484,7 +491,7 @@ module WidgetSpec
484
491
  # Perhaps calling to_s would be more ruby-esque, but that seems like it might
485
492
  # be pretty confusing when this method can already take either a name or number
486
493
  lambda {
487
- Erector::Widget.new do
494
+ Erector.inline do
488
495
  text character([])
489
496
  end.to_s
490
497
  }.should raise_error("Unrecognized argument to character: ")
@@ -494,19 +501,19 @@ module WidgetSpec
494
501
  describe "#join" do
495
502
 
496
503
  it "empty array means nothing to join" do
497
- Erector::Widget.new do
504
+ Erector.inline do
498
505
  join [], Erector::Widget.new { text "x" }
499
506
  end.to_s.should == ""
500
507
  end
501
508
 
502
509
  it "larger example with two tabs" do
503
- Erector::Widget.new do
510
+ Erector.inline do
504
511
  tab1 =
505
- Erector::Widget.new do
512
+ Erector.inline do
506
513
  a "Upload document", :href => "/upload"
507
514
  end
508
515
  tab2 =
509
- Erector::Widget.new do
516
+ Erector.inline do
510
517
  a "Logout", :href => "/logout"
511
518
  end
512
519
  join [tab1, tab2],
@@ -516,7 +523,7 @@ module WidgetSpec
516
523
  end
517
524
 
518
525
  it "plain string as join separator means pass it to text" do
519
- Erector::Widget.new do
526
+ Erector.inline do
520
527
  join [
521
528
  Erector::Widget.new { text "x" },
522
529
  Erector::Widget.new { text "y" }
@@ -525,7 +532,7 @@ module WidgetSpec
525
532
  end
526
533
 
527
534
  it "plain string as item to join means pass it to text" do
528
- Erector::Widget.new do
535
+ Erector.inline do
529
536
  join [
530
537
  "<",
531
538
  "&"
@@ -560,7 +567,7 @@ module WidgetSpec
560
567
  </script>
561
568
  EXPECTED
562
569
  expected.gsub!(/^ /, '')
563
- Erector::Widget.new do
570
+ Erector.inline do
564
571
  javascript do
565
572
  rawtext 'if (x < y && x > z) alert("don\'t stop");'
566
573
  end
@@ -577,14 +584,14 @@ module WidgetSpec
577
584
  </script>
578
585
  EXPECTED
579
586
  expected.gsub!(/^ /, '')
580
- Erector::Widget.new do
587
+ Erector.inline do
581
588
  javascript('alert("&<>\'hello");')
582
589
  end.to_s.should == expected
583
590
  end
584
591
 
585
592
  context "when receiving a params hash" do
586
593
  it "renders a source file" do
587
- html = Erector::Widget.new do
594
+ html = Erector.inline do
588
595
  javascript(:src => "/my/js/file.js")
589
596
  end.to_s
590
597
  doc = Hpricot(html)
@@ -594,7 +601,7 @@ module WidgetSpec
594
601
 
595
602
  context "when receiving text and a params hash" do
596
603
  it "renders a source file" do
597
- html = Erector::Widget.new do
604
+ html = Erector.inline do
598
605
  javascript('alert("&<>\'hello");', :src => "/my/js/file.js")
599
606
  end.to_s
600
607
  doc = Hpricot(html)
@@ -607,7 +614,7 @@ module WidgetSpec
607
614
  context "with too many arguments" do
608
615
  it "raises ArgumentError" do
609
616
  proc do
610
- Erector::Widget.new do
617
+ Erector.inline do
611
618
  javascript 'foobar', {}, 'fourth'
612
619
  end.to_s
613
620
  end.should raise_error(ArgumentError)
@@ -617,7 +624,7 @@ module WidgetSpec
617
624
 
618
625
  describe "#css" do
619
626
  it "makes a link when passed a string" do
620
- Erector::Widget.new do
627
+ Erector.inline do
621
628
  css "erector.css"
622
629
  end.to_s.should == "<link href=\"erector.css\" rel=\"stylesheet\" type=\"text/css\" />"
623
630
  end
@@ -625,7 +632,7 @@ module WidgetSpec
625
632
 
626
633
  describe "#url" do
627
634
  it "renders an anchor tag with the same href and text" do
628
- Erector::Widget.new do
635
+ Erector.inline do
629
636
  url "http://example.com"
630
637
  end.to_s.should == "<a href=\"http://example.com\">http://example.com</a>"
631
638
  end
@@ -633,7 +640,7 @@ module WidgetSpec
633
640
 
634
641
  describe '#capture' do
635
642
  it "should return content rather than write it to the buffer" do
636
- widget = Erector::Widget.new do
643
+ widget = Erector.inline do
637
644
  captured = capture do
638
645
  p 'Captured Content'
639
646
  end
@@ -645,7 +652,7 @@ module WidgetSpec
645
652
  end
646
653
 
647
654
  it "works with nested captures" do
648
- widget = Erector::Widget.new do
655
+ widget = Erector.inline do
649
656
  captured = capture do
650
657
  captured = capture do
651
658
  p 'Nested Capture'
@@ -663,11 +670,11 @@ module WidgetSpec
663
670
 
664
671
  describe 'nested' do
665
672
  it "can insert another widget without raw" do
666
- inner = Erector::Widget.new do
673
+ inner = Erector.inline do
667
674
  p "foo"
668
675
  end
669
676
 
670
- outer = Erector::Widget.new do
677
+ outer = Erector.inline do
671
678
  div inner
672
679
  end.to_s.should == '<div><p>foo</p></div>'
673
680
  end
@@ -693,7 +700,7 @@ module WidgetSpec
693
700
  end
694
701
 
695
702
  it "passing a widget to text method renders it" do
696
- Erector::Widget.new() do
703
+ Erector.inline do
697
704
  text "B"
698
705
  text A.new()
699
706
  text "B"
@@ -769,8 +776,8 @@ module WidgetSpec
769
776
  end
770
777
  lambda {
771
778
  thing = Thing7.new(:foo => 1, :baz => 3)
772
- thing.bar.should equal(7)
773
- thing.baz.should equal(3)
779
+ thing.instance_variable_get(:@bar).should equal(7)
780
+ thing.instance_variable_get(:@baz).should equal(3)
774
781
  }.should_not raise_error
775
782
  end
776
783
 
@@ -780,9 +787,9 @@ module WidgetSpec
780
787
  end
781
788
  lambda {
782
789
  thing = Thing8.new(:foo => 1, :baz => 2)
783
- thing.foo.should equal(1)
784
- thing.bar.should equal(7)
785
- thing.baz.should equal(2)
790
+ thing.instance_variable_get(:@foo).should equal(1)
791
+ thing.instance_variable_get(:@bar).should equal(7)
792
+ thing.instance_variable_get(:@baz).should equal(2)
786
793
  }.should_not raise_error
787
794
  end
788
795
 
@@ -792,7 +799,7 @@ module WidgetSpec
792
799
  end
793
800
  lambda {
794
801
  thing = Thing9.new
795
- thing.foo.should be_nil
802
+ thing.instance_variable_get(:@foo).should be_nil
796
803
  }.should_not raise_error
797
804
  end
798
805
 
@@ -814,34 +821,27 @@ module WidgetSpec
814
821
  lambda { Car.new(:wheels => 4) }.should raise_error
815
822
  end
816
823
 
817
- it "defines accessors for each of the needed variables" do
824
+ it "no longer defines accessors for each of the needed variables" do
818
825
  class NeedfulThing < Erector::Widget
819
826
  needs :love
820
827
  end
821
828
  thing = NeedfulThing.new(:love => "all we need")
822
- thing.love.should == "all we need"
829
+ lambda {thing.love}.should raise_error(NoMethodError)
823
830
  end
824
831
 
825
- it "doesnt define accessors for non-needed variables" do
826
- class NeedlessThing < Erector::Widget
827
- end
828
- thing = NeedlessThing.new(:love => "all we need")
829
- lambda {thing.love}.should raise_error
830
- end
831
-
832
- it "complains if you attempt to 'need' a variable whose name overlaps with an existing method" do
832
+ it "no longer complains if you attempt to 'need' a variable whose name overlaps with an existing method" do
833
833
  class ThingWithOverlap < Erector::Widget
834
834
  needs :text
835
835
  end
836
- lambda { ThingWithOverlap.new(:text => "alas") }.should raise_error(ArgumentError)
836
+ lambda { ThingWithOverlap.new(:text => "alas") }.should_not raise_error(ArgumentError)
837
837
  end
838
-
838
+
839
839
  end
840
840
 
841
841
  describe "#close_tag" do
842
842
  it "works when it's all alone, even though it messes with the indent level" do
843
- Erector::Widget.new { close_tag :foo }.to_s.should == "</foo>"
844
- Erector::Widget.new { close_tag :foo; close_tag :bar }.to_s.should == "</foo></bar>"
843
+ Erector.inline { close_tag :foo }.to_s.should == "</foo>"
844
+ Erector.inline { close_tag :foo; close_tag :bar }.to_s.should == "</foo></bar>"
845
845
  end
846
846
  end
847
847
  end
metadata CHANGED
@@ -1,32 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
- - Alex Chaffee
8
- - Brian Takita
9
- - Jeff Dean
10
- - Jim Kingdon
7
+ - Pivotal Labs
11
8
  autorequire:
12
9
  bindir: bin
13
10
  cert_chain: []
14
11
 
15
- date: 2009-06-17 00:00:00 -07:00
16
- default_executable: erector
12
+ date: 2009-09-27 00:00:00 -07:00
13
+ default_executable:
17
14
  dependencies:
18
15
  - !ruby/object:Gem::Dependency
19
- name: treetop
16
+ name: hoe
20
17
  type: :runtime
21
18
  version_requirement:
22
19
  version_requirements: !ruby/object:Gem::Requirement
23
20
  requirements:
24
21
  - - ">="
25
22
  - !ruby/object:Gem::Version
26
- version: 1.2.3
23
+ version: 1.5.0
27
24
  version:
28
25
  description: Html Builder library.
29
- email: erector@googlegroups.com
26
+ email: erector@googlegroups.compivotallabsopensource@googlegroups.com
30
27
  executables:
31
28
  - erector
32
29
  extensions: []
@@ -34,36 +31,38 @@ extensions: []
34
31
  extra_rdoc_files:
35
32
  - README.txt
36
33
  files:
37
- - README.txt
38
- - VERSION.yml
39
- - bin/erector
40
- - lib/erector.rb
41
34
  - lib/erector/erect.rb
42
35
  - lib/erector/erected.rb
43
36
  - lib/erector/extensions/object.rb
44
37
  - lib/erector/indenting.rb
38
+ - lib/erector/inline.rb
45
39
  - lib/erector/mixin.rb
46
- - lib/erector/rails.rb
47
40
  - lib/erector/rails/extensions/action_controller.rb
48
41
  - lib/erector/rails/extensions/action_view.rb
49
- - lib/erector/rails/extensions/rails_widget.rb
50
42
  - lib/erector/rails/extensions/rails_widget/helpers.rb
43
+ - lib/erector/rails/extensions/rails_widget.rb
51
44
  - lib/erector/rails/rails_version.rb
52
45
  - lib/erector/rails/template_handlers/action_view_template_handler.rb
46
+ - lib/erector/rails.rb
53
47
  - lib/erector/raw_string.rb
54
48
  - lib/erector/rhtml.treetop
55
49
  - lib/erector/unicode.rb
56
50
  - lib/erector/unicode_builder.rb
57
51
  - lib/erector/version.rb
58
52
  - lib/erector/widget.rb
59
- - lib/erector/widgets.rb
60
53
  - lib/erector/widgets/table.rb
54
+ - lib/erector/widgets.rb
55
+ - lib/erector.rb
56
+ - README.txt
57
+ - VERSION.yml
58
+ - bin/erector
61
59
  - spec/core_spec_suite.rb
62
60
  - spec/erect/erect_rails_spec.rb
63
61
  - spec/erect/erect_spec.rb
64
62
  - spec/erect/erected_spec.rb
65
63
  - spec/erect/rhtml_parser_spec.rb
66
64
  - spec/erector/indentation_spec.rb
65
+ - spec/erector/inline_spec.rb
67
66
  - spec/erector/mixin_spec.rb
68
67
  - spec/erector/unicode_builder_spec.rb
69
68
  - spec/erector/widget_spec.rb
@@ -73,10 +72,13 @@ files:
73
72
  - spec/spec_helper.rb
74
73
  - spec/spec_suite.rb
75
74
  has_rdoc: true
76
- homepage: http://erector.rubyforge.org/
75
+ homepage: http://erector.rubyforge.org
76
+ licenses: []
77
+
77
78
  post_install_message:
78
79
  rdoc_options:
79
- - --charset=UTF-8
80
+ - --main
81
+ - README.txt
80
82
  require_paths:
81
83
  - lib
82
84
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -94,25 +96,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
96
  requirements: []
95
97
 
96
98
  rubyforge_project: erector
97
- rubygems_version: 1.3.1
99
+ rubygems_version: 1.3.5
98
100
  signing_key:
99
- specification_version: 2
101
+ specification_version: 3
100
102
  summary: Html Builder library.
101
- test_files:
102
- - spec/rails_spec_suite.rb
103
- - spec/spec_suite.rb
104
- - spec/erector
105
- - spec/erector/indentation_spec.rb
106
- - spec/erector/unicode_builder_spec.rb
107
- - spec/erector/widgets
108
- - spec/erector/widgets/table_spec.rb
109
- - spec/erector/mixin_spec.rb
110
- - spec/erector/widget_spec.rb
111
- - spec/erect
112
- - spec/erect/erected_spec.rb
113
- - spec/erect/erect_rails_spec.rb
114
- - spec/erect/rhtml_parser_spec.rb
115
- - spec/erect/erect_spec.rb
116
- - spec/spec.opts
117
- - spec/spec_helper.rb
118
- - spec/core_spec_suite.rb
103
+ test_files: []
104
+