padrino-helpers 0.12.3 → 0.12.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efe48decfbfb7a521da3666e93d1c6b94834de2a
4
- data.tar.gz: ba1024635b475297a8367408c506e1e7e3850a94
3
+ metadata.gz: 58cb5f54d246c9e37cac9ff08017205030764ddb
4
+ data.tar.gz: e01706a5387dd6c6bacc26b3a6229b510f5cdfef
5
5
  SHA512:
6
- metadata.gz: 9db32bf5d81c31e7c8305e5039308adff035ab8514d05a13934c4122107e643e017b400bcc958bc27d90fe434296fc42e15634dc247324a5ac7e1767a5215654
7
- data.tar.gz: d728280dfec2211d4b78affa33d4a456477902126545fbb0c33065a624c1054f1d55a4f7e0200378d3cd12ab78b0133657e00f11b8a35500eda6e032f4a463c2
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('click me', :class => 'blocky') do; end
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).gsub('.','')
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.gsub(/\//, '_')
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 = "\n#{options.delete(:value)}"
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
- # @param [String] caption (defaults to: +Submit+)
517
- # The caption for the submit button.
518
- # @param [Hash] options
519
- # The html options for the input field.
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(name, url, options={})
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(name, options={}, &block)
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
- collection, fields = options.delete(:collection), options.delete(:fields)
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) || []
@@ -62,7 +62,7 @@ module Padrino
62
62
  if handler = find_proper_handler
63
63
  handler.capture_from_template(*args, &block)
64
64
  else
65
- block.call(*args)
65
+ yield(*args)
66
66
  end
67
67
  end
68
68
  alias :capture :capture_html
@@ -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 = block.call(*args)
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) : block.call(*args)
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
- object_name = name.partition('.').first.to_sym
39
+ item_name = name.partition('.').first.to_sym
40
40
 
41
- objects, counter = if options[:collection].respond_to?(:inject)
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
- objects.each_with_object(ActiveSupport::SafeBuffer.new) do |object,html|
49
- locals[object_name] = object if object
50
- locals["#{object_name}_counter".to_sym] = counter += 1 if counter
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) }
@@ -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
@@ -0,0 +1,3 @@
1
+ <div class=inner>
2
+ <div class=core></div>
3
+ </div>
@@ -0,0 +1,2 @@
1
+ .inner
2
+ .core
@@ -0,0 +1,2 @@
1
+ .inner
2
+ .core
@@ -0,0 +1,3 @@
1
+ <div class=outer>
2
+ <%= dive_helper(@ext) %>
3
+ </div>
@@ -0,0 +1,2 @@
1
+ .outer
2
+ = dive_helper(@ext)
@@ -0,0 +1,2 @@
1
+ .outer
2
+ = dive_helper(@ext)
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 = {}, &block)
34
- html = block && block.call
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 = {}, &block)
44
- html = block && block.call
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?
@@ -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</textarea>}, actual_html)
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
@@ -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
@@ -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.3
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-08-13 00:00:00.000000000 Z
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.3
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.3
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