input_css 0.1.1 → 0.1.2
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 +7 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/Rakefile +5 -0
- data/input_css.gemspec +3 -0
- data/lib/input_css.rb +29 -19
- data/lib/input_css/version.rb +1 -1
- data/spec/input_css_spec.rb +27 -27
- data/spec/spec_helper.rb +68 -2
- metadata +41 -21
- data/init.rb +0 -1
- data/install.rb +0 -1
- data/spec/rcov.opts +0 -4
- data/spec/spec.opts +0 -5
- data/uninstall.rb +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a909d7c29971c180313b62f06634385d5e1152af
|
4
|
+
data.tar.gz: ac555296f644e2eba5293b9070de7a317c7b154b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c0b71c9249581e5bb6253ae3b53830be8ace7abaff170701da159d653564228f564600b9eef24b238d97e751c261c063b139260c68b57809ed3dfa4985da00d
|
7
|
+
data.tar.gz: 915d650fb1d021739232056f6b4d56d547691c5ec013c9e68e51141a6b8799a2e4f399e7f10cb6753e74af05517b879060e731d31eec35279db1a569ff20e647
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Rakefile
CHANGED
data/input_css.gemspec
CHANGED
data/lib/input_css.rb
CHANGED
@@ -3,29 +3,39 @@ require "input_css/version"
|
|
3
3
|
# Modifies the 'options' of the tag helper so that, by default,
|
4
4
|
# there's a CSS class attribute based on the type attribute
|
5
5
|
# (Note: only applies to input fields)
|
6
|
+
module InputCSS
|
7
|
+
def tag(name, options=nil, open=false, escape=true)
|
8
|
+
options = css_options_for_tag(name, options)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def css_options_for_tag(name, options)
|
13
|
+
options = HashWithIndifferentAccess.new(options)
|
14
|
+
return options if options[:type] == 'hidden'
|
15
|
+
|
16
|
+
# alter CSS class based on type
|
17
|
+
# (only for <input ... /> tags)
|
18
|
+
if name.to_s.downcase =~ /^input$/
|
19
|
+
type, css = options[:type], options[:class]
|
20
|
+
type = 'text' if type == 'password'
|
21
|
+
options[:class] = "#{css.to_s} #{type.to_s}".gsub!(/^\s*/, '') unless css && css.split.include?(type)
|
22
|
+
end
|
23
|
+
options
|
24
|
+
end
|
25
|
+
module_function :css_options_for_tag
|
26
|
+
end
|
27
|
+
|
6
28
|
module ActionView
|
7
29
|
module Helpers
|
8
30
|
module TagHelper
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def css_options_for_tag(name, options)
|
18
|
-
options = HashWithIndifferentAccess.new(options)
|
19
|
-
return options if options[:type] == 'hidden'
|
20
|
-
|
21
|
-
# alter CSS class based on type
|
22
|
-
# (only for <input ... /> tags)
|
23
|
-
if name.to_s.downcase =~ /^input$/
|
24
|
-
type, css = options[:type], options[:class]
|
25
|
-
type = 'text' if type == 'password'
|
26
|
-
options[:class] = "#{css.to_s} #{type.to_s}".gsub!(/^\s*/, '') unless css && css.split.include?(type)
|
31
|
+
if respond_to?(:prepend) # Rails 5 compat
|
32
|
+
prepend InputCSS
|
33
|
+
else
|
34
|
+
def tag_with_default_css(name, options=nil, open=false, escape=true)
|
35
|
+
options = InputCSS.css_options_for_tag(name, options)
|
36
|
+
tag_without_default_css(name, options, open, escape)
|
27
37
|
end
|
28
|
-
|
38
|
+
alias_method_chain :tag, :default_css
|
29
39
|
end
|
30
40
|
end
|
31
41
|
|
data/lib/input_css/version.rb
CHANGED
data/spec/input_css_spec.rb
CHANGED
@@ -11,18 +11,18 @@ describe "InputCSS" do
|
|
11
11
|
VALID_TYPES.each do |type|
|
12
12
|
it "should have class='#{type}' for type='#{type}'" do
|
13
13
|
tag('input', { :type => type }).
|
14
|
-
should
|
14
|
+
should be_equivalent_to("<input class=\"#{type}\" type=\"#{type}\" />")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should have class='text' for type='password'" do
|
19
19
|
tag('input', { :type => 'password' }).
|
20
|
-
should
|
20
|
+
should be_equivalent_to("<input class=\"text\" type=\"password\" />")
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should not have a class attribute for type='hidden'" do
|
24
24
|
tag('input', {:type => 'hidden'}).
|
25
|
-
should
|
25
|
+
should be_equivalent_to("<input type=\"hidden\" />")
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -32,12 +32,12 @@ describe "InputCSS" do
|
|
32
32
|
|
33
33
|
describe "use examples shown in TagHelper#tag documentation" do
|
34
34
|
it "should not add a default class attribute to non-INPUT tags" do
|
35
|
-
tag('br').should
|
36
|
-
tag('br', nil, true).should
|
35
|
+
tag('br').should be_equivalent_to("<br />")
|
36
|
+
tag('br', nil, true).should be_equivalent_to("<br>")
|
37
37
|
tag('img', {:src => 'open & shut.png'}).
|
38
|
-
should
|
38
|
+
should be_equivalent_to("<img src=\"open & shut.png\" />")
|
39
39
|
tag('img', {:src => 'open & shut.png'}, false, false).
|
40
|
-
should
|
40
|
+
should be_equivalent_to("<img src=\"open & shut.png\" />")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -47,19 +47,19 @@ describe "InputCSS" do
|
|
47
47
|
|
48
48
|
it "should behave as expected (according to documentation) with the addition of default class" do
|
49
49
|
text_field_tag('name').
|
50
|
-
should
|
50
|
+
should be_equivalent_to("<input class=\"text\" id=\"name\" name=\"name\" type=\"text\" />")
|
51
51
|
text_field_tag('query', 'Enter your search query here').
|
52
|
-
should
|
52
|
+
should be_equivalent_to("<input class=\"text\" id=\"query\" name=\"query\" type=\"text\" value=\"Enter your search query here\" />")
|
53
53
|
text_field_tag('request', nil, :class => 'special_input').
|
54
|
-
should
|
54
|
+
should be_equivalent_to("<input class=\"special_input text\" id=\"request\" name=\"request\" type=\"text\" />")
|
55
55
|
text_field_tag('address', '', :size => 75).
|
56
|
-
should
|
56
|
+
should be_equivalent_to("<input class=\"text\" id=\"address\" name=\"address\" size=\"75\" type=\"text\" value=\"\" />")
|
57
57
|
text_field_tag('zip', nil, :maxlength => 5).
|
58
|
-
should
|
58
|
+
should be_equivalent_to("<input class=\"text\" id=\"zip\" maxlength=\"5\" name=\"zip\" type=\"text\" />")
|
59
59
|
text_field_tag('payment_amount', '$0.00', :disabled => true).
|
60
|
-
should
|
60
|
+
should be_equivalent_to("<input class=\"text\" disabled=\"disabled\" id=\"payment_amount\" name=\"payment_amount\" type=\"text\" value=\"$0.00\" />")
|
61
61
|
text_field_tag('ip', '0.0.0.0', :maxlength => 15, :size => 20, :class => 'ip-input').
|
62
|
-
should
|
62
|
+
should be_equivalent_to("<input class=\"ip-input text\" id=\"ip\" maxlength=\"15\" name=\"ip\" size=\"20\" type=\"text\" value=\"0.0.0.0\" />")
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -80,43 +80,43 @@ describe "InputCSS" do
|
|
80
80
|
# FormHelper#text_field
|
81
81
|
it "should add default css to text_field" do
|
82
82
|
text_field(:project, :title, :object => @project).
|
83
|
-
should
|
83
|
+
should be_equivalent_to("<input class=\"text\" id=\"project_title\" name=\"project[title]\" type=\"text\" value=\"RPH\" />")
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should append css to existing css" do
|
87
87
|
text_field(:project, :title, :object => @project, :class => 'project').
|
88
|
-
should
|
88
|
+
should be_equivalent_to("<input class=\"project text\" id=\"project_title\" name=\"project[title]\" type=\"text\" value=\"RPH\" />")
|
89
89
|
end
|
90
90
|
|
91
91
|
# FormHelper#hidden_field
|
92
92
|
it "should not add css to hidden_field" do
|
93
93
|
hidden_field(:project, :title, :object => @project).
|
94
|
-
should
|
94
|
+
should be_equivalent_to("<input id=\"project_title\" name=\"project[title]\" type=\"hidden\" value=\"RPH\" />")
|
95
95
|
end
|
96
96
|
|
97
97
|
# FormHelper#password_field
|
98
98
|
it "should add default css of 'text' to password_field" do
|
99
99
|
password_field(:project, :title, :object => @project).
|
100
|
-
should
|
100
|
+
should be_equivalent_to("<input class=\"text\" id=\"project_title\" name=\"project[title]\" type=\"password\" />")
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should add default css of 'text' to password_field" do
|
104
104
|
password_field(:project, :title, :object => @project, :class => 'project').
|
105
|
-
should
|
105
|
+
should be_equivalent_to("<input class=\"project text\" id=\"project_title\" name=\"project[title]\" type=\"password\" />")
|
106
106
|
end
|
107
107
|
|
108
108
|
# FormHelper#check_box
|
109
109
|
it "should add default css to check_box" do
|
110
110
|
check_box(:project, :is_complete, :object => @project).
|
111
|
-
should
|
112
|
-
"<input
|
113
|
-
"<input name=\"project[is_complete]\" type=\"
|
111
|
+
should be_equivalent_to(
|
112
|
+
"<input name=\"project[is_complete]\" type=\"hidden\" value=\"0\" />" +
|
113
|
+
"<input checked=\"checked\" class=\"checkbox\" id=\"project_is_complete\" name=\"project[is_complete]\" type=\"checkbox\" value=\"1\" />"
|
114
114
|
)
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should add default css to check_box" do
|
118
118
|
check_box(:project, :is_complete, :object => @project, :class => 'project').
|
119
|
-
should
|
119
|
+
should be_equivalent_to(
|
120
120
|
"<input checked=\"checked\" class=\"project checkbox\" id=\"project_is_complete\" name=\"project[is_complete]\" type=\"checkbox\" value=\"1\" />" +
|
121
121
|
"<input name=\"project[is_complete]\" type=\"hidden\" value=\"0\" />"
|
122
122
|
)
|
@@ -125,19 +125,19 @@ describe "InputCSS" do
|
|
125
125
|
# FormHelper#radio_button
|
126
126
|
it "should add default css to radio_button" do
|
127
127
|
radio_button(:project, :is_complete, 'yes').
|
128
|
-
should
|
128
|
+
should be_equivalent_to("<input class=\"radio\" id=\"project_is_complete_yes\" name=\"project[is_complete]\" type=\"radio\" value=\"yes\" />")
|
129
129
|
end
|
130
130
|
|
131
131
|
it "should add default css to radio_button" do
|
132
132
|
radio_button(:project, :is_complete, 'yes', :class => 'project').
|
133
|
-
should
|
133
|
+
should be_equivalent_to("<input class=\"project radio\" id=\"project_is_complete_yes\" name=\"project[is_complete]\" type=\"radio\" value=\"yes\" />")
|
134
134
|
end
|
135
135
|
|
136
136
|
# FormHelper#file_field
|
137
137
|
it "should add default css to file_field" do
|
138
138
|
file_field(:project, :chart).
|
139
|
-
should
|
139
|
+
should be_equivalent_to("<input class=\"file\" id=\"project_chart\" name=\"project[chart]\" type=\"file\" />")
|
140
140
|
end
|
141
141
|
end
|
142
142
|
end
|
143
|
-
end
|
143
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,70 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'action_controller'
|
3
2
|
require 'action_view'
|
4
|
-
|
3
|
+
require_relative "../lib/input_css"
|
4
|
+
|
5
|
+
require 'rspec/matchers' # req by equivalent-xml custom matcher `be_equivalent_to`
|
6
|
+
require 'equivalent-xml'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
# These two settings work together to allow you to limit a spec run
|
10
|
+
# to individual examples or groups you care about by tagging them with
|
11
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
12
|
+
# get run.
|
13
|
+
config.filter_run :focus
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
|
16
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
17
|
+
# file, and it's useful to allow more verbose output when running an
|
18
|
+
# individual spec file.
|
19
|
+
if config.files_to_run.one?
|
20
|
+
# Use the documentation formatter for detailed output,
|
21
|
+
# unless a formatter has already been configured
|
22
|
+
# (e.g. via a command-line flag).
|
23
|
+
config.default_formatter = 'doc'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Print the 10 slowest examples and example groups at the
|
27
|
+
# end of the spec run, to help surface which specs are running
|
28
|
+
# particularly slow.
|
29
|
+
# config.profile_examples = 10
|
30
|
+
|
31
|
+
# Run specs in random order to surface order dependencies. If you find an
|
32
|
+
# order dependency and want to debug it, you can fix the order by providing
|
33
|
+
# the seed, which is printed after each run.
|
34
|
+
# --seed 1234
|
35
|
+
config.order = :random
|
36
|
+
|
37
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
38
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
39
|
+
# test failures related to randomization by passing the same `--seed` value
|
40
|
+
# as the one that triggered the failure.
|
41
|
+
Kernel.srand config.seed
|
42
|
+
|
43
|
+
# rspec-expectations config goes here. You can use an alternate
|
44
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
45
|
+
# assertions if you prefer.
|
46
|
+
config.expect_with :rspec do |expectations|
|
47
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
48
|
+
# For more details, see:
|
49
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
50
|
+
expectations.syntax = [:should, :expect]
|
51
|
+
end
|
52
|
+
|
53
|
+
config.define_derived_metadata do |meta|
|
54
|
+
meta[:aggregate_failures] = true unless meta.key?(:aggregate_failures)
|
55
|
+
end
|
56
|
+
|
57
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
58
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
59
|
+
config.mock_with :rspec do |mocks|
|
60
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
61
|
+
# For more details, see:
|
62
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
63
|
+
mocks.syntax = [:should, :expect]
|
64
|
+
|
65
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
66
|
+
# a real object. This is generally recommended.
|
67
|
+
mocks.verify_partial_doubles = true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: input_css
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.1.1
|
4
|
+
version: 0.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ryan Heath
|
@@ -10,22 +9,48 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2017-07-19 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
|
-
prerelease: false
|
17
|
-
type: :runtime
|
18
15
|
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
19
37
|
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
none: false
|
21
38
|
requirements:
|
22
|
-
- -
|
39
|
+
- - ">="
|
23
40
|
- !ruby/object:Gem::Version
|
24
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: equivalent-xml
|
25
44
|
requirement: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
45
|
requirements:
|
28
|
-
- -
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
29
54
|
- !ruby/object:Gem::Version
|
30
55
|
version: '0'
|
31
56
|
description: This plugin taps into Rails tag helpers and adds a CSS class equal to
|
@@ -37,44 +62,39 @@ executables: []
|
|
37
62
|
extensions: []
|
38
63
|
extra_rdoc_files: []
|
39
64
|
files:
|
40
|
-
- .gitignore
|
65
|
+
- ".gitignore"
|
66
|
+
- ".rspec"
|
41
67
|
- Gemfile
|
42
68
|
- MIT-LICENSE
|
43
69
|
- README.textile
|
44
70
|
- Rakefile
|
45
|
-
- init.rb
|
46
71
|
- input_css.gemspec
|
47
|
-
- install.rb
|
48
72
|
- lib/input_css.rb
|
49
73
|
- lib/input_css/version.rb
|
50
74
|
- spec/input_css_spec.rb
|
51
|
-
- spec/rcov.opts
|
52
|
-
- spec/spec.opts
|
53
75
|
- spec/spec_helper.rb
|
54
76
|
- tasks/input_css_tasks.rake
|
55
|
-
- uninstall.rb
|
56
77
|
homepage: https://github.com/botandrose/input_css
|
57
78
|
licenses: []
|
79
|
+
metadata: {}
|
58
80
|
post_install_message:
|
59
81
|
rdoc_options: []
|
60
82
|
require_paths:
|
61
83
|
- lib
|
62
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
85
|
requirements:
|
65
|
-
- -
|
86
|
+
- - ">="
|
66
87
|
- !ruby/object:Gem::Version
|
67
88
|
version: '0'
|
68
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
90
|
requirements:
|
71
|
-
- -
|
91
|
+
- - ">="
|
72
92
|
- !ruby/object:Gem::Version
|
73
93
|
version: '0'
|
74
94
|
requirements: []
|
75
95
|
rubyforge_project: input_css
|
76
|
-
rubygems_version:
|
96
|
+
rubygems_version: 2.4.8
|
77
97
|
signing_key:
|
78
|
-
specification_version:
|
98
|
+
specification_version: 4
|
79
99
|
summary: Adds CSS classes for Rails input tags
|
80
100
|
test_files: []
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'input_css'
|
data/install.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# Install hook code here
|
data/spec/rcov.opts
DELETED
data/spec/spec.opts
DELETED
data/uninstall.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# Uninstall hook code here
|