input_css 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in input_css.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
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.
data/README.textile ADDED
@@ -0,0 +1,55 @@
1
+ h1. Input CSS
2
+
3
+ This plugin taps into Rails tag helpers and adds a CSS class equal to the type attribute for all 'input' fields.
4
+
5
+ h2. Reasoning...
6
+
7
+ One of the biggest pains when designing forms is dealing with the input field. It's both a button and a text box. And you NEVER want them to look the same (and if you do, your issues are far past what this plugin has to offer).
8
+
9
+ And of course, this plugin exists mainly because of IE6's lack of CSS2 support. Blah.
10
+
11
+ h2. Installation
12
+
13
+ You can install this as a plugin. Navigate to your project root and type:
14
+
15
+ <pre><code>git clone git://github.com/rpheath/input_css.git vendor/plugins/input_css</code></pre>
16
+
17
+ After the installation, you're good to go.
18
+
19
+ h2. Example(s)
20
+
21
+ Here's how it works.
22
+
23
+ h3. Example 1: without existing CSS
24
+
25
+ <pre><code><%= f.text_field :name -%></code></pre>
26
+
27
+ Gives us:
28
+
29
+ <pre><code><input type="text" class="text" name="user[name]" value="" /></code></pre>
30
+
31
+ h3. Example 2: with existing CSS
32
+
33
+ <pre><code><%= submit_tag 'Fix Me', :class => 'button' -%></code></pre>
34
+
35
+ Gives us:
36
+
37
+ <pre><code><input name="commit" type="submit" class="button submit" value="Fix Me" /></code></pre>
38
+
39
+ h2. The CSS
40
+
41
+ So now, you can do this in your CSS:
42
+
43
+ <pre><code>
44
+ input.text { ... }
45
+ input.submit { ... }
46
+ input.file { ... }
47
+ input.checkbox { ... }
48
+ input.radio { ... }
49
+ </code></pre>
50
+
51
+ And things are _much_ easier to style :-)
52
+
53
+ h2. License
54
+
55
+ Copyright (c) 2008 Ryan Heath (http://rpheath.com), released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'input_css'
data/input_css.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "input_css/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "input_css"
7
+ s.version = InputCSS::VERSION
8
+ s.authors = ["Ryan Heath", "Micah Geisel"]
9
+ s.email = ["rpheath@gmail.com", "micah@botandrose.com"]
10
+ s.homepage = "https://github.com/botandrose/input_css"
11
+ s.summary = %q{Adds CSS classes for Rails input tags}
12
+ s.description = %q{This plugin taps into Rails tag helpers and adds a CSS class equal to the type attribute for all ‘input’ fields.}
13
+
14
+ s.rubyforge_project = "input_css"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "rails"
22
+ end
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,3 @@
1
+ module InputCSS
2
+ VERSION = "0.0.1"
3
+ end
data/lib/input_css.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "input_css/version"
2
+
3
+ # Modifies the 'options' of the tag helper so that, by default,
4
+ # there's a CSS class attribute based on the type attribute
5
+ # (Note: only applies to input fields)
6
+ module ActionView
7
+ module Helpers
8
+ module TagHelper
9
+ # intercept #tag method to modify the 'options'
10
+ def tag_with_default_css(name, options=nil, open=false, escape=true)
11
+ options = css_options_for_tag(name, options)
12
+ tag_without_default_css(name, options, open, escape)
13
+ end
14
+
15
+ # save the original method
16
+ alias_method_chain :tag, :default_css
17
+
18
+ private
19
+ def css_options_for_tag(name, options)
20
+ options = HashWithIndifferentAccess.new(options)
21
+ return options if options[:type] == 'hidden'
22
+
23
+ # alter CSS class based on type
24
+ # (only for <input ... /> tags)
25
+ if name.to_s.downcase =~ /^input$/
26
+ type, css = options[:type], options[:class]
27
+ type = 'text' if type == 'password'
28
+ options[:class] = "#{css.to_s} #{type.to_s}".gsub!(/^\s*/, '') unless css && css.split.include?(type)
29
+ end
30
+ options
31
+ end
32
+ end
33
+
34
+ # ensure that the new #tag_with_default_css
35
+ # method is always called
36
+ class InstanceTag
37
+ alias_method :tag_without_error_wrapping, :tag_with_default_css
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,143 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "InputCSS" do
4
+ AVH = ActionView::Helpers
5
+
6
+ describe "testing all valid INPUT types" do
7
+ include AVH::TagHelper
8
+
9
+ VALID_TYPES = %w[text submit reset checkbox radio file image button]
10
+
11
+ VALID_TYPES.each do |type|
12
+ it "should have class='#{type}' for type='#{type}'" do
13
+ tag('input', { :type => type }).
14
+ should eql("<input class=\"#{type}\" type=\"#{type}\" />")
15
+ end
16
+ end
17
+
18
+ it "should have class='text' for type='password'" do
19
+ tag('input', { :type => 'password' }).
20
+ should eql("<input class=\"text\" type=\"password\" />")
21
+ end
22
+
23
+ it "should not have a class attribute for type='hidden'" do
24
+ tag('input', {:type => 'hidden'}).
25
+ should eql("<input type=\"hidden\" />")
26
+ end
27
+ end
28
+
29
+ # (http://www.noobkit.com/show/ruby/rails/rails-stable/actionpack/actionview/helpers/taghelper/tag.html)
30
+ describe "ActionView::Helpers" do
31
+ include AVH::TagHelper
32
+
33
+ describe "use examples shown in TagHelper#tag documentation" do
34
+ it "should not add a default class attribute to non-INPUT tags" do
35
+ tag('br').should eql("<br />")
36
+ tag('br', nil, true).should eql("<br>")
37
+ tag('img', {:src => 'open & shut.png'}).
38
+ should eql("<img src=\"open &amp; shut.png\" />")
39
+ tag('img', {:src => 'open &amp; shut.png'}, false, false).
40
+ should eql("<img src=\"open &amp; shut.png\" />")
41
+ end
42
+ end
43
+
44
+ # (http://www.noobkit.com/show/ruby/rails/rails-stable/actionpack/actionview/helpers/formtaghelper/text_field_tag.html)
45
+ describe "use examples shown in FormTagHelper#text_field_tag documentation" do
46
+ include AVH::FormTagHelper
47
+
48
+ it "should behave as expected (according to documentation) with the addition of default class" do
49
+ text_field_tag('name').
50
+ should eql("<input class=\"text\" id=\"name\" name=\"name\" type=\"text\" />")
51
+ text_field_tag('query', 'Enter your search query here').
52
+ should eql("<input class=\"text\" id=\"query\" name=\"query\" type=\"text\" value=\"Enter your search query here\" />")
53
+ text_field_tag('request', nil, :class => 'special_input').
54
+ should eql("<input class=\"special_input text\" id=\"request\" name=\"request\" type=\"text\" />")
55
+ text_field_tag('address', '', :size => 75).
56
+ should eql("<input class=\"text\" id=\"address\" name=\"address\" size=\"75\" type=\"text\" value=\"\" />")
57
+ text_field_tag('zip', nil, :maxlength => 5).
58
+ should eql("<input class=\"text\" id=\"zip\" maxlength=\"5\" name=\"zip\" type=\"text\" />")
59
+ text_field_tag('payment_amount', '$0.00', :disabled => true).
60
+ should eql("<input class=\"text\" disabled=\"disabled\" id=\"payment_amount\" name=\"payment_amount\" type=\"text\" value=\"$0.00\" />")
61
+ text_field_tag('ip', '0.0.0.0', :maxlength => 15, :size => 20, :class => 'ip-input').
62
+ should eql("<input class=\"ip-input text\" id=\"ip\" maxlength=\"15\" name=\"ip\" size=\"20\" type=\"text\" value=\"0.0.0.0\" />")
63
+ end
64
+ end
65
+
66
+ describe "testing FormHelpers" do
67
+ include AVH::FormHelper
68
+
69
+ class Project
70
+ attr_accessor :title, :is_complete
71
+ def initialize(title, is_complete)
72
+ @title, @is_complete = title, is_complete
73
+ end
74
+ end
75
+
76
+ before(:each) do
77
+ @project = Project.new('RPH', true)
78
+ end
79
+
80
+ # FormHelper#text_field
81
+ it "should add default css to text_field" do
82
+ text_field(:project, :title, :object => @project).
83
+ should eql("<input class=\"text\" id=\"project_title\" name=\"project[title]\" size=\"30\" type=\"text\" value=\"RPH\" />")
84
+ end
85
+
86
+ it "should append css to existing css" do
87
+ text_field(:project, :title, :object => @project, :class => 'project').
88
+ should eql("<input class=\"project text\" id=\"project_title\" name=\"project[title]\" size=\"30\" type=\"text\" value=\"RPH\" />")
89
+ end
90
+
91
+ # FormHelper#hidden_field
92
+ it "should not add css to hidden_field" do
93
+ hidden_field(:project, :title, :object => @project).
94
+ should eql("<input id=\"project_title\" name=\"project[title]\" type=\"hidden\" value=\"RPH\" />")
95
+ end
96
+
97
+ # FormHelper#password_field
98
+ it "should add default css of 'text' to password_field" do
99
+ password_field(:project, :title, :object => @project).
100
+ should eql("<input class=\"text\" id=\"project_title\" name=\"project[title]\" size=\"30\" type=\"password\" value=\"RPH\" />")
101
+ end
102
+
103
+ it "should add default css of 'text' to password_field" do
104
+ password_field(:project, :title, :object => @project, :class => 'project').
105
+ should eql("<input class=\"project text\" id=\"project_title\" name=\"project[title]\" size=\"30\" type=\"password\" value=\"RPH\" />")
106
+ end
107
+
108
+ # FormHelper#check_box
109
+ it "should add default css to check_box" do
110
+ check_box(:project, :is_complete, :object => @project).
111
+ should eql(
112
+ "<input checked=\"checked\" class=\"checkbox\" id=\"project_is_complete\" name=\"project[is_complete]\" type=\"checkbox\" value=\"1\" />" +
113
+ "<input name=\"project[is_complete]\" type=\"hidden\" value=\"0\" />"
114
+ )
115
+ end
116
+
117
+ it "should add default css to check_box" do
118
+ check_box(:project, :is_complete, :object => @project, :class => 'project').
119
+ should eql(
120
+ "<input checked=\"checked\" class=\"project checkbox\" id=\"project_is_complete\" name=\"project[is_complete]\" type=\"checkbox\" value=\"1\" />" +
121
+ "<input name=\"project[is_complete]\" type=\"hidden\" value=\"0\" />"
122
+ )
123
+ end
124
+
125
+ # FormHelper#radio_button
126
+ it "should add default css to radio_button" do
127
+ radio_button(:project, :is_complete, 'yes').
128
+ should eql("<input class=\"radio\" id=\"project_is_complete_yes\" name=\"project[is_complete]\" type=\"radio\" value=\"yes\" />")
129
+ end
130
+
131
+ it "should add default css to radio_button" do
132
+ radio_button(:project, :is_complete, 'yes', :class => 'project').
133
+ should eql("<input class=\"project radio\" id=\"project_is_complete_yes\" name=\"project[is_complete]\" type=\"radio\" value=\"yes\" />")
134
+ end
135
+
136
+ # FormHelper#file_field
137
+ it "should add default css to file_field" do
138
+ file_field(:project, :chart).
139
+ should eql("<input class=\"file\" id=\"project_chart\" name=\"project[chart]\" size=\"30\" type=\"file\" />")
140
+ end
141
+ end
142
+ end
143
+ end
data/spec/rcov.opts ADDED
@@ -0,0 +1,4 @@
1
+ --exclude
2
+ gems
3
+ --exclude
4
+ spec
data/spec/spec.opts ADDED
@@ -0,0 +1,5 @@
1
+ --colour
2
+ --backtrace
3
+ --format
4
+ specdoc
5
+ --diff
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'action_controller'
3
+ require 'action_view'
4
+ require File.join(File.dirname(__FILE__), "../lib/input_css")
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :input_css do
3
+ # # Task goes here
4
+ # end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: input_css
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ryan Heath
14
+ - Micah Geisel
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2012-01-06 00:00:00 -08:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rails
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: "This plugin taps into Rails tag helpers and adds a CSS class equal to the type attribute for all \xE2\x80\x98input\xE2\x80\x99 fields."
37
+ email:
38
+ - rpheath@gmail.com
39
+ - micah@botandrose.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - MIT-LICENSE
50
+ - README.textile
51
+ - Rakefile
52
+ - init.rb
53
+ - input_css.gemspec
54
+ - install.rb
55
+ - lib/input_css.rb
56
+ - lib/input_css/version.rb
57
+ - spec/input_css_spec.rb
58
+ - spec/rcov.opts
59
+ - spec/spec.opts
60
+ - spec/spec_helper.rb
61
+ - tasks/input_css_tasks.rake
62
+ - uninstall.rb
63
+ has_rdoc: true
64
+ homepage: https://github.com/botandrose/input_css
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project: input_css
93
+ rubygems_version: 1.6.2
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Adds CSS classes for Rails input tags
97
+ test_files: []
98
+