erector 0.3.105 → 0.3.110
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.
- data/lib/erector.rb +1 -1
- data/lib/erector/extensions/action_view_template_handler.rb +3 -0
- data/lib/erector/helpers.rb +3 -3
- data/lib/erector/widget.rb +18 -14
- data/spec/erector/rails_helpers_spec.rb +63 -61
- data/spec/rails/standard_helpers_spec.rb +2 -5
- data/spec/spec_helper.rb +19 -0
- metadata +1 -1
data/lib/erector.rb
CHANGED
|
@@ -25,6 +25,8 @@ module ActionView #:nodoc:
|
|
|
25
25
|
full_path = "#{view_path}/#{template_path}.rb"
|
|
26
26
|
if File.exists?(full_path)
|
|
27
27
|
require_dependency full_path
|
|
28
|
+
found = true
|
|
29
|
+
break
|
|
28
30
|
else
|
|
29
31
|
partial_file_path = full_path.gsub(/\/([^\/]*)$/, '/_\1')
|
|
30
32
|
if File.exists?(partial_file_path)
|
|
@@ -61,3 +63,4 @@ ActionView::Base.instance_eval do
|
|
|
61
63
|
register_template_handler :rb, ActionView::TemplateHandlers::Erector
|
|
62
64
|
end
|
|
63
65
|
end
|
|
66
|
+
# ActionMailer::Base.register_template_extension('rb')
|
data/lib/erector/helpers.rb
CHANGED
|
@@ -47,8 +47,6 @@ module Erector
|
|
|
47
47
|
# return text, take block
|
|
48
48
|
[
|
|
49
49
|
:link_to_function,
|
|
50
|
-
:form_for,
|
|
51
|
-
:form_tag,
|
|
52
50
|
:text_field_tag,
|
|
53
51
|
:password_field_tag,
|
|
54
52
|
:check_box_tag
|
|
@@ -63,7 +61,9 @@ module Erector
|
|
|
63
61
|
|
|
64
62
|
# render text, take block
|
|
65
63
|
[
|
|
66
|
-
:error_messages_for,
|
|
64
|
+
:error_messages_for,
|
|
65
|
+
:form_tag,
|
|
66
|
+
:form_for,
|
|
67
67
|
].each do |method_to_proxy_with_block|
|
|
68
68
|
method_def =<<-METHOD_DEF
|
|
69
69
|
def #{method_to_proxy_with_block}(*args, &block)
|
data/lib/erector/widget.rb
CHANGED
|
@@ -312,20 +312,24 @@ protected
|
|
|
312
312
|
# override concat on the helpers object (which is usually a Rails view object)
|
|
313
313
|
unless @helpers.respond_to?(:concat_without_erector)
|
|
314
314
|
@helpers.metaclass.class_eval do
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
315
|
+
alias_method :capture_without_erector, :capture
|
|
316
|
+
def capture(*args, &block)
|
|
317
|
+
result = nil
|
|
318
|
+
widget = @erector_widget_stack.first
|
|
319
|
+
begin
|
|
320
|
+
original_doc = widget.doc
|
|
321
|
+
widget.instance_eval do
|
|
322
|
+
@doc = HtmlParts.new
|
|
323
|
+
end
|
|
324
|
+
captured = capture_without_erector(*args, &block)
|
|
325
|
+
result = widget.raw(widget.doc.to_s)
|
|
326
|
+
ensure
|
|
327
|
+
widget.instance_eval do
|
|
328
|
+
@doc = original_doc
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
result
|
|
332
|
+
end
|
|
329
333
|
|
|
330
334
|
alias_method :concat_without_erector, :concat
|
|
331
335
|
define_method :concat do |*args|
|
|
@@ -23,76 +23,78 @@ module RailsHelpersSpec
|
|
|
23
23
|
@controller.append_view_path("#{RAILS_ROOT}/app/views")
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
it "define_javascript_functions" do
|
|
48
|
+
class Erector::TestWidget < Erector::Widget
|
|
49
|
+
def render
|
|
50
|
+
define_javascript_functions
|
|
51
|
+
end
|
|
50
52
|
end
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
end
|
|
53
|
+
@controller.render :widget => Erector::TestWidget
|
|
54
|
+
@response.body.should =~ /^<script type=\"text\/javascript\">\n/
|
|
55
|
+
end
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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") + ";"
|
|
91
92
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
#Note: "text_field_with_auto_complete" is now a plugin, which makes it difficult to test inside the Erector project
|
|
93
|
+
end
|
|
95
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
|
+
|
|
96
98
|
# :link_to_function,
|
|
97
99
|
# :link_to,
|
|
98
100
|
# :link_to_remote,
|
|
@@ -34,12 +34,13 @@ describe "a view" do
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "renders error messages" do
|
|
37
|
-
|
|
37
|
+
pending("error_messages_for is broken") do
|
|
38
38
|
message = Erector::Widget.new(@view) do
|
|
39
39
|
error_messages_for(:model)
|
|
40
40
|
end.to_s
|
|
41
41
|
message.should include("too silly")
|
|
42
42
|
message.should include("1 error")
|
|
43
|
+
end
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
end
|
|
@@ -63,7 +64,6 @@ describe "a view" do
|
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
it "renders non-forgery-protected forms via form_tag" do
|
|
66
|
-
pending("needs ActionView::capture to work")
|
|
67
67
|
class << @view
|
|
68
68
|
def protect_against_forgery?
|
|
69
69
|
false
|
|
@@ -78,7 +78,6 @@ describe "a view" do
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
it "renders forgery-protected forms via form_tag" do
|
|
81
|
-
pending("needs ActionView::capture to work")
|
|
82
81
|
class << @view
|
|
83
82
|
def protect_against_forgery?
|
|
84
83
|
true
|
|
@@ -94,9 +93,7 @@ describe "a view" do
|
|
|
94
93
|
end
|
|
95
94
|
|
|
96
95
|
Erector::Widget.new(@view) do
|
|
97
|
-
puts "starting"
|
|
98
96
|
form_tag("/foo") do
|
|
99
|
-
puts "start of block"
|
|
100
97
|
p "I'm in a form"
|
|
101
98
|
end
|
|
102
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>"
|
data/spec/spec_helper.rb
CHANGED
|
@@ -19,3 +19,22 @@ module Views
|
|
|
19
19
|
module TemplateHandlerSpec
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# uncomment this to find leftover debug putses
|
|
25
|
+
#
|
|
26
|
+
# alias :original_puts :puts
|
|
27
|
+
# def puts(string ="")
|
|
28
|
+
# super string.to_s + "\s(#{caller.first.match(/(\w+\.\w+:\d+)|Rakefile:\d+/)[0]})"
|
|
29
|
+
# end
|
|
30
|
+
#
|
|
31
|
+
# alias :original_p :p
|
|
32
|
+
# def p(string="")
|
|
33
|
+
# original_puts "\s(#{caller.first.match(/(\w+\.\w+:\d+)|Rakefile:\d+/)[0]})"
|
|
34
|
+
# super(string)
|
|
35
|
+
# end
|
|
36
|
+
#
|
|
37
|
+
# alias :original_print :print
|
|
38
|
+
# def print(string="")
|
|
39
|
+
# super string + "\s(#{caller.first.match(/(\w+\.\w+:\d+)|Rakefile:\d+/)[0]})"
|
|
40
|
+
# end
|