styled_inputs 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +15 -0
- data/MIT-LICENSE +20 -0
- data/README +46 -0
- data/Rakefile +80 -0
- data/init.rb +1 -0
- data/lib/styled_inputs/extensions/instance_tag.rb +21 -0
- data/lib/styled_inputs/extensions/tag_helper.rb +21 -0
- data/lib/styled_inputs.rb +46 -0
- data/test/styled_inputs_test.rb +129 -0
- data/test/test_helper.rb +7 -0
- metadata +64 -0
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006-2008 Aaron Pfeifer
|
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
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
= styled_inputs
|
2
|
+
|
3
|
+
+styled_inputs+ adds automated styling of input fields with css classes.
|
4
|
+
|
5
|
+
== Resources
|
6
|
+
|
7
|
+
Wiki
|
8
|
+
|
9
|
+
* http://wiki.pluginaweek.org/Styled_inputs
|
10
|
+
|
11
|
+
API
|
12
|
+
|
13
|
+
* http://api.pluginaweek.org/styled_inputs
|
14
|
+
|
15
|
+
Development
|
16
|
+
|
17
|
+
* http://dev.pluginaweek.org/browser/trunk/styled_inputs
|
18
|
+
|
19
|
+
Source
|
20
|
+
|
21
|
+
* http://svn.pluginaweek.org/trunk/styled_inputs
|
22
|
+
|
23
|
+
== Description
|
24
|
+
|
25
|
+
Normally, it is difficult to style inputs without adding classes to them so
|
26
|
+
that you can specify css for each type of input. Since this can become a
|
27
|
+
tedious manual task, styled_inputs automatically adds a classes to each
|
28
|
+
input that is generated either by tag or form helpers. The class that is
|
29
|
+
specified is the type of input being generated.
|
30
|
+
|
31
|
+
== Usage
|
32
|
+
|
33
|
+
=== Tags
|
34
|
+
|
35
|
+
text_field_tag('name') # => <input class="text" id="name" name="name" type="text" />
|
36
|
+
hidden_field_tag('name') # => <input class="hidden" id="name" name="name" type="hidden" />
|
37
|
+
|
38
|
+
=== Form helpers
|
39
|
+
|
40
|
+
text_field(:person, :name) # => <input class="text" id="person_name" name="person[name]" size="30" type="text" />
|
41
|
+
hidden_field(:person, :name) # => <input class="hidden" id="person_name" name="person[name]" type="hidden" />
|
42
|
+
|
43
|
+
== Dependencies
|
44
|
+
|
45
|
+
* Rails 2.0 or later
|
46
|
+
* set_or_append[http://wiki.pluginaweek.org/Set_or_append]
|
data/Rakefile
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rake/contrib/sshpublisher'
|
5
|
+
|
6
|
+
PKG_NAME = 'styled_inputs'
|
7
|
+
PKG_VERSION = '0.0.3'
|
8
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
9
|
+
RUBY_FORGE_PROJECT = 'pluginaweek'
|
10
|
+
|
11
|
+
desc 'Default: run unit tests.'
|
12
|
+
task :default => :test
|
13
|
+
|
14
|
+
desc 'Test the styled_inputs plugin.'
|
15
|
+
Rake::TestTask.new(:test) do |t|
|
16
|
+
t.libs << 'lib'
|
17
|
+
t.pattern = 'test/**/*_test.rb'
|
18
|
+
t.verbose = true
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Generate documentation for the styled_inputs plugin.'
|
22
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
23
|
+
rdoc.rdoc_dir = 'rdoc'
|
24
|
+
rdoc.title = 'StyledInputs'
|
25
|
+
rdoc.template = '../rdoc_template.rb'
|
26
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
27
|
+
rdoc.rdoc_files.include('README')
|
28
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
+
end
|
30
|
+
|
31
|
+
spec = Gem::Specification.new do |s|
|
32
|
+
s.name = PKG_NAME
|
33
|
+
s.version = PKG_VERSION
|
34
|
+
s.platform = Gem::Platform::RUBY
|
35
|
+
s.summary = 'Adds automated styling of input fields with css classes'
|
36
|
+
|
37
|
+
s.files = FileList['{lib,test}/**/*'].to_a + %w(CHANGELOG init.rb MIT-LICENSE Rakefile README)
|
38
|
+
s.require_path = 'lib'
|
39
|
+
s.autorequire = 'styled_inputs'
|
40
|
+
s.has_rdoc = true
|
41
|
+
s.test_files = Dir['test/**/*_test.rb']
|
42
|
+
|
43
|
+
s.author = 'Aaron Pfeifer'
|
44
|
+
s.email = 'aaron@pluginaweek.org'
|
45
|
+
s.homepage = 'http://www.pluginaweek.org'
|
46
|
+
end
|
47
|
+
|
48
|
+
Rake::GemPackageTask.new(spec) do |p|
|
49
|
+
p.gem_spec = spec
|
50
|
+
p.need_tar = true
|
51
|
+
p.need_zip = true
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'Publish the beta gem'
|
55
|
+
task :pgem => [:package] do
|
56
|
+
Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{PKG_FILE_NAME}.gem").upload
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Publish the API documentation'
|
60
|
+
task :pdoc => [:rdoc] do
|
61
|
+
Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{PKG_NAME}", 'rdoc').upload
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Publish the API docs and gem'
|
65
|
+
task :publish => [:pgem, :pdoc, :release]
|
66
|
+
|
67
|
+
desc 'Publish the release files to RubyForge.'
|
68
|
+
task :release => [:gem, :package] do
|
69
|
+
require 'rubyforge'
|
70
|
+
|
71
|
+
ruby_forge = RubyForge.new.configure
|
72
|
+
ruby_forge.login
|
73
|
+
|
74
|
+
%w( gem tgz zip ).each do |ext|
|
75
|
+
file = "pkg/#{PKG_FILE_NAME}.#{ext}"
|
76
|
+
puts "Releasing #{File.basename(file)}..."
|
77
|
+
|
78
|
+
ruby_forge.add_release(RUBY_FORGE_PROJECT, PKG_NAME, PKG_VERSION, file)
|
79
|
+
end
|
80
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'styled_inputs'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PluginAWeek #:nodoc:
|
2
|
+
module StyledInputs
|
3
|
+
module Extensions #:nodoc:
|
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
|
+
def tag_with_styled_inputs(name, options) #:nodoc:
|
12
|
+
tag_without_styled_inputs(name, styled_input(name, options))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ActionView::Helpers::InstanceTag.class_eval do
|
20
|
+
include PluginAWeek::StyledInputs::Extensions::InstanceTag
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PluginAWeek #:nodoc:
|
2
|
+
module StyledInputs
|
3
|
+
module Extensions #:nodoc:
|
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
|
+
def tag_with_styled_inputs(name, options = nil, open = false) #:nodoc:
|
12
|
+
tag_without_styled_inputs(name, styled_input(name, options), open)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ActionView::Helpers::TagHelper.class_eval do
|
20
|
+
include PluginAWeek::StyledInputs::Extensions::TagHelper
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'styled_inputs/extensions/tag_helper'
|
2
|
+
require 'styled_inputs/extensions/instance_tag'
|
3
|
+
|
4
|
+
module PluginAWeek #:nodoc:
|
5
|
+
# Automatically adds css classes to input tags so that fields can be
|
6
|
+
# easily styled.
|
7
|
+
#
|
8
|
+
# Tag examples:
|
9
|
+
#
|
10
|
+
# text_field_tag('name') # => <input class="text" id="name" name="name" type="text" />
|
11
|
+
# hidden_field_tag('name') # => <input class="hidden" id="name" name="name" type="hidden" />
|
12
|
+
# radio_button_tag('agree', 1) # => <input class="radio" id="agree_1" name="agree" type="radio" value="1" />
|
13
|
+
#
|
14
|
+
# Form helper examples:
|
15
|
+
#
|
16
|
+
# text_field(:person, :name) # => <input class="text" id="person_name" name="person[name]" size="30" type="text" />
|
17
|
+
# hidden_field(:person, :name) # => <input class="hidden" id="person_name" name="person[name]" type="hidden" />
|
18
|
+
# radio_button(:person, :agree, 1) # => <input class="radio" id="person_agree_1" name="person[agree]" type="radio" value="1" />
|
19
|
+
#
|
20
|
+
# If you specify additional classes when creating a tag, the automated css
|
21
|
+
# classes will be prepended to the current ones. For example,
|
22
|
+
#
|
23
|
+
# text_field_tag('name', :class => 'selected') # => <input class="text selected" id="name" name="name" type="text" />
|
24
|
+
# text_field_tag('name', :class => 'selected shadow') # => <input class="text selected shadow" id="name" name="name" type="text" />
|
25
|
+
module StyledInputs
|
26
|
+
# Appends the input type to the value currently stored in the html options
|
27
|
+
# for the tag.
|
28
|
+
def styled_input(name, options)
|
29
|
+
options = options.stringify_keys
|
30
|
+
|
31
|
+
if name.to_s == 'input' && options.include?('type')
|
32
|
+
options['class'] = (options['class'].to_s + " #{options['type']}").strip
|
33
|
+
end
|
34
|
+
|
35
|
+
options
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
ActionController::Base.class_eval do
|
41
|
+
helper PluginAWeek::StyledInputs
|
42
|
+
end
|
43
|
+
|
44
|
+
ActionView::Helpers::InstanceTag.class_eval do
|
45
|
+
include PluginAWeek::StyledInputs
|
46
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class StyledInputsTest < Test::Unit::TestCase
|
4
|
+
include PluginAWeek::StyledInputs
|
5
|
+
include ActionView::Helpers::TagHelper
|
6
|
+
|
7
|
+
def test_should_not_style_input_if_tag_is_not_input
|
8
|
+
expected = {}
|
9
|
+
assert_equal expected, styled_input('td', expected)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_not_style_input_if_correct_type_but_tag_is_not_input
|
13
|
+
expected = {'type' => 'text'}
|
14
|
+
assert_equal expected, styled_input('td', expected)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_style_input_if_tag_is_input
|
18
|
+
expected = {'type' => 'text', 'class' => 'text'}
|
19
|
+
assert_equal expected, styled_input('input', {'type' => 'text'})
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_style_input_if_tag_is_symbolic_input
|
23
|
+
expected = {'type' => 'text', 'class' => 'text'}
|
24
|
+
assert_equal expected, styled_input(:input, {'type' => 'text'})
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_not_style_input_if_tag_is_input_but_type_not_specified
|
28
|
+
expected = {}
|
29
|
+
assert_equal expected, styled_input('input', expected)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_append_style_if_class_is_already_populated
|
33
|
+
expected = {'type' => 'text', 'class' => 'selected text'}
|
34
|
+
assert_equal expected, styled_input('input', {'type' => 'text', 'class' => 'selected'})
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_style_general_tag_builder
|
38
|
+
assert_equal '<input class="text" type="text" />', tag('input', {'type' => 'text'})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class FormTagHelperTest < Test::Unit::TestCase
|
43
|
+
include PluginAWeek::StyledInputs
|
44
|
+
include ActionView::Helpers::TagHelper
|
45
|
+
include ActionView::Helpers::FormTagHelper
|
46
|
+
include ActionView::Helpers::FormHelper
|
47
|
+
|
48
|
+
def test_should_style_text_field_tag
|
49
|
+
assert_equal '<input class="text" id="name" name="name" type="text" />', text_field_tag('name')
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_style_hidden_field_tag
|
53
|
+
assert_equal '<input class="hidden" id="name" name="name" type="hidden" />', hidden_field_tag('name')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_style_file_field_tag
|
57
|
+
assert_equal '<input class="file" id="picture" name="picture" type="file" />', file_field_tag('picture')
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_style_password_field_tag
|
61
|
+
assert_equal '<input class="password" id="secret" name="secret" type="password" />', password_field_tag('secret')
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_should_style_check_box_tag
|
65
|
+
assert_equal '<input class="checkbox" id="agree" name="agree" type="checkbox" value="1" />', check_box_tag('agree')
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_should_style_radio_button_tag
|
69
|
+
assert_equal '<input class="radio" id="agree_1" name="agree" type="radio" value="1" />', radio_button_tag('agree', 1)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_should_style_submit_tag
|
73
|
+
assert_equal '<input class="submit" name="commit" type="submit" value="Submit" />', submit_tag('Submit')
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_should_style_image_submit_tag
|
77
|
+
assert_equal '<input class="image" src="button.png" type="image" />', image_submit_tag('button.png')
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
def path_to_image(source)
|
82
|
+
source
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class FormHelperTest < Test::Unit::TestCase
|
87
|
+
class Person
|
88
|
+
attr_accessor :name,
|
89
|
+
:agree,
|
90
|
+
:picture,
|
91
|
+
:secret
|
92
|
+
end
|
93
|
+
|
94
|
+
include PluginAWeek::StyledInputs
|
95
|
+
include ActionView::Helpers::TagHelper
|
96
|
+
include ActionView::Helpers::FormTagHelper
|
97
|
+
include ActionView::Helpers::FormHelper
|
98
|
+
|
99
|
+
def setup
|
100
|
+
@person = Person.new
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_should_style_text_field
|
104
|
+
assert_equal '<input class="text" id="person_name" name="person[name]" size="30" type="text" />', text_field(:person, :name)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_should_style_password_field
|
108
|
+
assert_equal '<input class="password" id="person_secret" name="person[secret]" size="30" type="password" />', password_field(:person, :secret)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_should_style_hidden_field
|
112
|
+
assert_equal '<input class="hidden" id="person_name" name="person[name]" type="hidden" />', hidden_field(:person, :name)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_should_style_file_field
|
116
|
+
assert_equal '<input class="file" id="person_picture" name="person[picture]" size="30" type="file" />', file_field(:person, :picture)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_should_style_check_box
|
120
|
+
expected =
|
121
|
+
'<input class="checkbox" id="person_agree" name="person[agree]" type="checkbox" value="1" />' +
|
122
|
+
'<input class="hidden" name="person[agree]" type="hidden" value="0" />'
|
123
|
+
assert_equal expected, check_box(:person, :agree)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_should_style_radio_button
|
127
|
+
assert_equal '<input class="radio" id="person_agree_1" name="person[agree]" type="radio" value="1" />', radio_button(:person, :agree, 1)
|
128
|
+
end
|
129
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: styled_inputs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Pfeifer
|
8
|
+
autorequire: styled_inputs
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-01 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: aaron@pluginaweek.org
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/styled_inputs.rb
|
26
|
+
- lib/styled_inputs
|
27
|
+
- lib/styled_inputs/extensions
|
28
|
+
- lib/styled_inputs/extensions/tag_helper.rb
|
29
|
+
- lib/styled_inputs/extensions/instance_tag.rb
|
30
|
+
- test/styled_inputs_test.rb
|
31
|
+
- test/test_helper.rb
|
32
|
+
- CHANGELOG
|
33
|
+
- init.rb
|
34
|
+
- MIT-LICENSE
|
35
|
+
- Rakefile
|
36
|
+
- README
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://www.pluginaweek.org
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.1.1
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: Adds automated styling of input fields with css classes
|
63
|
+
test_files:
|
64
|
+
- test/styled_inputs_test.rb
|