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,68 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
-
|
3
|
-
module BaseSpec
|
4
|
-
class TestWidgetController < ActionController::Base
|
5
|
-
def index_with_implicit_assigns
|
6
|
-
@foobar = "foobar"
|
7
|
-
render_widget Erector::TestWidget
|
8
|
-
end
|
9
|
-
|
10
|
-
def index_with_explicit_assigns
|
11
|
-
render_widget Erector::TestWidget, :foobar => "foobar"
|
12
|
-
end
|
13
|
-
|
14
|
-
def index_with_render_colon_widget
|
15
|
-
render :widget => Erector::TestWidget, :foobar => "foobar"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Erector::TestWidget < Erector::Widget
|
20
|
-
def render
|
21
|
-
text @foobar
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe TestWidgetController, "rendering widgets" do
|
26
|
-
before do
|
27
|
-
@controller = BaseSpec::TestWidgetController.new
|
28
|
-
@request = ActionController::TestRequest.new
|
29
|
-
@response = ActionController::TestResponse.new
|
30
|
-
@controller.send(:initialize_template_class, @response)
|
31
|
-
@controller.send(:assign_shortcuts, @request, @response)
|
32
|
-
class << @controller
|
33
|
-
public :rendered_widget, :render
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "#render_widget" do
|
38
|
-
it "assigns to @rendered_widget" do
|
39
|
-
@controller.rendered_widget.should be_nil
|
40
|
-
@controller.render_widget Erector::TestWidget
|
41
|
-
@controller.rendered_widget.should be_instance_of(Erector::TestWidget)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "instantiates a widget with implicit assigns" do
|
45
|
-
@controller.index_with_implicit_assigns
|
46
|
-
@response.body.should == "foobar"
|
47
|
-
end
|
48
|
-
|
49
|
-
it "instantiates a widget with explicit assigns" do
|
50
|
-
@controller.index_with_explicit_assigns
|
51
|
-
@response.body.should == "foobar"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#render :widget" do
|
56
|
-
it "assigns to @rendered_widget" do
|
57
|
-
@controller.rendered_widget.should be_nil
|
58
|
-
@controller.render :widget => Erector::TestWidget
|
59
|
-
@controller.rendered_widget.should be_instance_of(Erector::TestWidget)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "instantiates a widget with explicit assigns" do
|
63
|
-
@controller.index_with_render_colon_widget
|
64
|
-
@response.body.should == "foobar"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
-
|
3
|
-
module TemplateHandlerSpec
|
4
|
-
|
5
|
-
class TemplateHandlerSpecController < ActionController::Base
|
6
|
-
end
|
7
|
-
|
8
|
-
describe ActionView::TemplateHandlers::Erector do
|
9
|
-
|
10
|
-
before do
|
11
|
-
@controller = TemplateHandlerSpecController.new
|
12
|
-
@request = ActionController::TestRequest.new
|
13
|
-
@response = ActionController::TestResponse.new
|
14
|
-
@controller.send(:initialize_template_class, @response)
|
15
|
-
@controller.send(:assign_shortcuts, @request, @response)
|
16
|
-
class << @controller
|
17
|
-
public :rendered_widget, :render
|
18
|
-
end
|
19
|
-
@controller.append_view_path("#{RAILS_ROOT}/app/views")
|
20
|
-
end
|
21
|
-
|
22
|
-
it "assigns locals" do
|
23
|
-
handler = ActionView::TemplateHandlers::Erector.new(@controller)
|
24
|
-
handler.render("class Views::TemplateHandlerSpec::TestPartial", {:foo => "bar"}).should ==
|
25
|
-
"<div class=\"partial\">bar</div>"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
@@ -1,149 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
-
require 'ostruct'
|
3
|
-
|
4
|
-
module RailsHelpersSpec
|
5
|
-
|
6
|
-
class RailsHelpersSpecController < ActionController::Base
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "Rails helpers" do
|
10
|
-
|
11
|
-
before do
|
12
|
-
@controller = RailsHelpersSpecController.new
|
13
|
-
@request = ActionController::TestRequest.new
|
14
|
-
@response = ActionController::TestResponse.new
|
15
|
-
@controller.send(:initialize_template_class, @response)
|
16
|
-
@controller.send(:assign_shortcuts, @request, @response)
|
17
|
-
@controller.send(:initialize_current_url)
|
18
|
-
class << @controller
|
19
|
-
public :rendered_widget, :render
|
20
|
-
|
21
|
-
attr_accessor :user # dummy instance variable for assigns testing
|
22
|
-
end
|
23
|
-
@controller.append_view_path("#{RAILS_ROOT}/app/views")
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "returning raw text" do
|
27
|
-
it "image_tag" do
|
28
|
-
class Erector::TestWidget < Erector::Widget
|
29
|
-
def render
|
30
|
-
image_tag("rails.png")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
@controller.render :widget => Erector::TestWidget
|
34
|
-
@response.body.should == "<img alt=\"Rails\" src=\"/images/rails.png\" />"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "javascript_include_tag" do
|
38
|
-
class Erector::TestWidget < Erector::Widget
|
39
|
-
def render
|
40
|
-
javascript_include_tag("rails")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
@controller.render :widget => Erector::TestWidget
|
44
|
-
@response.body.should == "<script src=\"/javascripts/rails.js\" type=\"text/javascript\"></script>"
|
45
|
-
end
|
46
|
-
|
47
|
-
it "define_javascript_functions" do
|
48
|
-
class Erector::TestWidget < Erector::Widget
|
49
|
-
def render
|
50
|
-
define_javascript_functions
|
51
|
-
end
|
52
|
-
end
|
53
|
-
@controller.render :widget => Erector::TestWidget
|
54
|
-
@response.body.should =~ /^<script type=\"text\/javascript\">\n/
|
55
|
-
end
|
56
|
-
|
57
|
-
it "stylesheet_link_tag" do
|
58
|
-
class Erector::TestWidget < Erector::Widget
|
59
|
-
def render
|
60
|
-
stylesheet_link_tag("rails")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
@controller.render :widget => Erector::TestWidget
|
64
|
-
@response.body.should == "<link href=\"/stylesheets/rails.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
|
65
|
-
end
|
66
|
-
|
67
|
-
def sortable_js_for(element_id, url)
|
68
|
-
"Sortable.create(\"#{element_id}\", {onUpdate:function(){new Ajax.Request('#{url}', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(\"#{element_id}\")})}})"
|
69
|
-
end
|
70
|
-
|
71
|
-
it "sortable_element" do
|
72
|
-
class Erector::TestWidget < Erector::Widget
|
73
|
-
def render
|
74
|
-
sortable_element("rails", :url => "/foo")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
@controller.render :widget => Erector::TestWidget
|
78
|
-
@response.body.should ==
|
79
|
-
"<script type=\"text/javascript\">\n//<![CDATA[\n" +
|
80
|
-
sortable_js_for("rails", "/foo") +
|
81
|
-
"\n//]]>\n</script>"
|
82
|
-
end
|
83
|
-
|
84
|
-
it "sortable_element_js" do
|
85
|
-
class Erector::TestWidget < Erector::Widget
|
86
|
-
def render
|
87
|
-
sortable_element_js("rails", :url => "/foo")
|
88
|
-
end
|
89
|
-
end
|
90
|
-
@controller.render :widget => Erector::TestWidget
|
91
|
-
@response.body.should == sortable_js_for("rails", "/foo") + ";"
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
#Note: "text_field_with_auto_complete" is now a plugin, which makes it difficult to test inside the Erector project
|
96
|
-
end
|
97
|
-
|
98
|
-
# :link_to_function,
|
99
|
-
# :link_to,
|
100
|
-
# :link_to_remote,
|
101
|
-
# :mail_to,
|
102
|
-
# :button_to,
|
103
|
-
# :submit_tag,
|
104
|
-
|
105
|
-
describe "which html-escape their first parameter:" do
|
106
|
-
it "link_to_function with name" do
|
107
|
-
class Erector::TestWidget < Erector::Widget
|
108
|
-
def render
|
109
|
-
link_to_function("hi", "alert('hi')")
|
110
|
-
end
|
111
|
-
end
|
112
|
-
@controller.render :widget => Erector::TestWidget
|
113
|
-
@response.body.should == "<a href=\"#\" onclick=\"alert('hi'); return false;\">hi</a>"
|
114
|
-
end
|
115
|
-
|
116
|
-
it "link_to_function with block" do
|
117
|
-
class Erector::TestWidget < Erector::Widget
|
118
|
-
def render
|
119
|
-
link_to_function("Show me more", nil, :id => "more_link") do |page|
|
120
|
-
page[:details].visual_effect :toggle_blind
|
121
|
-
page[:more_link].replace_html "Show me less"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
@controller.render :widget => Erector::TestWidget
|
126
|
-
@response.body.should == "<a href=\"#\" id=\"more_link\" onclick=\"$("details").visualEffect("toggle_blind");\n$("more_link").update("Show me less");; return false;\">Show me more</a>"
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "which render to the ERB stream:" do
|
131
|
-
it "error_messages for, with object name" do
|
132
|
-
pending("error_messages_for is broken")
|
133
|
-
class Erector::TestWidget < Erector::Widget
|
134
|
-
def render
|
135
|
-
error_messages_for 'user'
|
136
|
-
end
|
137
|
-
end
|
138
|
-
errors = ActiveRecord::Errors.new(nil)
|
139
|
-
errors.add("name", "must be unpronounceable")
|
140
|
-
@controller.user = OpenStruct.new({:name => 'bob', :errors => errors})
|
141
|
-
@controller.render :widget => Erector::TestWidget
|
142
|
-
@response.body.should == "<a href=\"#\" onclick=\"alert('hi'); return false;\">hi</a>"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
|
149
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe "a view" do
|
4
|
-
before(:each) do
|
5
|
-
@view = ActionView::Base.new
|
6
|
-
# hook in model and add error messages
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "with errors" do
|
10
|
-
before(:each) do
|
11
|
-
class DummyView < ActionView::Base
|
12
|
-
attr_accessor :model
|
13
|
-
end
|
14
|
-
|
15
|
-
class DummyModel
|
16
|
-
# not sure what the best way is to mock out a model without
|
17
|
-
# needing a database. But here's my attempt.
|
18
|
-
attr_accessor :errors
|
19
|
-
|
20
|
-
def self.human_attribute_name(attribute)
|
21
|
-
attribute.to_s.capitalize
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
@view = DummyView.new()
|
26
|
-
model = DummyModel.new()
|
27
|
-
model.errors = ActiveRecord::Errors.new(model)
|
28
|
-
model.errors.add(:field, 'too silly')
|
29
|
-
@view.model = model
|
30
|
-
end
|
31
|
-
|
32
|
-
it "was set up correctly" do
|
33
|
-
@view.model.errors.full_messages.join(',').should == "Field too silly"
|
34
|
-
end
|
35
|
-
|
36
|
-
it "renders error messages" do
|
37
|
-
pending("error_messages_for is broken") do
|
38
|
-
message = Erector::Widget.new(@view) do
|
39
|
-
error_messages_for(:model)
|
40
|
-
end.to_s
|
41
|
-
message.should include("too silly")
|
42
|
-
message.should include("1 error")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
it "renders links" do
|
49
|
-
Erector::Widget.new(@view) do
|
50
|
-
link_to 'This&that', '/foo?this=1&that=1'
|
51
|
-
end.to_s.should == "<a href=\"/foo?this=1&that=1\">This&that</a>"
|
52
|
-
end
|
53
|
-
|
54
|
-
it "#image_tag" do
|
55
|
-
Erector::Widget.new(@view) do
|
56
|
-
image_tag("/foo")
|
57
|
-
end.to_s.should == %{<img alt="Foo" src="/foo" />}
|
58
|
-
end
|
59
|
-
|
60
|
-
it "#image_tag with parameters" do
|
61
|
-
Erector::Widget.new(@view) do
|
62
|
-
image_tag("/foo", :id => "photo_foo", :class => "a_photo_class")
|
63
|
-
end.to_s.should == %{<img alt="Foo" class="a_photo_class" id="photo_foo" src="/foo" />}
|
64
|
-
end
|
65
|
-
|
66
|
-
it "renders non-forgery-protected forms via form_tag" do
|
67
|
-
class << @view
|
68
|
-
def protect_against_forgery?
|
69
|
-
false
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
Erector::Widget.new(@view) do
|
74
|
-
form_tag("/foo") do
|
75
|
-
p "I'm in a form"
|
76
|
-
end
|
77
|
-
end.to_s.should == "<form action=\"/foo\" method=\"post\"><p>I'm in a form</p></form>"
|
78
|
-
end
|
79
|
-
|
80
|
-
it "renders forgery-protected forms via form_tag" do
|
81
|
-
class << @view
|
82
|
-
def protect_against_forgery?
|
83
|
-
true
|
84
|
-
end
|
85
|
-
|
86
|
-
def request_forgery_protection_token
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
def form_authenticity_token
|
91
|
-
"token"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
Erector::Widget.new(@view) do
|
96
|
-
form_tag("/foo") do
|
97
|
-
p "I'm in a form"
|
98
|
-
end
|
99
|
-
end.to_s.should == "<form action=\"/foo\" method=\"post\"><div style=\"margin:0;padding:0\"><input name=\"\" type=\"hidden\" value=\"token\" /></div><p>I'm in a form</p></form>"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
data/spec/rails/view_spec.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe "a view" do
|
4
|
-
before(:each) do
|
5
|
-
@view = ActionView::Base.new
|
6
|
-
# hook in model and add error messages
|
7
|
-
end
|
8
|
-
|
9
|
-
it "can capture with an erector block" do
|
10
|
-
pending("needs some re-work (maybe how haml does it?)")
|
11
|
-
message = Erector::Widget.new(@view) do
|
12
|
-
captured = @helpers.capture do
|
13
|
-
h1 'capture me!'
|
14
|
-
end
|
15
|
-
captured.should == "<h1>capture me!</h1>"
|
16
|
-
end.to_s.should == ""
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "the case which fake_erbout handles" do
|
22
|
-
it "works" do
|
23
|
-
@view = ActionView::Base.new
|
24
|
-
Erector::Widget.new(@view) do
|
25
|
-
foo = capture() do
|
26
|
-
fake_erbout do
|
27
|
-
helpers.concat('foo')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
foo.should == 'foo'
|
31
|
-
end.to_s.should == ""
|
32
|
-
end
|
33
|
-
end
|
data/spec/view_caching.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
module ViewCaching
|
2
|
-
def self.included(mod)
|
3
|
-
mod.extend ClassMethods
|
4
|
-
end
|
5
|
-
module ClassMethods
|
6
|
-
def view_cache
|
7
|
-
@view_cache ||= {}
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def view_cache(&blk)
|
12
|
-
cache = self.class.view_cache
|
13
|
-
if cache.empty?
|
14
|
-
cache[:body] = @body = yield
|
15
|
-
cache[:doc] = @doc = Hpricot(@body)
|
16
|
-
else
|
17
|
-
@body = cache[:body]
|
18
|
-
@doc = cache[:doc]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def doc
|
23
|
-
@doc
|
24
|
-
end
|
25
|
-
|
26
|
-
def body
|
27
|
-
@body
|
28
|
-
end
|
29
|
-
alias_method :html, :body
|
30
|
-
end
|