padrino-helpers 0.12.3 → 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/padrino-helpers/asset_tag_helpers.rb +2 -2
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +1 -1
- data/lib/padrino-helpers/form_builder/deprecated_builder_methods.rb +0 -13
- data/lib/padrino-helpers/form_helpers.rb +9 -7
- data/lib/padrino-helpers/form_helpers/options.rb +2 -1
- data/lib/padrino-helpers/output_helpers.rb +1 -1
- data/lib/padrino-helpers/output_helpers/abstract_handler.rb +1 -1
- data/lib/padrino-helpers/output_helpers/haml_handler.rb +1 -1
- data/lib/padrino-helpers/render_helpers.rb +5 -5
- data/lib/padrino/rendering.rb +10 -0
- data/test/fixtures/render_app/app.rb +16 -0
- data/test/fixtures/render_app/views/dive_inner_erb.erb +3 -0
- data/test/fixtures/render_app/views/dive_inner_haml.haml +2 -0
- data/test/fixtures/render_app/views/dive_inner_slim.slim +2 -0
- data/test/fixtures/render_app/views/dive_outer_erb.erb +3 -0
- data/test/fixtures/render_app/views/dive_outer_haml.haml +2 -0
- data/test/fixtures/render_app/views/dive_outer_slim.slim +2 -0
- data/test/helper.rb +4 -4
- data/test/test_form_helpers.rb +3 -3
- data/test/test_render_helpers.rb +10 -0
- data/test/test_rendering.rb +10 -0
- metadata +16 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58cb5f54d246c9e37cac9ff08017205030764ddb
|
4
|
+
data.tar.gz: e01706a5387dd6c6bacc26b3a6229b510f5cdfef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70f78741ff49c8509d01e166357712eb051010ac239d368aeabaa2f397331e20f804388adb07b90bc899e927799f9cd990bc45af96db4c97ad601e5fe60e60ca
|
7
|
+
data.tar.gz: 062b3a871e216dbf8908b479bd6f0748a5df92f4caf56eaa2b22f08ae5ee9b13bc2f1fc87fd14f11db8fe5f65e169890ebf318ca9d3b95152347bb5e7bc1a90e
|
@@ -69,7 +69,7 @@ module Padrino
|
|
69
69
|
# link_to('click me', '/dashboard', :class => 'linky')
|
70
70
|
# link_to('click me', '/dashboard', :remote => true)
|
71
71
|
# link_to('click me', '/dashboard', :method => :delete)
|
72
|
-
# link_to('
|
72
|
+
# link_to('/dashboard', :class => 'blocky') do; end
|
73
73
|
#
|
74
74
|
# Note that you can pass :+if+ or :+unless+ conditions, but if you provide :current as
|
75
75
|
# condition padrino return true/false if the request.path_info match the given url.
|
@@ -184,7 +184,7 @@ module Padrino
|
|
184
184
|
# favicon_tag 'favicon.png', :type => 'image/ico'
|
185
185
|
#
|
186
186
|
def favicon_tag(source, options={})
|
187
|
-
type = File.extname(source).
|
187
|
+
type = File.extname(source).sub('.','')
|
188
188
|
options = options.dup.reverse_merge!(:href => image_path(source), :rel => 'icon', :type => "image/#{type}")
|
189
189
|
tag(:link, options)
|
190
190
|
end
|
@@ -17,7 +17,7 @@ module Padrino
|
|
17
17
|
fail "FormBuilder object must be present. If there's no object, use a symbol instead (i.e. :user)" unless object
|
18
18
|
@options = options
|
19
19
|
@namespace = options[:namespace]
|
20
|
-
@model_name = options[:as] || @object.class.to_s.underscore.
|
20
|
+
@model_name = options[:as] || @object.class.to_s.underscore.tr('/', '_')
|
21
21
|
nested = options[:nested]
|
22
22
|
if @is_nested = nested && (nested_parent = nested[:parent]) && nested_parent.respond_to?(:object)
|
23
23
|
@parent_form = nested_parent
|
@@ -25,14 +25,6 @@ module Padrino
|
|
25
25
|
is_nested && object.respond_to?(:new_record?) && !object.new_record? && object.id
|
26
26
|
end
|
27
27
|
|
28
|
-
##
|
29
|
-
# Returns a new record of the type specified in the object
|
30
|
-
#
|
31
|
-
def build_object(object_or_symbol)
|
32
|
-
logger.warn "##{__method__} is deprecated"
|
33
|
-
object_or_symbol.is_a?(Symbol) ? @template.instance_variable_get("@#{object_or_symbol}") || object_class(object_or_symbol).new : object_or
|
34
|
-
end
|
35
|
-
|
36
28
|
##
|
37
29
|
# Returns the object's models name.
|
38
30
|
#
|
@@ -60,11 +52,6 @@ module Padrino
|
|
60
52
|
!nested_form?
|
61
53
|
end
|
62
54
|
|
63
|
-
def build_object(symbol)
|
64
|
-
logger.warn "##{__method__} is deprecated"
|
65
|
-
@template.instance_variable_get("@#{symbol}") || symbol.to_s.camelize.constantize.new
|
66
|
-
end
|
67
|
-
|
68
55
|
def field_result
|
69
56
|
logger.warn "##{__method__} is deprecated"
|
70
57
|
result = []
|
@@ -397,7 +397,7 @@ module Padrino
|
|
397
397
|
# text_area_tag :username, :class => 'long', :value => "Demo?"
|
398
398
|
#
|
399
399
|
def text_area_tag(name, options={})
|
400
|
-
inner_html =
|
400
|
+
inner_html = TagHelpers::NEWLINE + options.delete(:value).to_s
|
401
401
|
options = { :name => name, :rows => "", :cols => "" }.update(options)
|
402
402
|
content_tag(:textarea, inner_html, options)
|
403
403
|
end
|
@@ -513,10 +513,11 @@ module Padrino
|
|
513
513
|
##
|
514
514
|
# Constructs a submit button from the given options.
|
515
515
|
#
|
516
|
-
# @
|
517
|
-
# The
|
518
|
-
# @
|
519
|
-
# The
|
516
|
+
# @overload submit_tag(options={})
|
517
|
+
# @param [Hash] options The html options for the input field.
|
518
|
+
# @overload submit_tag(caption, options={})
|
519
|
+
# @param [String] caption The caption for the submit button.
|
520
|
+
# @param [Hash] options The html options for the input field.
|
520
521
|
#
|
521
522
|
# @return [String] The html submit button based on the +options+ specified.
|
522
523
|
#
|
@@ -550,11 +551,11 @@ module Padrino
|
|
550
551
|
##
|
551
552
|
# Creates a form containing a single button that submits to the URL.
|
552
553
|
#
|
553
|
-
# @overload button_to(
|
554
|
+
# @overload button_to(caption, url, options={})
|
554
555
|
# @param [String] caption The text caption.
|
555
556
|
# @param [String] url The url href.
|
556
557
|
# @param [Hash] options The html options.
|
557
|
-
# @overload button_to(
|
558
|
+
# @overload button_to(url, options={}, &block)
|
558
559
|
# @param [String] url The url href.
|
559
560
|
# @param [Hash] options The html options.
|
560
561
|
# @param [Proc] block The button content.
|
@@ -579,6 +580,7 @@ module Padrino
|
|
579
580
|
# # </form>
|
580
581
|
#
|
581
582
|
def button_to(*args, &block)
|
583
|
+
warn 'Warning: method button_to with block will change behavior on Padrino 0.13.0 release and will wrap the content of the block with <button></button> tag.' if block_given?
|
582
584
|
options = args.extract_options!.dup
|
583
585
|
name, url = *args
|
584
586
|
options['data-remote'] = 'true' if options.delete(:remote)
|
@@ -85,7 +85,8 @@ module Padrino
|
|
85
85
|
|
86
86
|
def extract_option_items!(options)
|
87
87
|
if options[:collection]
|
88
|
-
|
88
|
+
fields = options.delete(:fields)
|
89
|
+
collection = options.delete(:collection)
|
89
90
|
collection.map{ |item| [ item.send(fields.first), item.send(fields.last) ] }
|
90
91
|
else
|
91
92
|
options.delete(:options) || []
|
@@ -30,7 +30,7 @@ module Padrino
|
|
30
30
|
#
|
31
31
|
def capture_from_template(*args, &block)
|
32
32
|
self.output_buffer, _buf_was = ActiveSupport::SafeBuffer.new, self.output_buffer
|
33
|
-
raw =
|
33
|
+
raw = yield(*args)
|
34
34
|
captured = template.instance_variable_get(:@_out_buf)
|
35
35
|
self.output_buffer = _buf_was
|
36
36
|
engine_matches?(block) && !captured.empty? ? captured : raw.to_s
|
@@ -16,7 +16,7 @@ module Padrino
|
|
16
16
|
# Captures the html from a block of template code for this handler.
|
17
17
|
#
|
18
18
|
def capture_from_template(*args, &block)
|
19
|
-
engine_matches?(block) ? template.capture_haml(*args, &block) :
|
19
|
+
engine_matches?(block) ? template.capture_haml(*args, &block) : yield(*args)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
OutputHelpers.register(:haml, HamlHandler)
|
@@ -36,18 +36,18 @@ module Padrino
|
|
36
36
|
|
37
37
|
path,_,name = template.to_s.rpartition(File::SEPARATOR)
|
38
38
|
template_path = File.join(path,"_#{name}").to_sym
|
39
|
-
|
39
|
+
item_name = name.partition('.').first.to_sym
|
40
40
|
|
41
|
-
|
41
|
+
items, counter = if options[:collection].respond_to?(:inject)
|
42
42
|
[options.delete(:collection), 0]
|
43
43
|
else
|
44
44
|
[[options.delete(:object)], nil]
|
45
45
|
end
|
46
46
|
|
47
47
|
locals = options[:locals]
|
48
|
-
|
49
|
-
locals[
|
50
|
-
locals["#{
|
48
|
+
items.each_with_object(ActiveSupport::SafeBuffer.new) do |item,html|
|
49
|
+
locals[item_name] = item if item
|
50
|
+
locals["#{item_name}_counter".to_sym] = counter += 1 if counter
|
51
51
|
content =
|
52
52
|
if block_given?
|
53
53
|
concat_content render(explicit_engine, template_path, options){ capture_html(&block) }
|
data/lib/padrino/rendering.rb
CHANGED
@@ -395,3 +395,13 @@ unless defined? Padrino::Rendering::SlimTemplate
|
|
395
395
|
require 'padrino/rendering/slim_template'
|
396
396
|
end
|
397
397
|
end
|
398
|
+
|
399
|
+
if Padrino::Rendering.engine_configurations.empty? && !defined?(Padrino::IGNORE_NO_RENDERING_ENGINE)
|
400
|
+
warn <<-EOT
|
401
|
+
WARNING: no supported rendering engine found. To use Padrino::Helpers and
|
402
|
+
Padrino::Rendering properly you should include `gem 'erubis'`, `gem 'haml'`
|
403
|
+
or `gem 'slim'` in your Gemfile. If you are confident about using
|
404
|
+
Padrino::Helpers without Padrino::Rendering, please define constant
|
405
|
+
`Padrino::IGNORE_NO_RENDERING_ENGINE = true` before `require 'padrino-helpers'`.
|
406
|
+
EOT
|
407
|
+
end
|
@@ -91,4 +91,20 @@ class RenderDemo < Padrino::Application
|
|
91
91
|
content_tag :div, 'go block!'
|
92
92
|
end
|
93
93
|
end
|
94
|
+
|
95
|
+
helpers do
|
96
|
+
def dive_helper(ext)
|
97
|
+
# @current_engine, save = nil
|
98
|
+
form_result = form_tag '/' do
|
99
|
+
render "dive_inner_#{ext}"
|
100
|
+
end
|
101
|
+
# @current_engine = save
|
102
|
+
content_tag('div', form_result, :class => 'wrapper')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
get '/double_dive_:ext' do
|
107
|
+
@ext = params[:ext]
|
108
|
+
render "dive_outer_#{@ext}"
|
109
|
+
end
|
94
110
|
end
|
data/test/helper.rb
CHANGED
@@ -30,8 +30,8 @@ class MiniTest::Spec
|
|
30
30
|
|
31
31
|
# assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
|
32
32
|
# In this case, block is the html to evaluate
|
33
|
-
def assert_has_tag(name, attributes = {}
|
34
|
-
html =
|
33
|
+
def assert_has_tag(name, attributes = {})
|
34
|
+
html = yield if block_given?
|
35
35
|
assert html.html_safe?, 'html_safe? failed'
|
36
36
|
matcher = HaveSelector.new(name, attributes)
|
37
37
|
raise "Please specify a block!" if html.blank?
|
@@ -40,8 +40,8 @@ class MiniTest::Spec
|
|
40
40
|
|
41
41
|
# assert_has_no_tag, tag(:h1, :content => "yellow") { "<h1>green</h1>" }
|
42
42
|
# In this case, block is the html to evaluate
|
43
|
-
def assert_has_no_tag(name, attributes = {}
|
44
|
-
html =
|
43
|
+
def assert_has_no_tag(name, attributes = {})
|
44
|
+
html = yield if block_given?
|
45
45
|
attributes.merge!(:count => 0)
|
46
46
|
matcher = HaveSelector.new(name, attributes)
|
47
47
|
raise "Please specify a block!" if html.blank?
|
data/test/test_form_helpers.rb
CHANGED
@@ -499,9 +499,9 @@ describe "FormHelpers" do
|
|
499
499
|
end
|
500
500
|
|
501
501
|
it 'should insert newline to before of content' do
|
502
|
-
actual_html = text_area_tag(:about, :value => "\na test")
|
503
|
-
assert_has_tag(:textarea, :content => "\na test", :name => 'about') { actual_html }
|
504
|
-
assert_match(%r{<textarea[^>]*>\n\na test
|
502
|
+
actual_html = text_area_tag(:about, :value => "\na test&".html_safe)
|
503
|
+
assert_has_tag(:textarea, :content => "\na test&".html_safe, :name => 'about') { actual_html }
|
504
|
+
assert_match(%r{<textarea[^>]*>\n\na test&</textarea>}, actual_html)
|
505
505
|
end
|
506
506
|
|
507
507
|
it 'should display text area in erb' do
|
data/test/test_render_helpers.rb
CHANGED
@@ -212,4 +212,14 @@ describe "RenderHelpers" do
|
|
212
212
|
assert_have_selector 'b', :content => 'c'
|
213
213
|
end
|
214
214
|
end
|
215
|
+
|
216
|
+
describe 'rendering with helpers that use render' do
|
217
|
+
%W{erb haml slim}.each do |engine|
|
218
|
+
it "should work with #{engine}" do
|
219
|
+
skip
|
220
|
+
visit "/double_dive_#{engine}"
|
221
|
+
assert_have_selector '.outer .wrapper form .inner .core'
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
215
225
|
end
|
data/test/test_rendering.rb
CHANGED
@@ -691,4 +691,14 @@ describe "Rendering" do
|
|
691
691
|
end
|
692
692
|
end
|
693
693
|
end
|
694
|
+
|
695
|
+
describe 'sinatra template helpers' do
|
696
|
+
it "should respect default_content_type option defined by sinatra" do
|
697
|
+
mock_app do
|
698
|
+
get(:index){ builder "xml.foo" }
|
699
|
+
end
|
700
|
+
get '/'
|
701
|
+
assert_equal "application/xml;charset=utf-8", response['Content-Type']
|
702
|
+
end
|
703
|
+
end
|
694
704
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-
|
14
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: padrino-support
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - '='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.12.
|
22
|
+
version: 0.12.4
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.12.
|
29
|
+
version: 0.12.4
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: tilt
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -181,6 +181,12 @@ files:
|
|
181
181
|
- test/fixtures/render_app/views/current_engines/_erb.erb
|
182
182
|
- test/fixtures/render_app/views/current_engines/_haml.haml
|
183
183
|
- test/fixtures/render_app/views/current_engines/_slim.slim
|
184
|
+
- test/fixtures/render_app/views/dive_inner_erb.erb
|
185
|
+
- test/fixtures/render_app/views/dive_inner_haml.haml
|
186
|
+
- test/fixtures/render_app/views/dive_inner_slim.slim
|
187
|
+
- test/fixtures/render_app/views/dive_outer_erb.erb
|
188
|
+
- test/fixtures/render_app/views/dive_outer_haml.haml
|
189
|
+
- test/fixtures/render_app/views/dive_outer_slim.slim
|
184
190
|
- test/fixtures/render_app/views/double_capture_erb.erb
|
185
191
|
- test/fixtures/render_app/views/double_capture_haml.haml
|
186
192
|
- test/fixtures/render_app/views/double_capture_slim.slim
|
@@ -299,6 +305,12 @@ test_files:
|
|
299
305
|
- test/fixtures/render_app/views/current_engines/_erb.erb
|
300
306
|
- test/fixtures/render_app/views/current_engines/_haml.haml
|
301
307
|
- test/fixtures/render_app/views/current_engines/_slim.slim
|
308
|
+
- test/fixtures/render_app/views/dive_inner_erb.erb
|
309
|
+
- test/fixtures/render_app/views/dive_inner_haml.haml
|
310
|
+
- test/fixtures/render_app/views/dive_inner_slim.slim
|
311
|
+
- test/fixtures/render_app/views/dive_outer_erb.erb
|
312
|
+
- test/fixtures/render_app/views/dive_outer_haml.haml
|
313
|
+
- test/fixtures/render_app/views/dive_outer_slim.slim
|
302
314
|
- test/fixtures/render_app/views/double_capture_erb.erb
|
303
315
|
- test/fixtures/render_app/views/double_capture_haml.haml
|
304
316
|
- test/fixtures/render_app/views/double_capture_slim.slim
|