padrino-helpers 0.9.26 → 0.9.27
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/padrino-helpers/form_helpers.rb +1 -1
- data/lib/padrino-helpers/render_helpers.rb +5 -3
- data/test/fixtures/markup_app/views/simple_partial.erb +1 -0
- data/test/fixtures/markup_app/views/simple_partial.haml +1 -0
- data/test/fixtures/markup_app/views/simple_partial.slim +1 -0
- data/test/fixtures/render_app/app.rb +6 -0
- data/test/fixtures/render_app/views/current_engines/_erb.erb +1 -1
- data/test/fixtures/render_app/views/current_engines/_haml.haml +1 -1
- data/test/fixtures/render_app/views/current_engines/_slim.slim +1 -1
- data/test/fixtures/render_app/views/explicit_engine.haml +5 -0
- data/test/test_form_builder.rb +17 -0
- data/test/test_output_helpers.rb +17 -0
- data/test/test_render_helpers.rb +12 -3
- metadata +15 -7
@@ -417,7 +417,7 @@ module Padrino
|
|
417
417
|
# configured_form_builder_class(nil) => StandardFormBuilder
|
418
418
|
#
|
419
419
|
def configured_form_builder_class(explicit_builder=nil)
|
420
|
-
default_builder = self.respond_to?(:
|
420
|
+
default_builder = self.respond_to?(:settings) && self.settings.default_builder
|
421
421
|
configured_builder = explicit_builder || default_builder || 'StandardFormBuilder'
|
422
422
|
configured_builder = "Padrino::Helpers::FormBuilder::#{configured_builder}".constantize if configured_builder.is_a?(String)
|
423
423
|
configured_builder
|
@@ -9,13 +9,15 @@ module Padrino
|
|
9
9
|
# partial 'photo/item', :object => @photo
|
10
10
|
# partial 'photo/item', :collection => @photos
|
11
11
|
# partial 'photo/item', :locals => { :foo => :bar }
|
12
|
+
# partial 'photo/item', :engine => :erb
|
12
13
|
#
|
13
14
|
def partial(template, options={})
|
14
15
|
options.reverse_merge!(:locals => {}, :layout => false)
|
15
16
|
path = template.to_s.split(File::SEPARATOR)
|
16
17
|
object_name = path[-1].to_sym
|
17
18
|
path[-1] = "_#{path[-1]}"
|
18
|
-
|
19
|
+
explicit_engine = options.delete(:engine)
|
20
|
+
template_path = File.join(path).to_sym
|
19
21
|
raise 'Partial collection specified but is nil' if options.has_key?(:collection) && options[:collection].nil?
|
20
22
|
if collection = options.delete(:collection)
|
21
23
|
options.delete(:object)
|
@@ -23,13 +25,13 @@ module Padrino
|
|
23
25
|
collection.map { |member|
|
24
26
|
counter += 1
|
25
27
|
options[:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter)
|
26
|
-
render(
|
28
|
+
render(explicit_engine, template_path, options.dup)
|
27
29
|
}.join("\n")
|
28
30
|
else
|
29
31
|
if member = options.delete(:object)
|
30
32
|
options[:locals].merge!(object_name => member)
|
31
33
|
end
|
32
|
-
render(
|
34
|
+
render(explicit_engine, template_path, options.dup)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
alias :render_partial :partial
|
@@ -0,0 +1 @@
|
|
1
|
+
<p class="erb"><%= partial 'partials/erb', :engine => "erb" %></p>
|
@@ -0,0 +1 @@
|
|
1
|
+
%p.haml= partial 'partials/haml', :engine => "haml"
|
@@ -0,0 +1 @@
|
|
1
|
+
p.slim= partial 'partials/slim', :engine => "slim"
|
@@ -2,6 +2,7 @@ PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
|
|
2
2
|
PADRINO_ENV = 'test' unless defined? PADRINO_ENV
|
3
3
|
|
4
4
|
require 'padrino-core'
|
5
|
+
require 'slim'
|
5
6
|
|
6
7
|
class RenderUser
|
7
8
|
attr_accessor :name
|
@@ -21,6 +22,11 @@ class RenderDemo < Padrino::Application
|
|
21
22
|
render :current_engine
|
22
23
|
end
|
23
24
|
|
25
|
+
# get current engines from explicit engine partials
|
26
|
+
get '/explicit_engine' do
|
27
|
+
render :explicit_engine
|
28
|
+
end
|
29
|
+
|
24
30
|
# partial with object
|
25
31
|
get '/partial/object' do
|
26
32
|
partial 'template/user', :object => RenderUser.new('John'), :locals => { :extra => "bar" }
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
<span><%= current_engine %></span>
|
@@ -1 +1 @@
|
|
1
|
-
=current_engine
|
1
|
+
%span=current_engine
|
@@ -1 +1 @@
|
|
1
|
-
=current_engine
|
1
|
+
span=current_engine
|
data/test/test_form_builder.rb
CHANGED
@@ -4,6 +4,13 @@ require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
|
|
4
4
|
class TestFormBuilder < Test::Unit::TestCase
|
5
5
|
include Padrino::Helpers::FormHelpers
|
6
6
|
|
7
|
+
# Dummy form builder for testing
|
8
|
+
module Padrino::Helpers::FormBuilder
|
9
|
+
class FakeFormBuilder < AbstractFormBuilder
|
10
|
+
def foo_field; @template.content_tag(:span, "bar"); end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
7
14
|
def app
|
8
15
|
MarkupDemo.tap { |app| app.set :environment, :test }
|
9
16
|
end
|
@@ -41,6 +48,16 @@ class TestFormBuilder < Test::Unit::TestCase
|
|
41
48
|
assert_has_tag('form input', :type => 'text', :name => 'outer_user_account[username]') { actual_html }
|
42
49
|
end
|
43
50
|
|
51
|
+
should "display form specifying default builder setting" do
|
52
|
+
self.expects(:settings).returns(stub(:default_builder => 'FakeFormBuilder')).once
|
53
|
+
actual_html = ""
|
54
|
+
assert_nothing_raised do
|
55
|
+
actual_html = form_for(@user, '/register', :id => 'register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.foo_field }
|
56
|
+
end
|
57
|
+
assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :method => 'post') { actual_html }
|
58
|
+
assert_has_tag('span', :content => "bar") { actual_html }
|
59
|
+
end
|
60
|
+
|
44
61
|
should "display correct form html with remote option" do
|
45
62
|
actual_html = form_for(@user, '/update', :"accept-charset" => "UTF-8", :remote => true) { "Demo" }
|
46
63
|
assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/update', :method => 'post', "data-remote" => 'true') { actual_html }
|
data/test/test_output_helpers.rb
CHANGED
@@ -113,4 +113,21 @@ class TestOutputHelpers < Test::Unit::TestCase
|
|
113
113
|
assert_have_selector 'p.end', :content => "slim"
|
114
114
|
end
|
115
115
|
end
|
116
|
+
|
117
|
+
context 'for #partial method in simple sinatra application' do
|
118
|
+
should 'properly output in erb' do
|
119
|
+
visit '/erb/simple_partial'
|
120
|
+
assert_have_selector 'p.erb', :content => "erb"
|
121
|
+
end
|
122
|
+
|
123
|
+
should 'properly output in haml' do
|
124
|
+
visit '/haml/simple_partial'
|
125
|
+
assert_have_selector 'p.haml', :content => "haml"
|
126
|
+
end
|
127
|
+
|
128
|
+
should 'properly output in slim' do
|
129
|
+
visit '/slim/simple_partial'
|
130
|
+
assert_have_selector 'p.slim', :content => "slim"
|
131
|
+
end
|
132
|
+
end
|
116
133
|
end
|
data/test/test_render_helpers.rb
CHANGED
@@ -51,9 +51,18 @@ class TestRenderHelpers < Test::Unit::TestCase
|
|
51
51
|
should 'detect correctly current engine for a padrino application' do
|
52
52
|
visit '/current_engine'
|
53
53
|
assert_have_selector 'p.start', :content => "haml"
|
54
|
-
assert_have_selector 'p.haml', :content => "haml"
|
55
|
-
assert_have_selector 'p.erb', :content => "erb"
|
56
|
-
assert_have_selector 'p.slim', :content => "slim"
|
54
|
+
assert_have_selector 'p.haml span', :content => "haml"
|
55
|
+
assert_have_selector 'p.erb span', :content => "erb"
|
56
|
+
assert_have_selector 'p.slim span', :content => "slim"
|
57
|
+
assert_have_selector 'p.end', :content => "haml"
|
58
|
+
end
|
59
|
+
|
60
|
+
should "detect correctly current engine for explicit engine on partials" do
|
61
|
+
visit '/explicit_engine'
|
62
|
+
assert_have_selector 'p.start', :content => "haml"
|
63
|
+
assert_have_selector 'p.haml span', :content => "haml"
|
64
|
+
assert_have_selector 'p.erb span', :content => "erb"
|
65
|
+
assert_have_selector 'p.slim span', :content => "slim"
|
57
66
|
assert_have_selector 'p.end', :content => "haml"
|
58
67
|
end
|
59
68
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 27
|
10
|
+
version: 0.9.27
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Padrino Team
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-
|
21
|
+
date: 2011-05-06 00:00:00 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: padrino-core
|
@@ -28,12 +28,12 @@ dependencies:
|
|
28
28
|
requirements:
|
29
29
|
- - "="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
hash:
|
31
|
+
hash: 13
|
32
32
|
segments:
|
33
33
|
- 0
|
34
34
|
- 9
|
35
|
-
-
|
36
|
-
version: 0.9.
|
35
|
+
- 27
|
36
|
+
version: 0.9.27
|
37
37
|
type: :runtime
|
38
38
|
version_requirements: *id001
|
39
39
|
- !ruby/object:Gem::Dependency
|
@@ -133,12 +133,16 @@ files:
|
|
133
133
|
- test/fixtures/markup_app/views/partials/_erb.erb
|
134
134
|
- test/fixtures/markup_app/views/partials/_haml.haml
|
135
135
|
- test/fixtures/markup_app/views/partials/_slim.slim
|
136
|
+
- test/fixtures/markup_app/views/simple_partial.erb
|
137
|
+
- test/fixtures/markup_app/views/simple_partial.haml
|
138
|
+
- test/fixtures/markup_app/views/simple_partial.slim
|
136
139
|
- test/fixtures/render_app/app.rb
|
137
140
|
- test/fixtures/render_app/views/current_engine.haml
|
138
141
|
- test/fixtures/render_app/views/current_engines/_erb.erb
|
139
142
|
- test/fixtures/render_app/views/current_engines/_haml.haml
|
140
143
|
- test/fixtures/render_app/views/current_engines/_slim.slim
|
141
144
|
- test/fixtures/render_app/views/erb/test.erb
|
145
|
+
- test/fixtures/render_app/views/explicit_engine.haml
|
142
146
|
- test/fixtures/render_app/views/haml/test.haml
|
143
147
|
- test/fixtures/render_app/views/template/_user.haml
|
144
148
|
- test/fixtures/render_app/views/template/haml_template.haml
|
@@ -222,12 +226,16 @@ test_files:
|
|
222
226
|
- test/fixtures/markup_app/views/partials/_erb.erb
|
223
227
|
- test/fixtures/markup_app/views/partials/_haml.haml
|
224
228
|
- test/fixtures/markup_app/views/partials/_slim.slim
|
229
|
+
- test/fixtures/markup_app/views/simple_partial.erb
|
230
|
+
- test/fixtures/markup_app/views/simple_partial.haml
|
231
|
+
- test/fixtures/markup_app/views/simple_partial.slim
|
225
232
|
- test/fixtures/render_app/app.rb
|
226
233
|
- test/fixtures/render_app/views/current_engine.haml
|
227
234
|
- test/fixtures/render_app/views/current_engines/_erb.erb
|
228
235
|
- test/fixtures/render_app/views/current_engines/_haml.haml
|
229
236
|
- test/fixtures/render_app/views/current_engines/_slim.slim
|
230
237
|
- test/fixtures/render_app/views/erb/test.erb
|
238
|
+
- test/fixtures/render_app/views/explicit_engine.haml
|
231
239
|
- test/fixtures/render_app/views/haml/test.haml
|
232
240
|
- test/fixtures/render_app/views/template/_user.haml
|
233
241
|
- test/fixtures/render_app/views/template/haml_template.haml
|