styled_inputs 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,10 @@
1
1
  == master
2
2
 
3
+ == 0.1.1 / 2008-12-28
4
+
5
+ * Don't style hidden inputs
6
+ * Fix input styling not always being included on classes directly including ActionView::Helpers::TagHelper
7
+
3
8
  == 0.1.0 / 2008-12-14
4
9
 
5
10
  * Remove the PluginAWeek namespace
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'styled_inputs'
8
- s.version = '0.1.0'
8
+ s.version = '0.1.1'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Adds automated styling of input fields with css classes'
11
11
 
@@ -24,23 +24,4 @@ require 'styled_inputs/extensions/instance_tag'
24
24
  # text_field_tag('name', :class => 'selected') # => <input class="text selected" id="name" name="name" type="text" />
25
25
  # text_field_tag('name', :class => 'selected shadow') # => <input class="text selected shadow" id="name" name="name" type="text" />
26
26
  module StyledInputs
27
- # Appends the input type to the value currently stored in the html options
28
- # for the tag.
29
- def styled_input(name, options = nil)
30
- options = (options || {}).stringify_keys
31
-
32
- if name.to_s == 'input' && options.include?('type')
33
- options['class'] = (options['class'].to_s + " #{options['type']}").strip
34
- end
35
-
36
- options
37
- end
38
- end
39
-
40
- ActionController::Base.class_eval do
41
- helper StyledInputs
42
- end
43
-
44
- ActionView::Helpers::InstanceTag.class_eval do
45
- include StyledInputs
46
27
  end
@@ -1,22 +1,6 @@
1
- module StyledInputs
2
- module Extensions #:nodoc:
3
- # Adds support for hooking calls to +tag+ for form fields
4
- module InstanceTag
5
- def self.included(base) #:nodoc:
6
- base.class_eval do
7
- alias_method_chain :tag, :styled_inputs
8
- end
9
- end
10
-
11
- # Ensure that the options are updated for input tags before generating
12
- # the html for the tag
13
- def tag_with_styled_inputs(name, options, *args) #:nodoc:
14
- tag_without_styled_inputs(name, styled_input(name, options), *args)
15
- end
16
- end
17
- end
18
- end
19
-
1
+ # ActiveRecordHelper chains InstanceTag's +tag+ implementation. As a result,
2
+ # in order to add styled inputs, that re-implementation needs to be chained
3
+ # again.
20
4
  ActionView::Helpers::InstanceTag.class_eval do
21
- include StyledInputs::Extensions::InstanceTag
5
+ alias_method_chain :tag, :styled_inputs
22
6
  end
@@ -1,22 +1,19 @@
1
- module StyledInputs
2
- module Extensions #:nodoc:
3
- # Adds support for hooking calls to +tag+
4
- module TagHelper
5
- def self.included(base) #:nodoc:
6
- base.class_eval do
7
- alias_method_chain :tag, :styled_inputs
8
- end
9
- end
10
-
11
- # Ensure that the options are updated for input tags before generating
12
- # the html for the tag
13
- def tag_with_styled_inputs(name, options = nil, *args) #:nodoc:
14
- tag_without_styled_inputs(name, styled_input(name, options), *args)
15
- end
16
- end
17
- end
18
- end
19
-
1
+ # The TagHelper module is re-opened directly instead of including additional
2
+ # modules in order for the chained behavior to be applied to other, unanticipated
3
+ # classes that include ActionView::Helpers::TagHelper directly.
20
4
  ActionView::Helpers::TagHelper.class_eval do
21
- include StyledInputs::Extensions::TagHelper
5
+ # Appends the input type to the value currently stored in the html options
6
+ # for the tag.
7
+ def styled_input(name, options = nil)
8
+ options = (options || {}).stringify_keys
9
+ options['class'] = "#{options['class']} #{options['type']}".strip if name.to_s == 'input' && options.include?('type') && options['type'] != 'hidden'
10
+ options
11
+ end
12
+
13
+ # Ensure that the options are updated for input tags before generating
14
+ # the html for the tag
15
+ def tag_with_styled_inputs(name, options = nil, *args) #:nodoc:
16
+ tag_without_styled_inputs(name, styled_input(name, options), *args)
17
+ end
18
+ alias_method_chain :tag, :styled_inputs
22
19
  end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class DateHelperTest < ActionView::TestCase
4
+ def test_should_not_style_hidden_date_fields_if_using_hidden
5
+ assert_equal '<input id="date_year" name="date[year]" type="hidden" value="1980" />', select_year(1980, :use_hidden => true).strip
6
+ end
7
+
8
+ def test_should_not_style_hidden_date_fields_if_not_using_hidden
9
+ expected = <<-end_str
10
+ <select id="date_year" name="date[year]">
11
+ <option selected="selected" value="1980">1980</option>
12
+ <option value="1981">1981</option>
13
+ </select>
14
+ end_str
15
+ assert_equal expected, select_year(1980, :start_year => 1980, :end_year => 1981)
16
+ end
17
+ end
@@ -8,8 +8,6 @@ class FormHelperTest < ActionView::TestCase
8
8
  :secret
9
9
  end
10
10
 
11
- tests StyledInputs
12
-
13
11
  def setup
14
12
  @person = Person.new
15
13
  end
@@ -22,8 +20,8 @@ class FormHelperTest < ActionView::TestCase
22
20
  assert_equal '<input class="password" id="person_secret" name="person[secret]" size="30" type="password" />', password_field(:person, :secret)
23
21
  end
24
22
 
25
- def test_should_style_hidden_field
26
- assert_equal '<input class="hidden" id="person_name" name="person[name]" type="hidden" />', hidden_field(:person, :name)
23
+ def test_should_not_style_hidden_field
24
+ assert_equal '<input id="person_name" name="person[name]" type="hidden" />', hidden_field(:person, :name)
27
25
  end
28
26
 
29
27
  def test_should_style_file_field
@@ -33,7 +31,7 @@ class FormHelperTest < ActionView::TestCase
33
31
  def test_should_style_check_box
34
32
  expected =
35
33
  '<input class="checkbox" id="person_agree" name="person[agree]" type="checkbox" value="1" />' +
36
- '<input class="hidden" name="person[agree]" type="hidden" value="0" />'
34
+ '<input name="person[agree]" type="hidden" value="0" />'
37
35
  assert_equal expected, check_box(:person, :agree)
38
36
  end
39
37
 
@@ -1,14 +1,12 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class FormTagHelperTest < ActionView::TestCase
4
- tests StyledInputs
5
-
6
4
  def test_should_style_text_field_tag
7
5
  assert_equal '<input class="text" id="name" name="name" type="text" />', text_field_tag('name')
8
6
  end
9
7
 
10
- def test_should_style_hidden_field_tag
11
- assert_equal '<input class="hidden" id="name" name="name" type="hidden" />', hidden_field_tag('name')
8
+ def test_should_not_style_hidden_field_tag
9
+ assert_equal '<input id="name" name="name" type="hidden" />', hidden_field_tag('name')
12
10
  end
13
11
 
14
12
  def test_should_style_file_field_tag
@@ -1,8 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class StyledInputsTest < ActionView::TestCase
4
- tests StyledInputs
5
-
6
4
  def test_should_not_style_input_if_tag_is_not_input
7
5
  expected = {}
8
6
  assert_equal expected, styled_input('td', expected)
@@ -1,8 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class TagHelperTest < ActionView::TestCase
4
- tests StyledInputs
5
-
6
4
  def test_should_allow_no_options_to_be_specified
7
5
  assert_equal '<br />', tag('br')
8
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: styled_inputs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-14 00:00:00 -05:00
12
+ date: 2008-12-28 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -32,6 +32,7 @@ files:
32
32
  - test/helpers/tag_helper_test.rb
33
33
  - test/helpers/styled_inputs_test.rb
34
34
  - test/helpers/form_helper_test.rb
35
+ - test/helpers/date_helper_test.rb
35
36
  - test/helpers/form_tag_helper_test.rb
36
37
  - CHANGELOG.rdoc
37
38
  - init.rb
@@ -68,4 +69,5 @@ test_files:
68
69
  - test/helpers/tag_helper_test.rb
69
70
  - test/helpers/styled_inputs_test.rb
70
71
  - test/helpers/form_helper_test.rb
72
+ - test/helpers/date_helper_test.rb
71
73
  - test/helpers/form_tag_helper_test.rb