pivotal-erector 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +81 -0
- data/VERSION.yml +4 -0
- data/bin/erect +7 -0
- data/lib/erector/erect.rb +148 -0
- data/lib/erector/erected.rb +63 -0
- data/lib/erector/extensions/object.rb +18 -0
- data/lib/erector/indenting.rb +36 -0
- data/lib/erector/rails/extensions/action_controller/1.2.5/action_controller.rb +17 -0
- data/lib/erector/rails/extensions/action_controller/2.2.0/action_controller.rb +26 -0
- data/lib/erector/rails/extensions/action_controller.rb +8 -0
- data/lib/erector/rails/extensions/action_view.rb +21 -0
- data/lib/erector/rails/extensions/widget/1.2.5/widget.rb +18 -0
- data/lib/erector/rails/extensions/widget/2.2.0/widget.rb +36 -0
- data/lib/erector/rails/extensions/widget.rb +117 -0
- data/lib/erector/rails/supported_rails_versions.rb +14 -0
- data/lib/erector/rails/template_handlers/1.2.5/action_view_template_handler.rb +32 -0
- data/lib/erector/rails/template_handlers/2.0.0/action_view_template_handler.rb +36 -0
- data/lib/erector/rails/template_handlers/2.1.0/action_view_template_handler.rb +31 -0
- data/lib/erector/rails/template_handlers/2.2.0/action_view_template_handler.rb +46 -0
- data/lib/erector/rails/template_handlers/action_view_template_handler.rb +14 -0
- data/lib/erector/rails.rb +6 -0
- data/lib/erector/raw_string.rb +8 -0
- data/lib/erector/rhtml.treetop +156 -0
- data/lib/erector/unicode.rb +18185 -0
- data/lib/erector/unicode_builder.rb +67 -0
- data/lib/erector/version.rb +10 -0
- data/lib/erector/widget.rb +510 -0
- data/lib/erector/widgets/table.rb +96 -0
- data/lib/erector/widgets.rb +2 -0
- data/lib/erector.rb +16 -0
- data/spec/core_spec_suite.rb +3 -0
- data/spec/erect/erect_spec.rb +145 -0
- data/spec/erect/erected_spec.rb +80 -0
- data/spec/erect/rhtml_parser_spec.rb +318 -0
- data/spec/erector/indentation_spec.rb +136 -0
- data/spec/erector/unicode_builder_spec.rb +75 -0
- data/spec/erector/widget_spec.rb +657 -0
- data/spec/erector/widgets/table_spec.rb +99 -0
- data/spec/rails_spec_suite.rb +3 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/spec_suite.rb +45 -0
- metadata +118 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module TableSpec
|
4
|
+
class DefaultsTestTable < Erector::Widgets::Table
|
5
|
+
column :first_name
|
6
|
+
column :last_name
|
7
|
+
column :email
|
8
|
+
row_classes :even, :odd
|
9
|
+
end
|
10
|
+
|
11
|
+
class CustomHeadingTable < Erector::Widgets::Table
|
12
|
+
column :first_name, "Column - First Name"
|
13
|
+
column :email, lambda {|id| span id}
|
14
|
+
end
|
15
|
+
|
16
|
+
class CustomCellTable < Erector::Widgets::Table
|
17
|
+
column :first_name do |obj|
|
18
|
+
span obj.first_name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ::Erector::Widgets::Table do
|
23
|
+
describe "with custom heading" do
|
24
|
+
attr_reader :html, :doc
|
25
|
+
before do
|
26
|
+
widget = CustomHeadingTable.new(nil, :row_objects => [])
|
27
|
+
@html = widget.to_s
|
28
|
+
@doc = Hpricot(html)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "renders a custom heading text and procs" do
|
32
|
+
table = doc.at("table")
|
33
|
+
table.search("th").map {|c| c.inner_html}.should == [
|
34
|
+
"Column - First Name",
|
35
|
+
"<span>email</span>"
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
it "renders a tbody to be compatible with IE6" do
|
40
|
+
doc.at("tbody").should_not be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "with custom cell content" do
|
45
|
+
attr_reader :html, :doc
|
46
|
+
before do
|
47
|
+
@object1 = Struct.new(:first_name).new("Hello")
|
48
|
+
widget = CustomCellTable.new(nil, :row_objects => [@object1])
|
49
|
+
@html = widget.to_s
|
50
|
+
@doc = Hpricot(html)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "renders custom cell html" do
|
54
|
+
table = doc.at("table")
|
55
|
+
row = table.search("tr")[1]
|
56
|
+
row.at("td").inner_html.should == "<span>Hello</span>"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "with default heading and cell definitions" do
|
61
|
+
attr_reader :html, :doc
|
62
|
+
before do
|
63
|
+
@object1 = Struct.new(:first_name, :last_name, :email).new(1, 2, 3)
|
64
|
+
@object2 = Struct.new(:first_name, :last_name, :email).new(4, 5, 6)
|
65
|
+
@object3 = Struct.new(:first_name, :last_name, :email).new(7, 8, 9)
|
66
|
+
widget = DefaultsTestTable.new(nil, :row_objects => [@object1, @object2, @object3])
|
67
|
+
@html = widget.to_s
|
68
|
+
@doc = Hpricot(html)
|
69
|
+
@table = doc.at("table")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "renders column titles" do
|
73
|
+
title_row = @table.at("tr")
|
74
|
+
titles = title_row.search("th").collect {|heading| heading.inner_html}
|
75
|
+
titles.should == [ "First Name", "Last Name", "Email" ]
|
76
|
+
end
|
77
|
+
|
78
|
+
it "renders data" do
|
79
|
+
data_rows = @table.search("tr")[1..-1]
|
80
|
+
cell_values = data_rows.collect do |row|
|
81
|
+
row.search("td").collect {|col| col.inner_html}
|
82
|
+
end
|
83
|
+
|
84
|
+
cell_values.should == [
|
85
|
+
['1', '2', '3'],
|
86
|
+
['4', '5', '6'],
|
87
|
+
['7', '8', '9'],
|
88
|
+
]
|
89
|
+
end
|
90
|
+
|
91
|
+
it "renders the row classes" do
|
92
|
+
data_rows = @table.search("tr")[1..-1]
|
93
|
+
data_rows[0]['class'].should == 'even'
|
94
|
+
data_rows[1]['class'].should == 'odd'
|
95
|
+
data_rows[2]['class'].should == 'even'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require "rubygems"
|
3
|
+
$LOAD_PATH.unshift("#{dir}/../lib")
|
4
|
+
require "erector"
|
5
|
+
require "erector/rails"
|
6
|
+
require "hpricot"
|
7
|
+
require "rr"
|
8
|
+
require 'tempfile'
|
9
|
+
require 'ostruct'
|
10
|
+
require 'treetop'
|
11
|
+
require "erector/erect"
|
12
|
+
require "erector/erected"
|
13
|
+
require "spec"
|
14
|
+
require "spec/autorun"
|
15
|
+
|
16
|
+
Spec::Runner.configure do |config|
|
17
|
+
config.mock_with :rr
|
18
|
+
end
|
19
|
+
|
20
|
+
# This mimics Rails load path and dependency stuff
|
21
|
+
RAILS_ROOT = File.expand_path("#{File.dirname(__FILE__)}/rails_root") unless defined?(RAILS_ROOT)
|
22
|
+
#$: << "#{RAILS_ROOT}/app"
|
23
|
+
module Views
|
24
|
+
module TemplateHandlerSpec
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
# uncomment this to find leftover debug putses
|
30
|
+
#
|
31
|
+
# alias :original_puts :puts
|
32
|
+
# def puts(string ="")
|
33
|
+
# super string.to_s + "\s(#{caller.first.match(/(\w+\.\w+:\d+)|Rakefile:\d+/)[0]})"
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# alias :original_p :p
|
37
|
+
# def p(string="")
|
38
|
+
# original_puts "\s(#{caller.first.match(/(\w+\.\w+:\d+)|Rakefile:\d+/)[0]})"
|
39
|
+
# super(string)
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# alias :original_print :print
|
43
|
+
# def print(string="")
|
44
|
+
# super string + "\s(#{caller.first.match(/(\w+\.\w+:\d+)|Rakefile:\d+/)[0]})"
|
45
|
+
# end
|
46
|
+
unless '1.9'.respond_to?(:force_encoding)
|
47
|
+
String.class_eval do
|
48
|
+
begin
|
49
|
+
remove_method :chars
|
50
|
+
rescue NameError
|
51
|
+
# OK
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_suite.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
class SpecSuite
|
2
|
+
class << self
|
3
|
+
def all
|
4
|
+
system("ruby #{dir}/core_spec_suite.rb") || raise("Core Spec Suite failed")
|
5
|
+
dir = File.dirname(__FILE__)
|
6
|
+
require "#{dir}/../lib/erector/rails/supported_rails_versions"
|
7
|
+
versions = Erector::Rails::SUPPORTED_RAILS_VERSIONS.keys.sort.reverse
|
8
|
+
versions.each do |rails_version|
|
9
|
+
puts "Running rails_spec_suite for Rails version #{rails_version}"
|
10
|
+
run_with_rails_version("#{dir}/rails_spec_suite.rb", rails_version) ||
|
11
|
+
"Suite failed for Rails version #{rails_version}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def core
|
16
|
+
run Dir["#{dir}/{erect,erector}/**/*_spec.rb"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def rails
|
20
|
+
Dir.chdir("#{dir}/rails_root") do
|
21
|
+
run Dir["spec/**/*_spec.rb"]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def run(files)
|
26
|
+
files.each do |file|
|
27
|
+
require file
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def run_with_rails_version(suite_path, rails_version)
|
33
|
+
system("export RAILS_VERSION=#{rails_version} && ruby #{suite_path}") ||
|
34
|
+
raise("Failed for version #{rails_version}")
|
35
|
+
end
|
36
|
+
|
37
|
+
def dir
|
38
|
+
File.dirname(__FILE__)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if $0 == __FILE__
|
44
|
+
SpecSuite.all
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pivotal-erector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Chaffee
|
8
|
+
- Brian Takita
|
9
|
+
- Jeff Dean
|
10
|
+
- Jim Kingdon
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
|
15
|
+
date: 2009-04-05 00:00:00 -07:00
|
16
|
+
default_executable: erect
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: treetop
|
20
|
+
type: :runtime
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.3
|
27
|
+
version:
|
28
|
+
description: Html Builder library.
|
29
|
+
email: erector-devel@rubyforge.org
|
30
|
+
executables:
|
31
|
+
- erect
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files:
|
35
|
+
- README.txt
|
36
|
+
files:
|
37
|
+
- README.txt
|
38
|
+
- VERSION.yml
|
39
|
+
- bin/erect
|
40
|
+
- lib/erector.rb
|
41
|
+
- lib/erector/erect.rb
|
42
|
+
- lib/erector/erected.rb
|
43
|
+
- lib/erector/extensions/object.rb
|
44
|
+
- lib/erector/indenting.rb
|
45
|
+
- lib/erector/rails.rb
|
46
|
+
- lib/erector/rails/extensions/action_controller.rb
|
47
|
+
- lib/erector/rails/extensions/action_controller/1.2.5/action_controller.rb
|
48
|
+
- lib/erector/rails/extensions/action_controller/2.2.0/action_controller.rb
|
49
|
+
- lib/erector/rails/extensions/action_view.rb
|
50
|
+
- lib/erector/rails/extensions/widget.rb
|
51
|
+
- lib/erector/rails/extensions/widget/1.2.5/widget.rb
|
52
|
+
- lib/erector/rails/extensions/widget/2.2.0/widget.rb
|
53
|
+
- lib/erector/rails/supported_rails_versions.rb
|
54
|
+
- lib/erector/rails/template_handlers/1.2.5/action_view_template_handler.rb
|
55
|
+
- lib/erector/rails/template_handlers/2.0.0/action_view_template_handler.rb
|
56
|
+
- lib/erector/rails/template_handlers/2.1.0/action_view_template_handler.rb
|
57
|
+
- lib/erector/rails/template_handlers/2.2.0/action_view_template_handler.rb
|
58
|
+
- lib/erector/rails/template_handlers/action_view_template_handler.rb
|
59
|
+
- lib/erector/raw_string.rb
|
60
|
+
- lib/erector/rhtml.treetop
|
61
|
+
- lib/erector/unicode.rb
|
62
|
+
- lib/erector/unicode_builder.rb
|
63
|
+
- lib/erector/version.rb
|
64
|
+
- lib/erector/widget.rb
|
65
|
+
- lib/erector/widgets.rb
|
66
|
+
- lib/erector/widgets/table.rb
|
67
|
+
- spec/core_spec_suite.rb
|
68
|
+
- spec/erect/erect_spec.rb
|
69
|
+
- spec/erect/erected_spec.rb
|
70
|
+
- spec/erect/rhtml_parser_spec.rb
|
71
|
+
- spec/erector/indentation_spec.rb
|
72
|
+
- spec/erector/unicode_builder_spec.rb
|
73
|
+
- spec/erector/widget_spec.rb
|
74
|
+
- spec/erector/widgets/table_spec.rb
|
75
|
+
- spec/rails_spec_suite.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- spec/spec_suite.rb
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: http://erector.rubyforge.org/
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --charset=UTF-8
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
version:
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: "0"
|
96
|
+
version:
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.2.0
|
101
|
+
signing_key:
|
102
|
+
specification_version: 2
|
103
|
+
summary: Html Builder library.
|
104
|
+
test_files:
|
105
|
+
- spec/erector
|
106
|
+
- spec/erector/widgets
|
107
|
+
- spec/erector/widgets/table_spec.rb
|
108
|
+
- spec/erector/unicode_builder_spec.rb
|
109
|
+
- spec/erector/widget_spec.rb
|
110
|
+
- spec/erector/indentation_spec.rb
|
111
|
+
- spec/rails_spec_suite.rb
|
112
|
+
- spec/spec_suite.rb
|
113
|
+
- spec/core_spec_suite.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
- spec/erect
|
116
|
+
- spec/erect/erected_spec.rb
|
117
|
+
- spec/erect/erect_spec.rb
|
118
|
+
- spec/erect/rhtml_parser_spec.rb
|