form_helper_css 0.0.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/.gitignore +5 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +21 -0
- data/README +43 -0
- data/Rakefile +23 -0
- data/form_helper_css.gemspec +29 -0
- data/lib/form_helper_css/form_helper_css.rb +51 -0
- data/lib/form_helper_css/version.rb +3 -0
- data/lib/form_helper_css.rb +2 -0
- data/test/form_helper_css_test.rb +117 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2006 Markus Koller
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
= form_helper_css
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
This plugin enhances the default tag helpers to automatically add CSS classes
|
6
|
+
to form elements. It's similar to the <tt>enhanced_form_tag_helper</tt> plugin,
|
7
|
+
but takes a different approach by directly intercepting the <tt>tag</tt> and
|
8
|
+
<tt>content_tag</tt> methods, and should therefore work in all situations where
|
9
|
+
form elements are created, especially the <tt>FormHelper</tt> and more exotic
|
10
|
+
ones like <tt>button_to</tt>.
|
11
|
+
|
12
|
+
The following elements are enhanced:
|
13
|
+
|
14
|
+
* <tt><input></tt> tags get their type as class name
|
15
|
+
* submit and reset buttons additionally get the class name _button_
|
16
|
+
* password fields additionally get the class name _text_
|
17
|
+
* <tt><textarea></tt> tags get the class name _text_
|
18
|
+
* <tt><select></tt> and <tt><button></tt> tags are not enhanced
|
19
|
+
|
20
|
+
If any helper options already specify a class, nothing will be changed. If you
|
21
|
+
don't want a class to be added, pass <tt>:class => nil</tt>.
|
22
|
+
|
23
|
+
There is a single option which can be set in the following manner:
|
24
|
+
|
25
|
+
ActionView::Helpers::TagHelper::FORM_HELPER_CSS_OPTIONS.merge!(:append => true)
|
26
|
+
|
27
|
+
If set to true, then even if a class is specified, the magical classes will be appended to the output.
|
28
|
+
|
29
|
+
== License
|
30
|
+
|
31
|
+
The <tt>form_helper_css</tt> plugin is released under the MIT license.
|
32
|
+
|
33
|
+
== Author
|
34
|
+
|
35
|
+
Philip Hallstrom <philip at pjkh dot com>
|
36
|
+
|
37
|
+
== Original Author
|
38
|
+
|
39
|
+
Markus Koller <toupeira at gmx dot ch>
|
40
|
+
|
41
|
+
http://snafu.diarrhea.ch
|
42
|
+
|
43
|
+
24 December 2006
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rdoc/task'
|
5
|
+
|
6
|
+
desc 'Default: run unit tests.'
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
desc 'Test the form_helper_css plugin.'
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.libs << 'lib'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the form_helper_css plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'FormHelperCss'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "form_helper_css/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "form_helper_css"
|
7
|
+
s.version = FormHelperCss::VERSION
|
8
|
+
s.authors = ["Philip Hallstrom"]
|
9
|
+
s.email = ["philip at pjkh dot com"]
|
10
|
+
s.homepage = "https://github.com/phallstrom/form_helper_css"
|
11
|
+
s.summary = "enhances the default tag helpers to automatically add CSS classes to form elements"
|
12
|
+
s.description = "This plugin enhances the default tag helpers to automatically add CSS classes
|
13
|
+
to form elements. It's similar to the enhanced_form_tag_helper plugin,
|
14
|
+
but takes a different approach by directly intercepting the tag and
|
15
|
+
content_tag methods, and should therefore work in all situations where
|
16
|
+
form elements are created, especially the <tt>FormHelper</tt> and more exotic
|
17
|
+
ones like button_to."
|
18
|
+
|
19
|
+
s.rubyforge_project = "form_helper_css"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
|
26
|
+
# specify any dependencies here; for example:
|
27
|
+
s.add_development_dependency "rake"
|
28
|
+
# s.add_runtime_dependency "rest-client"
|
29
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
module ActionView
|
4
|
+
module Helpers
|
5
|
+
module TagHelper
|
6
|
+
|
7
|
+
FORM_HELPER_CSS_OPTIONS = {:append => false}
|
8
|
+
|
9
|
+
def css_options_for_tag(name, options={})
|
10
|
+
name = name.to_sym
|
11
|
+
options = options.stringify_keys
|
12
|
+
if FORM_HELPER_CSS_OPTIONS[:append] == false && options.has_key?('class')
|
13
|
+
return options
|
14
|
+
elsif name == :input and options['type']
|
15
|
+
return options if (options['type'] == 'hidden')
|
16
|
+
if FORM_HELPER_CSS_OPTIONS[:append] && options['class']
|
17
|
+
options['class'] << ' ' + options['type'].to_s.dup
|
18
|
+
else
|
19
|
+
options['class'] = options['type'].to_s.dup
|
20
|
+
end
|
21
|
+
options['class'] << ' button' if ['submit', 'reset'].include? options['type']
|
22
|
+
options['class'] << ' text' if options['type'] == 'password'
|
23
|
+
elsif name == :textarea
|
24
|
+
if FORM_HELPER_CSS_OPTIONS[:append] && options['class']
|
25
|
+
options['class'] << ' text'
|
26
|
+
else
|
27
|
+
options['class'] = 'text'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
if options['class']
|
31
|
+
options['class'] = options['class'].to_s.strip.split(/\s+/).uniq.join(' ') # de-dup the class list
|
32
|
+
end
|
33
|
+
options
|
34
|
+
end
|
35
|
+
|
36
|
+
def tag_with_css(name, options=nil, open=false, escape=true)
|
37
|
+
tag_without_css(name, css_options_for_tag(name, options || {}), open, escape)
|
38
|
+
end
|
39
|
+
alias_method_chain :tag, :css
|
40
|
+
|
41
|
+
def content_tag_string_with_css(name, content, options, escape=true)
|
42
|
+
content_tag_string_without_css(name, content, css_options_for_tag(name, options || {}), escape)
|
43
|
+
end
|
44
|
+
alias_method_chain :content_tag_string, :css
|
45
|
+
end
|
46
|
+
|
47
|
+
class InstanceTag
|
48
|
+
alias_method :tag_without_error_wrapping, :tag_with_css
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'action_controller'
|
6
|
+
require 'form_helper_css'
|
7
|
+
|
8
|
+
class FormHelperCssTest < Test::Unit::TestCase
|
9
|
+
include ActionView::Helpers::TagHelper
|
10
|
+
include ActionView::Helpers::UrlHelper
|
11
|
+
include ActionView::Helpers::FormTagHelper
|
12
|
+
include ActionView::Helpers::FormHelper
|
13
|
+
|
14
|
+
def setup
|
15
|
+
ActionView::Helpers::TagHelper::FORM_HELPER_CSS_OPTIONS.merge!(:append => false)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_tag_helper
|
19
|
+
assert_equal '<br />', tag(:br)
|
20
|
+
assert_equal '<p></p>', content_tag(:p, '')
|
21
|
+
assert_equal '<input type="text" />', tag(:input, :type => 'text', :class => nil)
|
22
|
+
assert_equal '<textarea></textarea>', content_tag(:textarea, '', :class => nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_url_helper
|
26
|
+
assert_match 'class="submit button"', button_to('button', '/')
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_form_tag_helper
|
30
|
+
assert_match 'class="checkbox"', check_box_tag('checkbox')
|
31
|
+
assert_match 'class="file"', file_field_tag('file')
|
32
|
+
assert_no_match /class=".+"/, hidden_field_tag('hidden')
|
33
|
+
assert_match 'class="password text"', password_field_tag('password')
|
34
|
+
assert_match 'class="radio"', radio_button_tag('radio', 'value')
|
35
|
+
assert_match 'class="submit button"', submit_tag('submit')
|
36
|
+
assert_match 'class="reset button"', submit_tag('reset', :type => 'reset')
|
37
|
+
assert_match 'class="button"', submit_tag('submit', :type => 'button')
|
38
|
+
assert_match 'class="text"', text_area_tag('text')
|
39
|
+
assert_match 'class="text"', text_field_tag('text')
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_form_tag_helper_with_class
|
43
|
+
assert_match 'class="foo"', check_box_tag('checkbox', 'value', false, :class => 'foo')
|
44
|
+
assert_match 'class="foo"', file_field_tag('file', :class => 'foo')
|
45
|
+
assert_match 'class="foo"', hidden_field_tag('hidden', 1, :class => 'foo')
|
46
|
+
assert_match 'class="foo"', password_field_tag('password', nil, :class => 'foo')
|
47
|
+
assert_match 'class="foo"', radio_button_tag('radio', 'value', false, :class => 'foo')
|
48
|
+
assert_match 'class="foo"', submit_tag('submit', :class => 'foo')
|
49
|
+
assert_match 'class="foo"', submit_tag('reset', :type => 'reset', :class => 'foo')
|
50
|
+
assert_match 'class="foo"', submit_tag('submit', :type => 'button', :class => 'foo')
|
51
|
+
assert_match 'class="foo"', text_area_tag('text', nil, :class => 'foo')
|
52
|
+
assert_match 'class="foo"', text_field_tag('text', nil, :class => 'foo')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_form_tag_helper_with_class_and_append
|
56
|
+
ActionView::Helpers::TagHelper::FORM_HELPER_CSS_OPTIONS.merge!(:append => true)
|
57
|
+
assert_match 'class="foo checkbox"', check_box_tag('checkbox', 'value', false, :class => 'foo')
|
58
|
+
assert_match 'class="foo file"', file_field_tag('file', :class => 'foo')
|
59
|
+
assert_match 'class="foo"', hidden_field_tag('hidden', 1, :class => 'foo')
|
60
|
+
assert_match 'class="foo password text"', password_field_tag('password', nil, :class => 'foo')
|
61
|
+
assert_match 'class="foo radio"', radio_button_tag('radio', 'value', false, :class => 'foo')
|
62
|
+
assert_match 'class="foo submit button"', submit_tag('submit', :class => 'foo')
|
63
|
+
assert_match 'class="foo reset button"', submit_tag('reset', :type => 'reset', :class => 'foo')
|
64
|
+
assert_match 'class="foo button"', submit_tag('submit', :type => 'button', :class => 'foo')
|
65
|
+
assert_match 'class="foo text"', text_area_tag('text', nil, :class => 'foo')
|
66
|
+
assert_match 'class="foo text"', text_field_tag('text', nil, :class => 'foo')
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def test_form_helper
|
71
|
+
assert_match 'class="checkbox"', check_box(:object, :field)
|
72
|
+
assert_match 'class="file"', file_field(:object, :field)
|
73
|
+
assert_no_match /class=".+"/, hidden_field(:object, :field)
|
74
|
+
assert_match 'class="password text"', password_field(:object, :field)
|
75
|
+
assert_match '', radio_button(:object, :field, 'value')
|
76
|
+
assert_match 'class="text"', text_area(:object, :field)
|
77
|
+
assert_match 'class="text"', text_field(:object, :field)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_form_helper_with_class
|
81
|
+
assert_match 'class="foo"', check_box(:object, :field, :class => 'foo')
|
82
|
+
assert_match 'class="foo"', file_field(:object, :field, :class => 'foo')
|
83
|
+
assert_match 'class="foo"', hidden_field(:object, :field, :class => 'foo')
|
84
|
+
assert_match 'class="foo"', password_field(:object, :field, :class => 'foo')
|
85
|
+
assert_match 'class="foo"', radio_button(:object, :field, 'value', :class => 'foo')
|
86
|
+
assert_match 'class="foo"', text_area(:object, :field, :class => 'foo')
|
87
|
+
assert_match 'class="foo"', text_field(:object, :field, :class => 'foo')
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_form_helper_with_class_and_append
|
91
|
+
ActionView::Helpers::TagHelper::FORM_HELPER_CSS_OPTIONS.merge!(:append => true)
|
92
|
+
assert_match 'class="foo checkbox"', check_box(:object, :field, :class => 'foo')
|
93
|
+
assert_match 'class="foo file"', file_field(:object, :field, :class => 'foo')
|
94
|
+
assert_match 'class="foo"', hidden_field(:object, :field, :class => 'foo')
|
95
|
+
assert_match 'class="foo password text"', password_field(:object, :field, :class => 'foo')
|
96
|
+
assert_match 'class="foo radio"', radio_button(:object, :field, 'value', :class => 'foo')
|
97
|
+
assert_match 'class="foo text"', text_area(:object, :field, :class => 'foo')
|
98
|
+
assert_match 'class="foo text"', text_field(:object, :field, :class => 'foo')
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_form_helper_with_duplicate_classes_and_append
|
102
|
+
ActionView::Helpers::TagHelper::FORM_HELPER_CSS_OPTIONS.merge!(:append => true)
|
103
|
+
assert_match 'class="foo bar checkbox"', check_box(:object, :field, :class => 'foo bar foo')
|
104
|
+
assert_match 'class="foo bar file"', file_field(:object, :field, :class => 'foo bar foo')
|
105
|
+
assert_match 'class="foo bar foo"', hidden_field(:object, :field, :class => 'foo bar foo')
|
106
|
+
assert_match 'class="foo bar password text"', password_field(:object, :field, :class => 'foo bar foo')
|
107
|
+
assert_match 'class="foo bar radio"', radio_button(:object, :field, 'value', :class => 'foo bar foo')
|
108
|
+
assert_match 'class="foo bar text"', text_area(:object, :field, :class => 'foo bar foo')
|
109
|
+
assert_match 'class="foo bar text"', text_field(:object, :field, :class => 'foo bar foo')
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
protected
|
114
|
+
def protect_against_forgery?
|
115
|
+
false
|
116
|
+
end
|
117
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: form_helper_css
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Philip Hallstrom
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70261521563800 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70261521563800
|
25
|
+
description: ! 'This plugin enhances the default tag helpers to automatically add
|
26
|
+
CSS classes
|
27
|
+
|
28
|
+
to form elements. It''s similar to the enhanced_form_tag_helper plugin,
|
29
|
+
|
30
|
+
but takes a different approach by directly intercepting the tag and
|
31
|
+
|
32
|
+
content_tag methods, and should therefore work in all situations where
|
33
|
+
|
34
|
+
form elements are created, especially the <tt>FormHelper</tt> and more exotic
|
35
|
+
|
36
|
+
ones like button_to.'
|
37
|
+
email:
|
38
|
+
- philip at pjkh dot com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- MIT-LICENSE
|
46
|
+
- README
|
47
|
+
- Rakefile
|
48
|
+
- form_helper_css.gemspec
|
49
|
+
- lib/form_helper_css.rb
|
50
|
+
- lib/form_helper_css/form_helper_css.rb
|
51
|
+
- lib/form_helper_css/version.rb
|
52
|
+
- test/form_helper_css_test.rb
|
53
|
+
homepage: https://github.com/phallstrom/form_helper_css
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project: form_helper_css
|
73
|
+
rubygems_version: 1.8.10
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: enhances the default tag helpers to automatically add CSS classes to form
|
77
|
+
elements
|
78
|
+
test_files:
|
79
|
+
- test/form_helper_css_test.rb
|