padrino-helpers 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/.document +3 -3
  2. data/.yardopts +1 -0
  3. data/{LICENSE → LICENSE.txt} +0 -0
  4. data/README.rdoc +3 -3
  5. data/lib/padrino-helpers.rb +21 -14
  6. data/lib/padrino-helpers/asset_tag_helpers.rb +163 -34
  7. data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +1 -1
  8. data/lib/padrino-helpers/form_helpers.rb +287 -134
  9. data/lib/padrino-helpers/format_helpers.rb +135 -17
  10. data/lib/padrino-helpers/locale/lv.yml +103 -0
  11. data/lib/padrino-helpers/locale/zh_cn.yml +1 -1
  12. data/lib/padrino-helpers/number_helpers.rb +73 -59
  13. data/lib/padrino-helpers/output_helpers.rb +59 -15
  14. data/lib/padrino-helpers/output_helpers/abstract_handler.rb +15 -20
  15. data/lib/padrino-helpers/output_helpers/erb_handler.rb +12 -15
  16. data/lib/padrino-helpers/output_helpers/haml_handler.rb +10 -14
  17. data/lib/padrino-helpers/output_helpers/slim_handler.rb +10 -14
  18. data/lib/padrino-helpers/render_helpers.rb +23 -7
  19. data/lib/padrino-helpers/tag_helpers.rb +41 -16
  20. data/lib/padrino-helpers/translation_helpers.rb +14 -0
  21. data/test/fixtures/markup_app/views/content_for.erb +3 -0
  22. data/test/fixtures/markup_app/views/content_for.haml +3 -0
  23. data/test/fixtures/markup_app/views/content_for.slim +3 -0
  24. data/test/helper.rb +3 -15
  25. data/test/test_asset_tag_helpers.rb +1 -1
  26. data/test/test_form_builder.rb +3 -5
  27. data/test/test_form_helpers.rb +1 -1
  28. data/test/test_format_helpers.rb +1 -1
  29. data/test/test_locale.rb +1 -1
  30. data/test/test_number_helpers.rb +1 -1
  31. data/test/test_output_helpers.rb +22 -2
  32. data/test/test_render_helpers.rb +1 -1
  33. data/test/test_tag_helpers.rb +1 -1
  34. metadata +10 -8
@@ -10,27 +10,25 @@ module Padrino
10
10
  '"' => """
11
11
  }
12
12
 
13
- ##
14
- # Creates an html input field with given type and options
15
- #
16
- # ==== Examples
17
- #
18
- # input_tag :text, :class => "test"
19
- #
20
- def input_tag(type, options = {})
21
- options.reverse_merge!(:type => type)
22
- tag(:input, options)
23
- end
24
-
25
13
  ##
26
14
  # Creates an html tag with given name, content and options
27
15
  #
28
- # ==== Examples
16
+ # @overload content_tag(name, content, options)
17
+ # @param [Symbol] name The html type of tag.
18
+ # @param [String] content The contents in the tag.
19
+ # @param [Hash] options The html options to include in this tag.
20
+ # @overload content_tag(name, options, &block)
21
+ # @param [Symbol] name The html type of tag.
22
+ # @param [Hash] options The html options to include in this tag.
23
+ # @param [Proc] block The block returning html content
24
+ #
25
+ # @return [String] The html generated for the tag.
29
26
  #
27
+ # @example
30
28
  # content_tag(:p, "hello", :class => 'light')
31
- # content_tag(:p, :class => 'dark') do ... end
32
- # content_tag(name, content=nil, options={}, &block)
29
+ # content_tag(:p, :class => 'dark') { ... }
33
30
  #
31
+ # @api public
34
32
  def content_tag(*args, &block)
35
33
  name = args.first
36
34
  options = args.extract_options!
@@ -39,14 +37,41 @@ module Padrino
39
37
  block_is_template?(block) ? concat_content(tag_result) : tag_result
40
38
  end
41
39
 
40
+ ##
41
+ # Creates an html input field with given type and options
42
+ #
43
+ # @param [Symbol] type
44
+ # The html type of tag to create.
45
+ # @param [Hash] options
46
+ # The html options to include in this tag.
47
+ #
48
+ # @return [String] The html for the input tag.
49
+ #
50
+ # @example
51
+ # input_tag :text, :class => "test"
52
+ # input_tag :password, :size => "20"
53
+ #
54
+ # @api semipublic
55
+ def input_tag(type, options = {})
56
+ options.reverse_merge!(:type => type)
57
+ tag(:input, options)
58
+ end
59
+
42
60
  ##
43
61
  # Creates an html tag with the given name and options
44
62
  #
45
- # ==== Examples
63
+ # @param [Symbol] type
64
+ # The html type of tag to create.
65
+ # @param [Hash] options
66
+ # The html options to include in this tag.
67
+ #
68
+ # @return [String] The html for the input tag.
46
69
  #
70
+ # @example
47
71
  # tag(:br, :style => 'clear:both')
48
72
  # tag(:p, :content => "hello", :class => 'large')
49
73
  #
74
+ # @api public
50
75
  def tag(name, options={})
51
76
  content, open_tag = options.delete(:content), options.delete(:open)
52
77
  content = content.join("\n") if content.respond_to?(:join)
@@ -4,6 +4,13 @@ module Padrino
4
4
  ##
5
5
  # Delegates to I18n.translate with no additional functionality.
6
6
  #
7
+ # @param [Symbol] *args
8
+ # The keys to retrieve.
9
+ #
10
+ # @return [String]
11
+ # The translation for the specified keys.
12
+ #
13
+ # @api public
7
14
  def translate(*args)
8
15
  I18n.translate(*args)
9
16
  end
@@ -12,6 +19,13 @@ module Padrino
12
19
  ##
13
20
  # Delegates to I18n.localize with no additional functionality.
14
21
  #
22
+ # @param [Symbol] *args
23
+ # The keys to retrieve.
24
+ #
25
+ # @return [String]
26
+ # The translation for the specified keys.
27
+ #
28
+ # @api public
15
29
  def localize(*args)
16
30
  I18n.localize(*args)
17
31
  end
@@ -9,3 +9,6 @@
9
9
  <% end %>
10
10
 
11
11
  <div class='demo2'><%= yield_content :demo2, "Johnny", "Smith" %></div>
12
+
13
+ <div class="demo_has_content"><%= content_for?(:demo).to_s %>
14
+ <div class="fake_has_content"><%= content_for?(:fake).to_s %>
@@ -7,3 +7,6 @@
7
7
  %h1 This is content yielded with name #{fname + " " + lname}
8
8
 
9
9
  .demo2= yield_content :demo2, "Johnny", "Smith"
10
+
11
+ .demo_has_content= content_for?(:demo)
12
+ .fake_has_content= content_for?(:fake)
@@ -7,3 +7,6 @@
7
7
  h1 This is content yielded with name #{fname + " " + lname}
8
8
 
9
9
  .demo2== yield_content :demo2, "Johnny", "Smith"
10
+
11
+ .demo_has_content== content_for?(:demo)
12
+ .fake_has_content== content_for?(:fake)
@@ -1,13 +1,11 @@
1
1
  require File.expand_path('../../../load_paths', __FILE__)
2
- require 'test/unit'
3
- require 'shoulda'
4
- require 'mocha'
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'padrino-core', 'test', 'mini_shoulda')
5
3
  require 'rack/test'
6
4
  require 'webrat'
7
5
  require 'padrino-helpers'
8
6
  require 'active_support/time'
9
7
 
10
- class Test::Unit::TestCase
8
+ class MiniTest::Spec
11
9
  include Padrino::Helpers::OutputHelpers
12
10
  include Padrino::Helpers::TagHelpers
13
11
  include Padrino::Helpers::AssetTagHelpers
@@ -44,16 +42,6 @@ class Test::Unit::TestCase
44
42
  assert matcher.matches?(html), matcher.failure_message
45
43
  end
46
44
 
47
- # Silences the output by redirecting to stringIO
48
- # silence_logger { ...commands... } => "...output..."
49
- def silence_logger(&block)
50
- orig_stdout = $stdout
51
- $stdout = log_buffer = StringIO.new
52
- block.call
53
- $stdout = orig_stdout
54
- log_buffer.rewind && log_buffer.read
55
- end
56
-
57
45
  # Asserts that a file matches the pattern
58
46
  def assert_match_in_file(pattern, file)
59
47
  assert File.exist?(file), "File '#{file}' does not exist!"
@@ -71,7 +59,7 @@ end
71
59
 
72
60
  module Webrat
73
61
  module Logging
74
- def logger # # @private
62
+ def logger # @private
75
63
  @logger = nil
76
64
  end
77
65
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
  require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
3
3
 
4
- class TestAssetTagHelpers < Test::Unit::TestCase
4
+ describe "AssetTagHelpers" do
5
5
  include Padrino::Helpers::AssetTagHelpers
6
6
 
7
7
  def app
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
  require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
3
3
 
4
- class TestFormBuilder < Test::Unit::TestCase
4
+ describe "FormBuilder" do
5
5
  include Padrino::Helpers::FormHelpers
6
6
 
7
7
  # Dummy form builder for testing
@@ -51,9 +51,7 @@ class TestFormBuilder < Test::Unit::TestCase
51
51
  should "display form specifying default builder setting" do
52
52
  self.expects(:settings).returns(stub(:default_builder => 'FakeFormBuilder')).once
53
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
54
+ actual_html = form_for(@user, '/register', :id => 'register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.foo_field }
57
55
  assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :method => 'post') { actual_html }
58
56
  assert_has_tag('span', :content => "bar") { actual_html }
59
57
  end
@@ -88,7 +86,7 @@ class TestFormBuilder < Test::Unit::TestCase
88
86
 
89
87
  should "support changing form builder type" do
90
88
  form_html = proc { form_for(@user, '/register', :"accept-charset" => "UTF-8", :builder => "AbstractFormBuilder") { |f| f.text_field_block(:name) } }
91
- assert_raise(NoMethodError) { form_html.call }
89
+ assert_raises(NoMethodError) { form_html.call }
92
90
  end
93
91
 
94
92
  should "support using default standard builder" do
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
  require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
3
3
 
4
- class TestFormHelpers < Test::Unit::TestCase
4
+ describe "FormHelpers" do
5
5
  include Padrino::Helpers::FormHelpers
6
6
 
7
7
  def app
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
  require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
3
3
 
4
- class TestFormatHelpers < Test::Unit::TestCase
4
+ describe "FormatHelpers" do
5
5
  def app
6
6
  MarkupDemo.tap { |app| app.set :environment, :test }
7
7
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
- class TestLocales < Test::Unit::TestCase
3
+ describe "Locale Helpers" do
4
4
  Dir[File.expand_path("../../lib/padrino-helpers/locale/*.yml", __FILE__)].each do |file|
5
5
  base_original = YAML.load_file(file)
6
6
  name = File.basename(file, '.yml')
@@ -1,4 +1,4 @@
1
- class TestNumberHelpers < Test::Unit::TestCase
1
+ describe "NumberHelpers" do
2
2
  include Padrino::Helpers::NumberHelpers
3
3
 
4
4
  def kilobytes(number)
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
  require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
3
3
 
4
- class TestOutputHelpers < Test::Unit::TestCase
4
+ describe "OutputHelpers" do
5
5
  def app
6
6
  MarkupDemo.tap { |app| app.set :environment, :test }
7
7
  end
@@ -24,7 +24,27 @@ class TestOutputHelpers < Test::Unit::TestCase
24
24
  assert_have_selector '.demo h1', :content => "This is content yielded from a content_for"
25
25
  assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith"
26
26
  end
27
- end
27
+ end # content_for
28
+
29
+ context "for #content_for? method" do
30
+ should 'work for erb templates' do
31
+ visit '/erb/content_for'
32
+ assert_have_selector '.demo_has_content', :content => "true"
33
+ assert_have_selector '.fake_has_content', :content => "false"
34
+ end
35
+
36
+ should "work for haml templates" do
37
+ visit '/haml/content_for'
38
+ assert_have_selector '.demo_has_content', :content => "true"
39
+ assert_have_selector '.fake_has_content', :content => "false"
40
+ end
41
+
42
+ should "work for slim templates" do
43
+ visit '/slim/content_for'
44
+ assert_have_selector '.demo_has_content', :content => "true"
45
+ assert_have_selector '.fake_has_content', :content => "false"
46
+ end
47
+ end # content_for?
28
48
 
29
49
  context 'for #capture_html method' do
30
50
  should "work for erb templates" do
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
  require File.expand_path(File.dirname(__FILE__) + '/fixtures/render_app/app')
3
3
 
4
- class TestRenderHelpers < Test::Unit::TestCase
4
+ describe "RenderHelpers" do
5
5
  def app
6
6
  RenderDemo.tap { |app| app.set :environment, :test }
7
7
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
  require File.expand_path(File.dirname(__FILE__) + '/fixtures/markup_app/app')
3
3
 
4
- class TestTagHelpers < Test::Unit::TestCase
4
+ describe "TagHelpers" do
5
5
  def app
6
6
  MarkupDemo.tap { |app| app.set :environment, :test }
7
7
  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: 51
4
+ hash: 49
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 10
9
- - 2
10
- version: 0.10.2
9
+ - 3
10
+ version: 0.10.3
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-08-31 00:00:00 -07:00
21
+ date: 2011-10-03 00:00:00 -07:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -29,12 +29,12 @@ dependencies:
29
29
  requirements:
30
30
  - - "="
31
31
  - !ruby/object:Gem::Version
32
- hash: 51
32
+ hash: 49
33
33
  segments:
34
34
  - 0
35
35
  - 10
36
- - 2
37
- version: 0.10.2
36
+ - 3
37
+ version: 0.10.3
38
38
  type: :runtime
39
39
  version_requirements: *id001
40
40
  - !ruby/object:Gem::Dependency
@@ -63,7 +63,8 @@ extra_rdoc_files:
63
63
  files:
64
64
  - .document
65
65
  - .gitignore
66
- - LICENSE
66
+ - .yardopts
67
+ - LICENSE.txt
67
68
  - README.rdoc
68
69
  - Rakefile
69
70
  - lib/padrino-helpers.rb
@@ -81,6 +82,7 @@ files:
81
82
  - lib/padrino-helpers/locale/hu.yml
82
83
  - lib/padrino-helpers/locale/it.yml
83
84
  - lib/padrino-helpers/locale/ja.yml
85
+ - lib/padrino-helpers/locale/lv.yml
84
86
  - lib/padrino-helpers/locale/nl.yml
85
87
  - lib/padrino-helpers/locale/no.yml
86
88
  - lib/padrino-helpers/locale/pl.yml