erector 0.7.2 → 0.8.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 (67) hide show
  1. data/README.txt +17 -3
  2. data/VERSION.yml +2 -2
  3. data/bin/erector +1 -1
  4. data/lib/erector.rb +22 -2
  5. data/lib/erector/after_initialize.rb +34 -0
  6. data/lib/erector/caching.rb +93 -0
  7. data/lib/erector/convenience.rb +58 -0
  8. data/lib/erector/dependencies.rb +24 -0
  9. data/lib/erector/dependency.rb +21 -0
  10. data/lib/erector/{erect.rb → erect/erect.rb} +14 -4
  11. data/lib/erector/{erected.rb → erect/erected.rb} +6 -4
  12. data/lib/erector/{indenting.rb → erect/indenting.rb} +0 -0
  13. data/lib/erector/{rhtml.treetop → erect/rhtml.treetop} +51 -11
  14. data/lib/erector/errors.rb +12 -0
  15. data/lib/erector/extensions/hash.rb +21 -0
  16. data/lib/erector/externals.rb +88 -24
  17. data/lib/erector/html.rb +352 -0
  18. data/lib/erector/inline.rb +5 -5
  19. data/lib/erector/jquery.rb +36 -0
  20. data/lib/erector/mixin.rb +3 -5
  21. data/lib/erector/needs.rb +94 -0
  22. data/lib/erector/output.rb +117 -0
  23. data/lib/erector/rails.rb +2 -2
  24. data/lib/erector/rails/extensions/action_controller.rb +5 -3
  25. data/lib/erector/rails/extensions/rails_helpers.rb +159 -0
  26. data/lib/erector/rails/extensions/rails_widget.rb +98 -56
  27. data/lib/erector/rails/rails_form_builder.rb +8 -4
  28. data/lib/erector/rails/rails_version.rb +2 -2
  29. data/lib/erector/rails/template_handlers/ert_handler.rb +1 -1
  30. data/lib/erector/rails/template_handlers/rb_handler.rb +42 -1
  31. data/lib/erector/raw_string.rb +2 -2
  32. data/lib/erector/sass.rb +22 -0
  33. data/lib/erector/widget.rb +100 -653
  34. data/lib/erector/widgets.rb +1 -0
  35. data/lib/erector/widgets/external_renderer.rb +51 -0
  36. data/lib/erector/widgets/page.rb +45 -63
  37. data/lib/erector/widgets/table.rb +9 -1
  38. data/spec/erect/erect_rails_spec.rb +19 -17
  39. data/spec/erect/erect_spec.rb +11 -1
  40. data/spec/erect/erected_spec.rb +76 -5
  41. data/spec/erect/rhtml_parser_spec.rb +11 -1
  42. data/spec/erector/caching_spec.rb +267 -0
  43. data/spec/erector/convenience_spec.rb +258 -0
  44. data/spec/erector/dependency_spec.rb +46 -0
  45. data/spec/erector/externals_spec.rb +233 -0
  46. data/spec/erector/html_spec.rb +508 -0
  47. data/spec/erector/indentation_spec.rb +84 -24
  48. data/spec/erector/inline_spec.rb +19 -8
  49. data/spec/erector/jquery_spec.rb +35 -0
  50. data/spec/erector/mixin_spec.rb +1 -1
  51. data/spec/erector/needs_spec.rb +120 -0
  52. data/spec/erector/output_spec.rb +199 -0
  53. data/spec/erector/sample-file.txt +1 -0
  54. data/spec/erector/sass_spec.rb +33 -0
  55. data/spec/erector/widget_spec.rb +113 -932
  56. data/spec/erector/widgets/field_table_spec.rb +6 -6
  57. data/spec/erector/widgets/form_spec.rb +3 -3
  58. data/spec/erector/widgets/page_spec.rb +52 -6
  59. data/spec/erector/widgets/table_spec.rb +4 -4
  60. data/spec/spec_helper.rb +70 -29
  61. metadata +56 -19
  62. data/lib/erector/rails/extensions/rails_widget/rails_helpers.rb +0 -137
  63. data/spec/core_spec_suite.rb +0 -3
  64. data/spec/erector/external_spec.rb +0 -110
  65. data/spec/rails_spec_suite.rb +0 -3
  66. data/spec/spec.opts +0 -1
  67. data/spec/spec_suite.rb +0 -40
@@ -30,7 +30,7 @@ module Erector
30
30
  end
31
31
 
32
32
  it "renders the CreateUser form" do
33
- PasswordForm.new(:username => "bobdole").to_s.should ==
33
+ PasswordForm.new(:username => "bobdole").to_html.should ==
34
34
  "<form action=\"/user\" method=\"post\">" +
35
35
  "<fieldset class=\"field_table\">" +
36
36
  "<legend>Sign Up</legend>" +
@@ -80,7 +80,7 @@ module Erector
80
80
 
81
81
  it "renders a table with no fields and no buttons" do
82
82
  table = FieldTable.new(:title => "Meals")
83
- doc = Nokogiri::HTML(table.to_s)
83
+ doc = Nokogiri::HTML(table.to_html)
84
84
  doc.css("fieldset legend").text.should == "Meals"
85
85
  doc.at("fieldset")["class"].should == "field_table"
86
86
  doc.css("fieldset > table > tr").size.should == 0
@@ -90,7 +90,7 @@ module Erector
90
90
  table = FieldTable.new(:title => "Meals") do |t|
91
91
  t.button { t.input :type => "button", :value => "cancel" }
92
92
  end
93
- doc = Nokogiri::HTML(table.to_s)
93
+ doc = Nokogiri::HTML(table.to_html)
94
94
  doc.css("fieldset > table > tr").size.should == 1
95
95
  doc.at("fieldset table tr")["class"].should == "field_table_buttons"
96
96
  doc.at("td.field_table_button input")["value"].should == "cancel"
@@ -100,7 +100,7 @@ module Erector
100
100
  table = FieldTable.new(:title => "Meals") do |t|
101
101
  t.field("Breakfast") { t.text "scrambled eggs" }
102
102
  end
103
- doc = Nokogiri::HTML(table.to_s)
103
+ doc = Nokogiri::HTML(table.to_html)
104
104
  doc.css("fieldset > table > tr").size.should == 1
105
105
  doc.at("fieldset table tr")["class"].should == "field_table_field"
106
106
  doc.at("fieldset table tr th").text.should == "Breakfast:"
@@ -111,7 +111,7 @@ module Erector
111
111
  table = FieldTable.new(:title => "Meals") do |t|
112
112
  t.field { t.text "yum yum" }
113
113
  end
114
- doc = Nokogiri::HTML(table.to_s)
114
+ doc = Nokogiri::HTML(table.to_html)
115
115
  doc.css("fieldset > table > tr").size.should == 1
116
116
  doc.at("fieldset table tr")["class"].should == "field_table_field"
117
117
  doc.at("fieldset table tr th").text.should == ""
@@ -123,7 +123,7 @@ module Erector
123
123
  t.field("Breakfast", "the most important meal of the day") { t.text "eggs" }
124
124
  t.field("Lunch") { t.text "hot dogs" }
125
125
  end
126
- doc = Nokogiri::HTML(table.to_s)
126
+ doc = Nokogiri::HTML(table.to_html)
127
127
  doc.at("fieldset table tr").css("td[3]").text.should == "the most important meal of the day"
128
128
  end
129
129
 
@@ -5,15 +5,15 @@ describe Form do
5
5
  include Erector::Mixin
6
6
 
7
7
  it "defaults to POST, with no magic hidden method param" do
8
- Form.new(:action => "/foo").to_s.should == "<form action=\"/foo\" method=\"post\"></form>"
8
+ Form.new(:action => "/foo").to_html.should == "<form action=\"/foo\" method=\"post\"></form>"
9
9
  end
10
10
 
11
11
  it "works plainly with GET too" do
12
- Form.new(:action => "/foo", :method => "get").to_s.should == "<form action=\"/foo\" method=\"get\"></form>"
12
+ Form.new(:action => "/foo", :method => "get").to_html.should == "<form action=\"/foo\" method=\"get\"></form>"
13
13
  end
14
14
 
15
15
  it "uses POST and adds a magic hidden field with a _method param for DELETE" do
16
- Form.new(:action => "/foo", :method => "delete").to_s.should ==
16
+ Form.new(:action => "/foo", :method => "delete").to_html.should ==
17
17
  "<form action=\"/foo\" method=\"post\">"+
18
18
  "<input name=\"_method\" type=\"hidden\" value=\"delete\" />"+
19
19
  "</form>"
@@ -2,7 +2,7 @@ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
2
 
3
3
  describe Erector::Widgets::Page do
4
4
  it "works" do
5
- Erector::Widgets::Page.new.to_s
5
+ Erector::Widgets::Page.new.to_html
6
6
  end
7
7
 
8
8
  it "renders body_content" do
@@ -10,13 +10,13 @@ describe Erector::Widgets::Page do
10
10
  def body_content
11
11
  text "body_content"
12
12
  end
13
- end.new.to_s.should =~ /body_content/
13
+ end.new.to_html.should =~ /body_content/
14
14
  end
15
15
 
16
16
  it "renders a block passed to new" do
17
17
  Erector::Widgets::Page.new do
18
- text "body_content"
19
- end.to_s.should =~ /body_content/
18
+ text "nice bod"
19
+ end.to_html.should =~ /nice bod/
20
20
  end
21
21
 
22
22
  it "renders a block passed to content" do
@@ -26,7 +26,7 @@ describe Erector::Widgets::Page do
26
26
  text "body_content"
27
27
  end
28
28
  end
29
- end.new.to_s.should =~ /body_content/
29
+ end.new.to_html.should =~ /body_content/
30
30
  end
31
31
 
32
32
  it "allows subclasses to provide a css class for the body" do
@@ -34,6 +34,52 @@ describe Erector::Widgets::Page do
34
34
  def body_attributes
35
35
  {:class => "funky"}
36
36
  end
37
- end.new.to_s.should =~ /<body class=\"funky\">/
37
+ end.new.to_html.should =~ /<body class=\"funky\">/
38
+ end
39
+
40
+ it "allows subclasses to be called with a block" do
41
+ fun_page_class = Class.new(Erector::Widgets::Page) do
42
+ def body_content
43
+ h3 "what's fun?"
44
+ call_block
45
+ end
46
+ end
47
+ fun_page_class.new do
48
+ text "soccer!"
49
+ end.to_html.should include("<h3>what's fun?</h3>soccer!")
50
+ end
51
+
52
+ class NiceWidget < Erector::Widget
53
+ external :style, ".nice {}"
54
+ def content
55
+ text "nice widget"
56
+ end
57
+ end
58
+ class MeanWidget < Erector::Widget
59
+ external :style, ".mean {}"
60
+ end
61
+
62
+ class NicePage < Erector::Widgets::Page
63
+ def body_content
64
+ text "nice page"
65
+ widget NiceWidget
66
+ end
67
+ end
68
+
69
+ class MeanPage < Erector::Widgets::Page
70
+ def body_content
71
+ widget MeanWidget
72
+ end
73
+ end
74
+
75
+ it "only puts into dependencies those from widgets rendered on it" do
76
+ s = NicePage.new.to_html
77
+ s.should include("nice page")
78
+ s.should include("nice widget")
79
+ s.should include(".nice {}")
80
+ s.should_not include(".mean {}")
81
+
82
+ MeanPage.new.to_html.should include(".mean {}")
83
+ MeanPage.new.to_html.should_not include(".nice {}")
38
84
  end
39
85
  end
@@ -24,7 +24,7 @@ module TableSpec
24
24
  attr_reader :html, :doc
25
25
  before do
26
26
  widget = CustomHeadingTable.new(:row_objects => [])
27
- @html = widget.to_s
27
+ @html = widget.to_html
28
28
  @doc = Nokogiri::HTML(html)
29
29
  end
30
30
 
@@ -46,7 +46,7 @@ module TableSpec
46
46
  before do
47
47
  @object1 = Struct.new(:first_name).new("Hello")
48
48
  widget = CustomCellTable.new(:row_objects => [@object1])
49
- @html = widget.to_s
49
+ @html = widget.to_html
50
50
  @doc = Nokogiri::HTML(html)
51
51
  end
52
52
 
@@ -64,7 +64,7 @@ module TableSpec
64
64
  @object2 = Struct.new(:first_name, :last_name, :email).new(4, 5, 6)
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
- @html = widget.to_s
67
+ @html = widget.to_html
68
68
  @doc = Nokogiri::HTML(html)
69
69
  @table = doc.at("table")
70
70
  end
@@ -96,4 +96,4 @@ module TableSpec
96
96
  end
97
97
  end
98
98
  end
99
- end
99
+ end
@@ -1,12 +1,17 @@
1
- dir = File.dirname(__FILE__)
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+
3
+ VENDOR_RAILS = "#{File.dirname(__FILE__)}/rails_root/vendor/rails"
4
+ RAILS_LOAD_PATHS = Dir["#{VENDOR_RAILS}/*/lib"]
5
+ RAILS_LOAD_PATHS.each do |path|
6
+ $LOAD_PATH.unshift(File.expand_path(path))
7
+ end
8
+
2
9
  require "rubygems"
3
- $LOAD_PATH.unshift("#{dir}/../lib")
4
10
  require "erector"
5
11
  require "nokogiri"
6
12
  require "rr"
7
13
  require 'tempfile'
8
14
  require 'ostruct'
9
- ARGV.push(*File.read("#{File.dirname(__FILE__)}/spec.opts").split("\n"))
10
15
  require "spec"
11
16
  require "spec/autorun"
12
17
 
@@ -14,32 +19,6 @@ Spec::Runner.configure do |config|
14
19
  config.mock_with :rr
15
20
  end
16
21
 
17
- # This mimics Rails load path and dependency stuff
18
- RAILS_ROOT = File.expand_path("#{File.dirname(__FILE__)}/rails_root") unless defined?(RAILS_ROOT)
19
- #$: << "#{RAILS_ROOT}/app"
20
- module Views
21
- module TemplateHandlerSpec
22
- end
23
- end
24
-
25
-
26
- # uncomment this to find leftover debug putses
27
- #
28
- # alias :original_puts :puts
29
- # def puts(string ="")
30
- # super string.to_s + "\s(#{caller.first.match(/(\w+\.\w+:\d+)|Rakefile:\d+/)[0]})"
31
- # end
32
- #
33
- # alias :original_p :p
34
- # def p(string="")
35
- # original_puts "\s(#{caller.first.match(/(\w+\.\w+:\d+)|Rakefile:\d+/)[0]})"
36
- # super(string)
37
- # end
38
- #
39
- # alias :original_print :print
40
- # def print(string="")
41
- # super string + "\s(#{caller.first.match(/(\w+\.\w+:\d+)|Rakefile:\d+/)[0]})"
42
- # end
43
22
  unless '1.9'.respond_to?(:force_encoding)
44
23
  String.class_eval do
45
24
  begin
@@ -49,3 +28,65 @@ unless '1.9'.respond_to?(:force_encoding)
49
28
  end
50
29
  end
51
30
  end
31
+
32
+ module Matchers
33
+ # borrowed from http://github.com/aiwilliams/spec_goodies
34
+
35
+ class IncludeOnly # :nodoc:all
36
+ def initialize(*expected)
37
+ @expected = expected.flatten
38
+ end
39
+
40
+ def matches?(actual)
41
+ @missing = @expected.reject {|e| actual.include?(e)}
42
+ @extra = actual.reject {|e| @expected.include?(e)}
43
+ @extra.empty? && @missing.empty?
44
+ end
45
+
46
+ def failure_message
47
+ message = "expected to include only #{@expected.inspect}"
48
+ message << "\nextra: #{@extra.inspect}" unless @extra.empty?
49
+ message << "\nmissing: #{@missing.inspect}" unless @missing.empty?
50
+ message
51
+ end
52
+
53
+ def negative_failure_message
54
+ "expected to include more than #{@expected.inspect}"
55
+ end
56
+
57
+ def to_s
58
+ "include only #{@expected.inspect}"
59
+ end
60
+ end
61
+
62
+ # Unlike checking that two Enumerables are equal, where the
63
+ # objects in corresponding positions must be equal, this will
64
+ # allow you to ensure that an Enumerable has all the objects
65
+ # you expect, in any order; no more, no less.
66
+ def include_only(*expected)
67
+ IncludeOnly.new(*expected)
68
+ end
69
+ end
70
+
71
+ Spec::Runner.configure do |config|
72
+ include Matchers
73
+ end
74
+
75
+ def capturing_output
76
+ output = StringIO.new
77
+ $stdout = output
78
+ yield
79
+ output.string
80
+ ensure
81
+ $stdout = STDOUT
82
+ end
83
+
84
+ def capturing_stderr
85
+ output = StringIO.new
86
+ $stderr = output
87
+ yield
88
+ output.string
89
+ ensure
90
+ $stderr = STDERR
91
+ end
92
+
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ hash: 63
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Pivotal Labs
@@ -9,19 +15,25 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-11-16 00:00:00 -08:00
18
+ date: 2010-07-09 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: hoe
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 1
32
+ - 5
33
+ - 0
23
34
  version: 1.5.0
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  description: Html Builder library.
26
38
  email: erector@googlegroups.compivotallabsopensource@googlegroups.com
27
39
  executables:
@@ -30,16 +42,29 @@ extensions: []
30
42
 
31
43
  extra_rdoc_files:
32
44
  - README.txt
45
+ - spec/erector/sample-file.txt
33
46
  files:
34
- - lib/erector/erect.rb
35
- - lib/erector/erected.rb
47
+ - lib/erector/after_initialize.rb
48
+ - lib/erector/caching.rb
49
+ - lib/erector/convenience.rb
50
+ - lib/erector/dependencies.rb
51
+ - lib/erector/dependency.rb
52
+ - lib/erector/erect/erect.rb
53
+ - lib/erector/erect/erected.rb
54
+ - lib/erector/erect/indenting.rb
55
+ - lib/erector/erect/rhtml.treetop
56
+ - lib/erector/errors.rb
57
+ - lib/erector/extensions/hash.rb
36
58
  - lib/erector/extensions/object.rb
37
59
  - lib/erector/externals.rb
38
- - lib/erector/indenting.rb
60
+ - lib/erector/html.rb
39
61
  - lib/erector/inline.rb
62
+ - lib/erector/jquery.rb
40
63
  - lib/erector/mixin.rb
64
+ - lib/erector/needs.rb
65
+ - lib/erector/output.rb
41
66
  - lib/erector/rails/extensions/action_controller.rb
42
- - lib/erector/rails/extensions/rails_widget/rails_helpers.rb
67
+ - lib/erector/rails/extensions/rails_helpers.rb
43
68
  - lib/erector/rails/extensions/rails_widget.rb
44
69
  - lib/erector/rails/rails_form_builder.rb
45
70
  - lib/erector/rails/rails_version.rb
@@ -47,12 +72,13 @@ files:
47
72
  - lib/erector/rails/template_handlers/rb_handler.rb
48
73
  - lib/erector/rails.rb
49
74
  - lib/erector/raw_string.rb
50
- - lib/erector/rhtml.treetop
75
+ - lib/erector/sass.rb
51
76
  - lib/erector/unicode.rb
52
77
  - lib/erector/unicode_builder.rb
53
78
  - lib/erector/version.rb
54
79
  - lib/erector/widget.rb
55
80
  - lib/erector/widgets/environment_badge.rb
81
+ - lib/erector/widgets/external_renderer.rb
56
82
  - lib/erector/widgets/field_table.rb
57
83
  - lib/erector/widgets/form.rb
58
84
  - lib/erector/widgets/page.rb
@@ -63,25 +89,30 @@ files:
63
89
  - README.txt
64
90
  - VERSION.yml
65
91
  - bin/erector
66
- - spec/core_spec_suite.rb
67
92
  - spec/erect/erect_rails_spec.rb
68
93
  - spec/erect/erect_spec.rb
69
94
  - spec/erect/erected_spec.rb
70
95
  - spec/erect/rhtml_parser_spec.rb
71
- - spec/erector/external_spec.rb
96
+ - spec/erector/caching_spec.rb
97
+ - spec/erector/convenience_spec.rb
98
+ - spec/erector/dependency_spec.rb
99
+ - spec/erector/externals_spec.rb
100
+ - spec/erector/html_spec.rb
72
101
  - spec/erector/indentation_spec.rb
73
102
  - spec/erector/inline_spec.rb
103
+ - spec/erector/jquery_spec.rb
74
104
  - spec/erector/mixin_spec.rb
105
+ - spec/erector/needs_spec.rb
106
+ - spec/erector/output_spec.rb
107
+ - spec/erector/sample-file.txt
108
+ - spec/erector/sass_spec.rb
75
109
  - spec/erector/unicode_builder_spec.rb
76
110
  - spec/erector/widget_spec.rb
77
111
  - spec/erector/widgets/field_table_spec.rb
78
112
  - spec/erector/widgets/form_spec.rb
79
113
  - spec/erector/widgets/page_spec.rb
80
114
  - spec/erector/widgets/table_spec.rb
81
- - spec/rails_spec_suite.rb
82
- - spec/spec.opts
83
115
  - spec/spec_helper.rb
84
- - spec/spec_suite.rb
85
116
  has_rdoc: true
86
117
  homepage: http://erector.rubyforge.org
87
118
  licenses: []
@@ -93,21 +124,27 @@ rdoc_options:
93
124
  require_paths:
94
125
  - lib
95
126
  required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
96
128
  requirements:
97
129
  - - ">="
98
130
  - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
99
134
  version: "0"
100
- version:
101
135
  required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
102
137
  requirements:
103
138
  - - ">="
104
139
  - !ruby/object:Gem::Version
140
+ hash: 3
141
+ segments:
142
+ - 0
105
143
  version: "0"
106
- version:
107
144
  requirements: []
108
145
 
109
146
  rubyforge_project: erector
110
- rubygems_version: 1.3.5
147
+ rubygems_version: 1.3.7
111
148
  signing_key:
112
149
  specification_version: 3
113
150
  summary: Html Builder library.