erector 0.3.110 → 0.4.191
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +1 -1
- data/bin/erect +0 -0
- data/lib/erector.rb +13 -10
- data/lib/erector/doc.rb +138 -0
- data/lib/erector/erected.rb +1 -1
- data/lib/erector/rails.rb +6 -0
- data/lib/erector/rails/extensions/action_controller.rb +17 -0
- data/lib/erector/rails/extensions/action_view.rb +21 -0
- data/lib/erector/{helpers.rb → rails/extensions/widget.rb} +21 -14
- data/lib/erector/rails/supported_rails_versions.rb +11 -0
- data/lib/erector/rails/template_handlers/action_view_template_handler.rb +92 -0
- data/lib/erector/rhtml.treetop +6 -1
- data/lib/erector/unicode.rb +18185 -0
- data/lib/erector/unicode_builder.rb +67 -0
- data/lib/erector/widget.rb +86 -82
- data/spec/core_spec_suite.rb +3 -0
- data/spec/erect/erect_spec.rb +1 -4
- data/spec/erect/erected_spec.rb +1 -4
- data/spec/erect/rhtml_parser_spec.rb +9 -7
- data/spec/erector/doc_spec.rb +55 -0
- data/spec/erector/indentation_spec.rb +127 -0
- data/spec/erector/unicode_builder_spec.rb +75 -0
- data/spec/erector/widget_spec.rb +339 -175
- data/spec/erector/widgets/table_spec.rb +26 -37
- data/spec/rails_spec_suite.rb +3 -0
- data/spec/spec_helper.rb +11 -6
- data/spec/spec_suite.rb +44 -3
- metadata +54 -28
- data/lib/erector/extensions/action_controller.rb +0 -24
- data/lib/erector/extensions/action_view_template_handler.rb +0 -66
- data/lib/erector/html_parts.rb +0 -63
- data/spec/erector/extensions/render_widget_spec.rb +0 -68
- data/spec/erector/extensions/template_handler_spec.rb +0 -29
- data/spec/erector/rails_helpers_spec.rb +0 -149
- data/spec/rails/standard_helpers_spec.rb +0 -102
- data/spec/rails/view_spec.rb +0 -33
- data/spec/view_caching.rb +0 -30
- data/test/rails_root/app/views/template_handler_spec/test_page.rb +0 -8
@@ -1,43 +1,38 @@
|
|
1
1
|
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
2
|
|
3
|
-
#TODO: This is very confusing with column_a etc. Rewrite to use LastName, FirstName, Email or something like that.
|
4
|
-
|
5
3
|
module TableSpec
|
6
4
|
class DefaultsTestTable < Erector::Widgets::Table
|
7
|
-
column :
|
8
|
-
column :
|
9
|
-
column :
|
5
|
+
column :first_name
|
6
|
+
column :last_name
|
7
|
+
column :email
|
10
8
|
row_classes :even, :odd
|
11
9
|
end
|
12
10
|
|
13
11
|
class CustomHeadingTable < Erector::Widgets::Table
|
14
|
-
column :
|
15
|
-
column :
|
12
|
+
column :first_name, "Column - First Name"
|
13
|
+
column :email, lambda {|id| span id}
|
16
14
|
end
|
17
15
|
|
18
16
|
class CustomCellTable < Erector::Widgets::Table
|
19
|
-
column :
|
20
|
-
span obj.
|
17
|
+
column :first_name do |obj|
|
18
|
+
span obj.first_name
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
22
|
describe ::Erector::Widgets::Table do
|
25
23
|
describe "with custom heading" do
|
24
|
+
attr_reader :html, :doc
|
26
25
|
before do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
:row_objects => []
|
31
|
-
)
|
32
|
-
widget.to_s
|
33
|
-
end
|
26
|
+
widget = CustomHeadingTable.new(nil, :row_objects => [])
|
27
|
+
@html = widget.to_s
|
28
|
+
@doc = Hpricot(html)
|
34
29
|
end
|
35
30
|
|
36
31
|
it "renders a custom heading text and procs" do
|
37
32
|
table = doc.at("table")
|
38
33
|
table.search("th").map {|c| c.inner_html}.should == [
|
39
|
-
"Column -
|
40
|
-
"<span>
|
34
|
+
"Column - First Name",
|
35
|
+
"<span>email</span>"
|
41
36
|
]
|
42
37
|
end
|
43
38
|
|
@@ -47,15 +42,12 @@ module TableSpec
|
|
47
42
|
end
|
48
43
|
|
49
44
|
describe "with custom cell content" do
|
45
|
+
attr_reader :html, :doc
|
50
46
|
before do
|
51
|
-
@object1 = Struct.new(:
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
:row_objects => [@object1]
|
56
|
-
)
|
57
|
-
widget.to_s
|
58
|
-
end
|
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)
|
59
51
|
end
|
60
52
|
|
61
53
|
it "renders custom cell html" do
|
@@ -66,24 +58,21 @@ module TableSpec
|
|
66
58
|
end
|
67
59
|
|
68
60
|
describe "with default heading and cell definitions" do
|
61
|
+
attr_reader :html, :doc
|
69
62
|
before do
|
70
|
-
@object1 = Struct.new(:
|
71
|
-
@object2 = Struct.new(:
|
72
|
-
@object3 = Struct.new(:
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
:row_objects => [@object1, @object2, @object3]
|
77
|
-
)
|
78
|
-
widget.to_s
|
79
|
-
end
|
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)
|
80
69
|
@table = doc.at("table")
|
81
70
|
end
|
82
71
|
|
83
72
|
it "renders column titles" do
|
84
73
|
title_row = @table.at("tr")
|
85
74
|
titles = title_row.search("th").collect {|heading| heading.inner_html}
|
86
|
-
titles.should == [ "
|
75
|
+
titles.should == [ "First Name", "Last Name", "Email" ]
|
87
76
|
end
|
88
77
|
|
89
78
|
it "renders data" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,24 @@
|
|
1
1
|
dir = File.dirname(__FILE__)
|
2
2
|
require "rubygems"
|
3
|
-
require "active_record"
|
4
|
-
require "spec"
|
5
|
-
require "#{dir}/view_caching"
|
6
3
|
$LOAD_PATH.unshift("#{dir}/../lib")
|
7
4
|
require "erector"
|
5
|
+
require "erector/rails"
|
8
6
|
require "hpricot"
|
9
|
-
require "
|
7
|
+
require "rr"
|
8
|
+
require 'tempfile'
|
9
|
+
require 'ostruct'
|
10
|
+
require 'treetop'
|
11
|
+
require "erector/erect"
|
12
|
+
require "erector/erected"
|
13
|
+
require "spec"
|
14
|
+
|
10
15
|
|
11
16
|
Spec::Runner.configure do |config|
|
12
|
-
config.
|
17
|
+
config.mock_with :rr
|
13
18
|
end
|
14
19
|
|
15
20
|
# This mimics Rails load path and dependency stuff
|
16
|
-
RAILS_ROOT = File.expand_path("#{File.dirname(__FILE__)}
|
21
|
+
RAILS_ROOT = File.expand_path("#{File.dirname(__FILE__)}/rails_root") unless defined?(RAILS_ROOT)
|
17
22
|
#$: << "#{RAILS_ROOT}/app"
|
18
23
|
module Views
|
19
24
|
module TemplateHandlerSpec
|
data/spec/spec_suite.rb
CHANGED
@@ -1,4 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
4
41
|
end
|
42
|
+
|
43
|
+
if $0 == __FILE__
|
44
|
+
SpecSuite.all
|
45
|
+
end
|
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.
|
4
|
+
version: 0.4.191
|
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: 2008-
|
12
|
+
date: 2008-07-29 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -49,41 +49,67 @@ extensions: []
|
|
49
49
|
extra_rdoc_files:
|
50
50
|
- README.txt
|
51
51
|
files:
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
- spec/core_spec_suite.rb
|
54
|
+
- spec/rails
|
55
|
+
- spec/rails/rails_root
|
56
|
+
- spec/rails/rails_root/doc
|
57
|
+
- spec/rails/rails_root/config
|
58
|
+
- spec/rails/rails_root/config/environments
|
59
|
+
- spec/rails/rails_root/config/initializers
|
60
|
+
- spec/rails/rails_root/spec
|
61
|
+
- spec/rails/rails_root/spec/extensions
|
62
|
+
- spec/rails/rails_root/script
|
63
|
+
- spec/rails/rails_root/script/process
|
64
|
+
- spec/rails/rails_root/script/performance
|
65
|
+
- spec/rails/rails_root/app
|
66
|
+
- spec/rails/rails_root/app/views
|
67
|
+
- spec/rails/rails_root/app/views/template_handler_spec
|
68
|
+
- spec/rails/rails_root/app/controllers
|
69
|
+
- spec/rails/rails_root/app/helpers
|
70
|
+
- spec/rails/rails_root/public
|
71
|
+
- spec/rails/rails_root/public/javascripts
|
72
|
+
- spec/rails/rails_root/public/images
|
73
|
+
- spec/rails/extensions
|
74
|
+
- spec/rails_spec_suite.rb
|
52
75
|
- spec/erect
|
76
|
+
- spec/erect/rhtml_parser_spec.rb
|
53
77
|
- spec/erect/erect_spec.rb
|
54
78
|
- spec/erect/erected_spec.rb
|
55
|
-
- spec/erect/rhtml_parser_spec.rb
|
56
79
|
- spec/erector
|
57
|
-
- spec/erector/extensions
|
58
|
-
- spec/erector/extensions/render_widget_spec.rb
|
59
|
-
- spec/erector/extensions/template_handler_spec.rb
|
60
|
-
- spec/erector/rails_helpers_spec.rb
|
61
|
-
- spec/erector/widget_spec.rb
|
62
80
|
- spec/erector/widgets
|
63
81
|
- spec/erector/widgets/table_spec.rb
|
64
|
-
- spec/
|
65
|
-
- spec/
|
66
|
-
- spec/
|
67
|
-
- spec/
|
82
|
+
- spec/erector/doc_spec.rb
|
83
|
+
- spec/erector/extensions
|
84
|
+
- spec/erector/widget_spec.rb
|
85
|
+
- spec/erector/indentation_spec.rb
|
86
|
+
- spec/erector/unicode_builder_spec.rb
|
68
87
|
- spec/spec_suite.rb
|
69
|
-
-
|
88
|
+
- lib/erector.rb
|
70
89
|
- lib/erector
|
90
|
+
- lib/erector/widgets
|
91
|
+
- lib/erector/widgets/table.rb
|
92
|
+
- lib/erector/rails
|
93
|
+
- lib/erector/rails/supported_rails_versions.rb
|
94
|
+
- lib/erector/rails/extensions
|
95
|
+
- lib/erector/rails/extensions/action_controller.rb
|
96
|
+
- lib/erector/rails/extensions/widget.rb
|
97
|
+
- lib/erector/rails/extensions/action_view.rb
|
98
|
+
- lib/erector/rails/template_handlers
|
99
|
+
- lib/erector/rails/template_handlers/action_view_template_handler.rb
|
100
|
+
- lib/erector/raw_string.rb
|
101
|
+
- lib/erector/widgets.rb
|
102
|
+
- lib/erector/widget.rb
|
71
103
|
- lib/erector/erect.rb
|
72
|
-
- lib/erector/
|
104
|
+
- lib/erector/unicode_builder.rb
|
105
|
+
- lib/erector/doc.rb
|
73
106
|
- lib/erector/extensions
|
74
|
-
- lib/erector/extensions/action_controller.rb
|
75
|
-
- lib/erector/extensions/action_view_template_handler.rb
|
76
107
|
- lib/erector/extensions/object.rb
|
77
|
-
- lib/erector/
|
78
|
-
- lib/erector/html_parts.rb
|
79
|
-
- lib/erector/indenting.rb
|
80
|
-
- lib/erector/raw_string.rb
|
108
|
+
- lib/erector/unicode.rb
|
81
109
|
- lib/erector/rhtml.treetop
|
82
|
-
- lib/erector/
|
83
|
-
- lib/erector/
|
84
|
-
- lib/erector/
|
85
|
-
- lib/erector/widgets.rb
|
86
|
-
- lib/erector.rb
|
110
|
+
- lib/erector/rails.rb
|
111
|
+
- lib/erector/indenting.rb
|
112
|
+
- lib/erector/erected.rb
|
87
113
|
- README.txt
|
88
114
|
- bin/erect
|
89
115
|
has_rdoc: true
|
@@ -109,9 +135,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
135
|
requirements: []
|
110
136
|
|
111
137
|
rubyforge_project: erector
|
112
|
-
rubygems_version: 1.
|
138
|
+
rubygems_version: 1.1.1
|
113
139
|
signing_key:
|
114
140
|
specification_version: 2
|
115
141
|
summary: Erector is a Builder-like view framework, inspired by Markaby but overcoming some of its flaws
|
116
|
-
test_files:
|
117
|
-
|
142
|
+
test_files: []
|
143
|
+
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module ActionController #:nodoc:
|
2
|
-
class Base
|
3
|
-
def render_widget(widget_class, assigns=@assigns)
|
4
|
-
render :text => render_widget_to_string(widget_class, assigns)
|
5
|
-
end
|
6
|
-
|
7
|
-
def render_widget_to_string(widget_class, assigns = @assigns)
|
8
|
-
add_variables_to_assigns
|
9
|
-
@rendered_widget = widget_class.new(@template, assigns.merge(:params => params))
|
10
|
-
@rendered_widget.to_s
|
11
|
-
end
|
12
|
-
|
13
|
-
def render_with_erector_widget(*options, &block)
|
14
|
-
if options.first.is_a?(Hash) && widget = options.first.delete(:widget)
|
15
|
-
render_widget widget, *options, &block
|
16
|
-
else
|
17
|
-
render_without_erector_widget *options, &block
|
18
|
-
end
|
19
|
-
end
|
20
|
-
alias_method_chain :render, :erector_widget
|
21
|
-
|
22
|
-
attr_reader :rendered_widget
|
23
|
-
end
|
24
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module ActionView #:nodoc:
|
2
|
-
module TemplateHandlers #:nodoc:
|
3
|
-
class Erector
|
4
|
-
def initialize(view)
|
5
|
-
@view = view
|
6
|
-
end
|
7
|
-
|
8
|
-
def render(template, local_assigns)
|
9
|
-
|
10
|
-
if template =~ /class ([\w:_]+)/
|
11
|
-
classname_from_template = $1
|
12
|
-
template_path = Inflector::underscore(classname_from_template)
|
13
|
-
else
|
14
|
-
template_path = @view.first_render
|
15
|
-
end
|
16
|
-
|
17
|
-
paths = template_path.split('/')
|
18
|
-
if paths.first == 'views'
|
19
|
-
paths.shift
|
20
|
-
template_path = paths.join('/')
|
21
|
-
end
|
22
|
-
|
23
|
-
found = false
|
24
|
-
@view.view_paths.each_with_index do |view_path, i|
|
25
|
-
full_path = "#{view_path}/#{template_path}.rb"
|
26
|
-
if File.exists?(full_path)
|
27
|
-
require_dependency full_path
|
28
|
-
found = true
|
29
|
-
break
|
30
|
-
else
|
31
|
-
partial_file_path = full_path.gsub(/\/([^\/]*)$/, '/_\1')
|
32
|
-
if File.exists?(partial_file_path)
|
33
|
-
require_dependency partial_file_path
|
34
|
-
found = true
|
35
|
-
break
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
return unless found
|
40
|
-
|
41
|
-
dot_rb = /\.rb$/
|
42
|
-
widget_class = paths.inject(Views) do |current_module, node|
|
43
|
-
current_module.const_get(node.gsub(dot_rb, '').camelize)
|
44
|
-
end
|
45
|
-
|
46
|
-
rendered_widget = widget_class.new(@view, @view.assigns)
|
47
|
-
assign_locals(rendered_widget, local_assigns)
|
48
|
-
rendered_widget.to_s
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
# TODO: move into widget
|
53
|
-
def assign_locals(widget, local_assigns)
|
54
|
-
widget.assign_locals(local_assigns)
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
ActionView::Base.instance_eval do
|
62
|
-
if respond_to?(:register_template_handler)
|
63
|
-
register_template_handler :rb, ActionView::TemplateHandlers::Erector
|
64
|
-
end
|
65
|
-
end
|
66
|
-
# ActionMailer::Base.register_template_extension('rb')
|
data/lib/erector/html_parts.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
module Erector
|
2
|
-
|
3
|
-
# An array to which is written a stream of HTML "parts" -- each part being an open tag, a string, a close tag, etc.
|
4
|
-
class HtmlParts < Array
|
5
|
-
def to_s
|
6
|
-
map do |part|
|
7
|
-
case part[:type].to_sym
|
8
|
-
when :open
|
9
|
-
part[:attributes] ?
|
10
|
-
"<#{part[:tagName]}#{format_attributes(part[:attributes])}>" :
|
11
|
-
"<#{part[:tagName]}>"
|
12
|
-
when :close
|
13
|
-
"</#{part[:tagName]}>"
|
14
|
-
when :empty
|
15
|
-
part[:attributes] ?
|
16
|
-
"<#{part[:tagName]}#{format_attributes(part[:attributes])} />" :
|
17
|
-
"<#{part[:tagName]} />"
|
18
|
-
when :text
|
19
|
-
part[:value].html_escape
|
20
|
-
when :instruct
|
21
|
-
"<?xml#{format_sorted(sort_for_xml_declaration(part[:attributes]))}?>"
|
22
|
-
end
|
23
|
-
end.join
|
24
|
-
end
|
25
|
-
|
26
|
-
protected
|
27
|
-
def format_attributes(attributes)
|
28
|
-
return "" if !attributes || attributes.empty?
|
29
|
-
return format_sorted(sorted(attributes))
|
30
|
-
end
|
31
|
-
|
32
|
-
def format_sorted(sorted)
|
33
|
-
results = ['']
|
34
|
-
sorted.each do |key, value|
|
35
|
-
if value
|
36
|
-
if value.is_a?(Array)
|
37
|
-
value = [value].flatten.join(' ')
|
38
|
-
end
|
39
|
-
results << "#{key}=\"#{value.html_escape}\""
|
40
|
-
end
|
41
|
-
end
|
42
|
-
return results.join(' ')
|
43
|
-
end
|
44
|
-
|
45
|
-
def sorted(attributes)
|
46
|
-
stringized = []
|
47
|
-
attributes.each do |key, value|
|
48
|
-
stringized << [key.to_s, value]
|
49
|
-
end
|
50
|
-
return stringized.sort
|
51
|
-
end
|
52
|
-
|
53
|
-
def sort_for_xml_declaration(attributes)
|
54
|
-
# correct order is "version, encoding, standalone" (XML 1.0 section 2.8).
|
55
|
-
# But we only try to put version before encoding for now.
|
56
|
-
stringized = []
|
57
|
-
attributes.each do |key, value|
|
58
|
-
stringized << [key.to_s, value]
|
59
|
-
end
|
60
|
-
return stringized.sort{|a, b| b <=> a}
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|