styled_inputs 0.1.0 → 0.1.1
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.
- data/CHANGELOG.rdoc +5 -0
- data/Rakefile +1 -1
- data/lib/styled_inputs.rb +0 -19
- data/lib/styled_inputs/extensions/instance_tag.rb +4 -20
- data/lib/styled_inputs/extensions/tag_helper.rb +17 -20
- data/test/helpers/date_helper_test.rb +17 -0
- data/test/helpers/form_helper_test.rb +3 -5
- data/test/helpers/form_tag_helper_test.rb +2 -4
- data/test/helpers/styled_inputs_test.rb +0 -2
- data/test/helpers/tag_helper_test.rb +0 -2
- metadata +4 -2
data/CHANGELOG.rdoc
CHANGED
data/Rakefile
CHANGED
data/lib/styled_inputs.rb
CHANGED
@@ -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
|
-
|
2
|
-
|
3
|
-
|
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
|
-
|
5
|
+
alias_method_chain :tag, :styled_inputs
|
22
6
|
end
|
@@ -1,22 +1,19 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
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
|
-
|
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
|
26
|
-
assert_equal '<input
|
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
|
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
|
11
|
-
assert_equal '<input
|
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
|
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.
|
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-
|
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
|