erector 0.7.0 → 0.7.1

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.
@@ -0,0 +1,133 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module Erector
4
+ module Widgets
5
+
6
+ describe FieldTable do
7
+
8
+ describe "a basic, brittle characterization test, just to get up and running" do
9
+
10
+ class PasswordForm < Erector::Widget
11
+ def content
12
+ form :action => "/user", :method => "post" do
13
+ widget(FieldTable.new(:title => "Sign Up") do |t|
14
+ t.field("Name") do
15
+ input(:name => "name", :type => "text", :size => "30", :value => @username)
16
+ end
17
+ t.field("Password") do
18
+ input(:name => "password", :type => "password", :size => "30")
19
+ end
20
+ t.field("Password Again",
21
+ "Yes, we really want you to type your new password twice, for some reason.") do
22
+ input(:name => "password_verify", :type => "password", :size => "30")
23
+ end
24
+ t.button do
25
+ input(:name => "signup", :type => "submit", :value => "Sign Up")
26
+ end
27
+ end)
28
+ end
29
+ end
30
+ end
31
+
32
+ it "renders the CreateUser form" do
33
+ PasswordForm.new(:username => "bobdole").to_s.should ==
34
+ "<form action=\"/user\" method=\"post\">" +
35
+ "<fieldset class=\"field_table\">" +
36
+ "<legend>Sign Up</legend>" +
37
+ "<table width=\"100%\">" +
38
+ "<tr class=\"field_table_field\">" +
39
+ "<th>" +
40
+ "Name:</th>" +
41
+ "<td>" +
42
+ "<input name=\"name\" size=\"30\" type=\"text\" value=\"bobdole\" />" +
43
+ "</td>" +
44
+ "</tr>" +
45
+ "<tr class=\"field_table_field\">" +
46
+ "<th>" +
47
+ "Password:</th>" +
48
+ "<td>" +
49
+ "<input name=\"password\" size=\"30\" type=\"password\" />" +
50
+ "</td>" +
51
+ "</tr>" +
52
+ "<tr class=\"field_table_field\">" +
53
+ "<th>" +
54
+ "Password Again:</th>" +
55
+ "<td>" +
56
+ "<input name=\"password_verify\" size=\"30\" type=\"password\" />" +
57
+ "</td>" +
58
+ "<td>" +
59
+ "Yes, we really want you to type your new password twice, for some reason.</td>" +
60
+ "</tr>" +
61
+ "<tr class=\"field_table_buttons\">" +
62
+ "<td align=\"right\" colspan=\"2\">" +
63
+ "<table class=\"layout\">" +
64
+ "<tr>" +
65
+ "<td class=\"field_table_button\">" +
66
+ "<input name=\"signup\" type=\"submit\" value=\"Sign Up\" />" +
67
+ "</td>" +
68
+ "</tr>" +
69
+ "</table>" +
70
+ "</td>" +
71
+ "</tr>" +
72
+ "</table>" +
73
+ "</fieldset>" +
74
+ "</form>"
75
+
76
+ end
77
+ end
78
+
79
+ describe "using the configuration API to construct it on the fly" do
80
+
81
+ it "renders a table with no fields and no buttons" do
82
+ table = FieldTable.new(:title => "Meals")
83
+ doc = Nokogiri::HTML(table.to_s)
84
+ doc.css("fieldset legend").text.should == "Meals"
85
+ doc.at("fieldset")["class"].should == "field_table"
86
+ doc.css("fieldset > table > tr").size.should == 0
87
+ end
88
+
89
+ it "renders a table with no fields and one button" do
90
+ table = FieldTable.new(:title => "Meals") do |t|
91
+ t.button { t.input :type => "button", :value => "cancel" }
92
+ end
93
+ doc = Nokogiri::HTML(table.to_s)
94
+ doc.css("fieldset > table > tr").size.should == 1
95
+ doc.at("fieldset table tr")["class"].should == "field_table_buttons"
96
+ doc.at("td.field_table_button input")["value"].should == "cancel"
97
+ end
98
+
99
+ it "renders a table with a field and no buttons" do
100
+ table = FieldTable.new(:title => "Meals") do |t|
101
+ t.field("Breakfast") { t.text "scrambled eggs" }
102
+ end
103
+ doc = Nokogiri::HTML(table.to_s)
104
+ doc.css("fieldset > table > tr").size.should == 1
105
+ doc.at("fieldset table tr")["class"].should == "field_table_field"
106
+ doc.at("fieldset table tr th").text.should == "Breakfast:"
107
+ doc.at("fieldset table tr td").text.should == "scrambled eggs"
108
+ end
109
+
110
+ it "renders a table with a field with no label" do
111
+ table = FieldTable.new(:title => "Meals") do |t|
112
+ t.field { t.text "yum yum" }
113
+ end
114
+ doc = Nokogiri::HTML(table.to_s)
115
+ doc.css("fieldset > table > tr").size.should == 1
116
+ doc.at("fieldset table tr")["class"].should == "field_table_field"
117
+ doc.at("fieldset table tr th").text.should == ""
118
+ doc.at("fieldset table tr td").text.should == "yum yum"
119
+ end
120
+
121
+ it 'puts in an extra cell if you pass in a note' do
122
+ table = FieldTable.new(:title => "Meals") do |t|
123
+ t.field("Breakfast", "the most important meal of the day") { t.text "eggs" }
124
+ t.field("Lunch") { t.text "hot dogs" }
125
+ end
126
+ doc = Nokogiri::HTML(table.to_s)
127
+ doc.at("fieldset table tr").css("td[3]").text.should == "the most important meal of the day"
128
+ end
129
+
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module Erector
4
+ module Widgets
5
+ describe Page do
6
+ it "works" do
7
+ Page.new.to_s
8
+ end
9
+
10
+ it "contains basic_styles by default" do
11
+ Page.new.to_s.should =~ /.right {float: right;}/
12
+ end
13
+
14
+ it "can suppress basic_styles" do
15
+ Page.new(:basic_styles => false).to_s.should_not =~ /.right {float: right;}/
16
+ end
17
+
18
+ class FunkyPage < Page
19
+ def body_class
20
+ "funky"
21
+ end
22
+ end
23
+
24
+ it "allows subclasses to provide a css class for the body" do
25
+ FunkyPage.new.to_s.should =~ /<body class=\"funky\">/
26
+ end
27
+ end
28
+ end
29
+ end
@@ -25,7 +25,7 @@ module TableSpec
25
25
  before do
26
26
  widget = CustomHeadingTable.new(:row_objects => [])
27
27
  @html = widget.to_s
28
- @doc = Hpricot(html)
28
+ @doc = Nokogiri::HTML(html)
29
29
  end
30
30
 
31
31
  it "renders a custom heading text and procs" do
@@ -47,7 +47,7 @@ module TableSpec
47
47
  @object1 = Struct.new(:first_name).new("Hello")
48
48
  widget = CustomCellTable.new(:row_objects => [@object1])
49
49
  @html = widget.to_s
50
- @doc = Hpricot(html)
50
+ @doc = Nokogiri::HTML(html)
51
51
  end
52
52
 
53
53
  it "renders custom cell html" do
@@ -65,7 +65,7 @@ module TableSpec
65
65
  @object3 = Struct.new(:first_name, :last_name, :email).new(7, 8, 9)
66
66
  widget = DefaultsTestTable.new(:row_objects => [@object1, @object2, @object3])
67
67
  @html = widget.to_s
68
- @doc = Hpricot(html)
68
+ @doc = Nokogiri::HTML(html)
69
69
  @table = doc.at("table")
70
70
  end
71
71
 
@@ -2,7 +2,7 @@ dir = File.dirname(__FILE__)
2
2
  require "rubygems"
3
3
  $LOAD_PATH.unshift("#{dir}/../lib")
4
4
  require "erector"
5
- require "hpricot"
5
+ require "nokogiri"
6
6
  require "rr"
7
7
  require 'tempfile'
8
8
  require 'ostruct'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pivotal Labs
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-27 00:00:00 -07:00
12
+ date: 2009-10-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -34,15 +34,18 @@ files:
34
34
  - lib/erector/erect.rb
35
35
  - lib/erector/erected.rb
36
36
  - lib/erector/extensions/object.rb
37
+ - lib/erector/externals.rb
37
38
  - lib/erector/indenting.rb
38
39
  - lib/erector/inline.rb
39
40
  - lib/erector/mixin.rb
40
41
  - lib/erector/rails/extensions/action_controller.rb
41
42
  - lib/erector/rails/extensions/action_view.rb
42
- - lib/erector/rails/extensions/rails_widget/helpers.rb
43
+ - lib/erector/rails/extensions/rails_widget/rails_helpers.rb
43
44
  - lib/erector/rails/extensions/rails_widget.rb
45
+ - lib/erector/rails/rails_form_builder.rb
44
46
  - lib/erector/rails/rails_version.rb
45
- - lib/erector/rails/template_handlers/action_view_template_handler.rb
47
+ - lib/erector/rails/template_handlers/ert_handler.rb
48
+ - lib/erector/rails/template_handlers/rb_handler.rb
46
49
  - lib/erector/rails.rb
47
50
  - lib/erector/raw_string.rb
48
51
  - lib/erector/rhtml.treetop
@@ -50,6 +53,9 @@ files:
50
53
  - lib/erector/unicode_builder.rb
51
54
  - lib/erector/version.rb
52
55
  - lib/erector/widget.rb
56
+ - lib/erector/widgets/environment_badge.rb
57
+ - lib/erector/widgets/field_table.rb
58
+ - lib/erector/widgets/page.rb
53
59
  - lib/erector/widgets/table.rb
54
60
  - lib/erector/widgets.rb
55
61
  - lib/erector.rb
@@ -61,11 +67,14 @@ files:
61
67
  - spec/erect/erect_spec.rb
62
68
  - spec/erect/erected_spec.rb
63
69
  - spec/erect/rhtml_parser_spec.rb
70
+ - spec/erector/external_spec.rb
64
71
  - spec/erector/indentation_spec.rb
65
72
  - spec/erector/inline_spec.rb
66
73
  - spec/erector/mixin_spec.rb
67
74
  - spec/erector/unicode_builder_spec.rb
68
75
  - spec/erector/widget_spec.rb
76
+ - spec/erector/widgets/field_table_spec.rb
77
+ - spec/erector/widgets/page_spec.rb
69
78
  - spec/erector/widgets/table_spec.rb
70
79
  - spec/rails_spec_suite.rb
71
80
  - spec/spec.opts
@@ -1,110 +0,0 @@
1
- module Erector
2
- class RailsWidget < Widget
3
- include ActionController::UrlWriter
4
-
5
- # helpers returning raw text
6
- [
7
- :image_tag,
8
- :javascript_include_tag,
9
- :stylesheet_link_tag,
10
- :sortable_element,
11
- :sortable_element_js,
12
- :text_field_with_auto_complete,
13
- ].each do |helper_name|
14
- define_method helper_name do |*args|
15
- begin
16
- text raw(helpers.send(helper_name, *args))
17
- rescue => e
18
- puts e.backtrace.join("\n\t")
19
- raise e
20
- end
21
- end
22
- end
23
-
24
- # helpers returning raw text whose first parameter is HTML escaped
25
- [
26
- :link_to,
27
- :link_to_remote,
28
- :mail_to,
29
- :button_to,
30
- :submit_tag,
31
- ].each do |helper_name|
32
-
33
- method_def =<<-METHOD_DEF
34
- def #{helper_name}(link_text, *args, &block)
35
- text raw(helpers.#{helper_name}(h(link_text), *args, &block))
36
- end
37
- METHOD_DEF
38
- eval(method_def)
39
- end
40
-
41
- def error_messages_for(*args)
42
- text raw(helpers.error_messages_for(*args))
43
- end
44
-
45
- # return text, take block
46
- [
47
- :link_to_function,
48
- :text_field_tag,
49
- :password_field_tag,
50
- :check_box_tag
51
- ].each do |method_to_proxy_with_block|
52
- method_def =<<-METHOD_DEF
53
- def #{method_to_proxy_with_block}(*args, &block)
54
- text raw(helpers.#{method_to_proxy_with_block}(*args, &block))
55
- end
56
- METHOD_DEF
57
- eval(method_def)
58
- end
59
-
60
- # render text, take block
61
- [
62
- :error_messages_for,
63
- :form_tag,
64
- :form_for,
65
- ].each do |method_to_proxy_with_block|
66
- method_def =<<-METHOD_DEF
67
- def #{method_to_proxy_with_block}(*args, &block)
68
- helpers.#{method_to_proxy_with_block}(*args, &block)
69
- end
70
- METHOD_DEF
71
- eval(method_def)
72
- end
73
-
74
- def javascript_include_merged(key)
75
- helpers.javascript_include_merged(key)
76
- end
77
-
78
- def stylesheet_link_merged(key)
79
- helpers.stylesheet_link_merged(key)
80
- end
81
-
82
- def flash
83
- helpers.controller.send(:flash)
84
- end
85
-
86
- def session
87
- helpers.controller.session
88
- end
89
-
90
- def controller
91
- helpers.controller
92
- end
93
-
94
- def cycle(*args)
95
- helpers.cycle(*args)
96
- end
97
-
98
- def simple_format(string)
99
- p raw(string.to_s.html_escape.gsub(/\r\n?/, "\n").gsub(/\n/, "<br/>\n"))
100
- end
101
-
102
- def time_ago_in_words(*args)
103
- helpers.time_ago_in_words(*args)
104
- end
105
-
106
- def pluralize(*args)
107
- helpers.pluralize(*args)
108
- end
109
- end
110
- end