pluginaweek-styled_inputs 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 ADDED
@@ -0,0 +1,32 @@
1
+ == master
2
+
3
+ == 0.1.1 / 2008-12-28
4
+
5
+ * Don't style hidden inputs
6
+ * Fix input styling not always being included on classes directly including ActionView::Helpers::TagHelper
7
+
8
+ == 0.1.0 / 2008-12-14
9
+
10
+ * Remove the PluginAWeek namespace
11
+ * Update tests to use ActionView::TestCase
12
+
13
+ == 0.0.5 / 2008-06-22
14
+
15
+ * Remove log files from gems
16
+
17
+ == 0.0.4 / 2008-06-03
18
+
19
+ * Add support for Rails 2.0+
20
+
21
+ == 0.0.3 / 2008-06-01
22
+
23
+ * Remove dependency on set_or_append
24
+
25
+ == 0.0.2 / 2008-05-05
26
+
27
+ * Updated documentation
28
+
29
+ == 0.0.1 / 2007-08-17
30
+
31
+ * Add documentation
32
+ * Convert dos newlines to unix newlines
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006-2009 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.rdoc ADDED
@@ -0,0 +1,54 @@
1
+ = styled_inputs
2
+
3
+ +styled_inputs+ adds automated styling of input fields with css classes.
4
+
5
+ == Resources
6
+
7
+ API
8
+
9
+ * http://api.pluginaweek.org/styled_inputs
10
+
11
+ Bugs
12
+
13
+ * http://pluginaweek.lighthouseapp.com/projects/13289-styled_inputs
14
+
15
+ Development
16
+
17
+ * http://github.com/pluginaweek/styled_inputs
18
+
19
+ Source
20
+
21
+ * git://github.com/pluginaweek/styled_inputs.git
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
+ == Testing
44
+
45
+ Before you can run any tests, the following gem must be installed:
46
+ * plugin_test_helper[http://github.com/pluginaweek/plugin_test_helper]
47
+
48
+ To run against a specific version of Rails:
49
+
50
+ rake test RAILS_FRAMEWORK_ROOT=/path/to/rails
51
+
52
+ == Dependencies
53
+
54
+ * Rails 2.0 or later
data/Rakefile ADDED
@@ -0,0 +1,96 @@
1
+ require 'rake/testtask'
2
+ require 'rake/rdoctask'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/contrib/sshpublisher'
5
+
6
+ spec = Gem::Specification.new do |s|
7
+ s.name = 'styled_inputs'
8
+ s.version = '0.1.1'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = 'Adds automated styling of input fields with css classes in Rails'
11
+ s.description = s.summary
12
+
13
+ s.files = FileList['{lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
14
+ s.require_path = 'lib'
15
+ s.has_rdoc = true
16
+ s.test_files = Dir['test/**/*_test.rb']
17
+
18
+ s.author = 'Aaron Pfeifer'
19
+ s.email = 'aaron@pluginaweek.org'
20
+ s.homepage = 'http://www.pluginaweek.org'
21
+ s.rubyforge_project = 'pluginaweek'
22
+ end
23
+
24
+ desc 'Default: run all tests.'
25
+ task :default => :test
26
+
27
+ desc "Test the #{spec.name} plugin."
28
+ Rake::TestTask.new(:test) do |t|
29
+ t.libs << 'lib'
30
+ t.test_files = spec.test_files
31
+ t.verbose = true
32
+ end
33
+
34
+ begin
35
+ require 'rcov/rcovtask'
36
+ namespace :test do
37
+ desc "Test the #{spec.name} plugin with Rcov."
38
+ Rcov::RcovTask.new(:rcov) do |t|
39
+ t.libs << 'lib'
40
+ t.test_files = spec.test_files
41
+ t.rcov_opts << '--exclude="^(?!lib/)"'
42
+ t.verbose = true
43
+ end
44
+ end
45
+ rescue LoadError
46
+ end
47
+
48
+ desc "Generate documentation for the #{spec.name} plugin."
49
+ Rake::RDocTask.new(:rdoc) do |rdoc|
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = spec.name
52
+ rdoc.template = '../rdoc_template.rb'
53
+ rdoc.options << '--line-numbers' << '--inline-source'
54
+ rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG.rdoc', 'LICENSE', 'lib/**/*.rb')
55
+ end
56
+
57
+ desc 'Generate a gemspec file.'
58
+ task :gemspec do
59
+ File.open("#{spec.name}.gemspec", 'w') do |f|
60
+ f.write spec.to_ruby
61
+ end
62
+ end
63
+
64
+ Rake::GemPackageTask.new(spec) do |p|
65
+ p.gem_spec = spec
66
+ p.need_tar = true
67
+ p.need_zip = true
68
+ end
69
+
70
+ desc 'Publish the beta gem.'
71
+ task :pgem => [:package] do
72
+ Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{spec.name}-#{spec.version}.gem").upload
73
+ end
74
+
75
+ desc 'Publish the API documentation.'
76
+ task :pdoc => [:rdoc] do
77
+ Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{spec.name}", 'rdoc').upload
78
+ end
79
+
80
+ desc 'Publish the API docs and gem'
81
+ task :publish => [:pgem, :pdoc, :release]
82
+
83
+ desc 'Publish the release files to RubyForge.'
84
+ task :release => [:gem, :package] do
85
+ require 'rubyforge'
86
+
87
+ ruby_forge = RubyForge.new.configure
88
+ ruby_forge.login
89
+
90
+ %w(gem tgz zip).each do |ext|
91
+ file = "pkg/#{spec.name}-#{spec.version}.#{ext}"
92
+ puts "Releasing #{File.basename(file)}..."
93
+
94
+ ruby_forge.add_release(spec.rubyforge_project, spec.name, spec.version, file)
95
+ end
96
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'styled_inputs'
@@ -0,0 +1,27 @@
1
+ require 'styled_inputs/extensions/tag_helper'
2
+ require 'styled_inputs/extensions/instance_tag'
3
+
4
+ # Automatically adds css classes to input tags so that fields can be
5
+ # easily styled.
6
+ #
7
+ # == Tag examples
8
+ #
9
+ # text_field_tag('name') # => <input class="text" id="name" name="name" type="text" />
10
+ # hidden_field_tag('name') # => <input class="hidden" id="name" name="name" type="hidden" />
11
+ # radio_button_tag('agree', 1) # => <input class="radio" id="agree_1" name="agree" type="radio" value="1" />
12
+ #
13
+ # == Form helper examples
14
+ #
15
+ # text_field(:person, :name) # => <input class="text" id="person_name" name="person[name]" size="30" type="text" />
16
+ # hidden_field(:person, :name) # => <input class="hidden" id="person_name" name="person[name]" type="hidden" />
17
+ # radio_button(:person, :agree, 1) # => <input class="radio" id="person_agree_1" name="person[agree]" type="radio" value="1" />
18
+ #
19
+ # == Merging options
20
+ #
21
+ # If you specify additional classes when creating a tag, the automated css
22
+ # classes will be prepended to the current ones. For example,
23
+ #
24
+ # text_field_tag('name', :class => 'selected') # => <input class="text selected" id="name" name="name" type="text" />
25
+ # text_field_tag('name', :class => 'selected shadow') # => <input class="text selected shadow" id="name" name="name" type="text" />
26
+ module StyledInputs
27
+ end
@@ -0,0 +1,6 @@
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.
4
+ ActionView::Helpers::InstanceTag.class_eval do
5
+ alias_method_chain :tag, :styled_inputs
6
+ end
@@ -0,0 +1,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.
4
+ ActionView::Helpers::TagHelper.class_eval do
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
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
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class FormHelperTest < ActionView::TestCase
4
+ class Person
5
+ attr_accessor :name,
6
+ :agree,
7
+ :picture,
8
+ :secret
9
+ end
10
+
11
+ def setup
12
+ @person = Person.new
13
+ end
14
+
15
+ def test_should_style_text_field
16
+ assert_equal '<input class="text" id="person_name" name="person[name]" size="30" type="text" />', text_field(:person, :name)
17
+ end
18
+
19
+ def test_should_style_password_field
20
+ assert_equal '<input class="password" id="person_secret" name="person[secret]" size="30" type="password" />', password_field(:person, :secret)
21
+ end
22
+
23
+ def test_should_not_style_hidden_field
24
+ assert_equal '<input id="person_name" name="person[name]" type="hidden" />', hidden_field(:person, :name)
25
+ end
26
+
27
+ def test_should_style_file_field
28
+ assert_equal '<input class="file" id="person_picture" name="person[picture]" size="30" type="file" />', file_field(:person, :picture)
29
+ end
30
+
31
+ def test_should_style_check_box
32
+ expected =
33
+ '<input name="person[agree]" type="hidden" value="0" />' +
34
+ '<input class="checkbox" id="person_agree" name="person[agree]" type="checkbox" value="1" />'
35
+ assert_equal expected, check_box(:person, :agree)
36
+ end
37
+
38
+ def test_should_style_radio_button
39
+ assert_equal '<input class="radio" id="person_agree_1" name="person[agree]" type="radio" value="1" />', radio_button(:person, :agree, 1)
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class FormTagHelperTest < ActionView::TestCase
4
+ def test_should_style_text_field_tag
5
+ assert_equal '<input class="text" id="name" name="name" type="text" />', text_field_tag('name')
6
+ end
7
+
8
+ def test_should_not_style_hidden_field_tag
9
+ assert_equal '<input id="name" name="name" type="hidden" />', hidden_field_tag('name')
10
+ end
11
+
12
+ def test_should_style_file_field_tag
13
+ assert_equal '<input class="file" id="picture" name="picture" type="file" />', file_field_tag('picture')
14
+ end
15
+
16
+ def test_should_style_password_field_tag
17
+ assert_equal '<input class="password" id="secret" name="secret" type="password" />', password_field_tag('secret')
18
+ end
19
+
20
+ def test_should_style_check_box_tag
21
+ assert_equal '<input class="checkbox" id="agree" name="agree" type="checkbox" value="1" />', check_box_tag('agree')
22
+ end
23
+
24
+ def test_should_style_radio_button_tag
25
+ assert_equal '<input class="radio" id="agree_1" name="agree" type="radio" value="1" />', radio_button_tag('agree', 1)
26
+ end
27
+
28
+ def test_should_style_submit_tag
29
+ assert_equal '<input class="submit" name="commit" type="submit" value="Submit" />', submit_tag('Submit')
30
+ end
31
+
32
+ def test_should_style_image_submit_tag
33
+ assert_equal '<input class="image" src="button.png" type="image" />', image_submit_tag('button.png')
34
+ end
35
+
36
+ private
37
+ def path_to_image(source)
38
+ source
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class StyledInputsTest < ActionView::TestCase
4
+ def test_should_not_style_input_if_tag_is_not_input
5
+ expected = {}
6
+ assert_equal expected, styled_input('td', expected)
7
+ end
8
+
9
+ def test_should_not_style_input_if_correct_type_but_tag_is_not_input
10
+ expected = {'type' => 'text'}
11
+ assert_equal expected, styled_input('td', expected)
12
+ end
13
+
14
+ def test_should_style_input_if_tag_is_input
15
+ expected = {'type' => 'text', 'class' => 'text'}
16
+ assert_equal expected, styled_input('input', {'type' => 'text'})
17
+ end
18
+
19
+ def test_should_style_input_if_tag_is_symbolic_input
20
+ expected = {'type' => 'text', 'class' => 'text'}
21
+ assert_equal expected, styled_input(:input, {'type' => 'text'})
22
+ end
23
+
24
+ def test_should_not_style_input_if_tag_is_input_but_type_not_specified
25
+ expected = {}
26
+ assert_equal expected, styled_input('input', expected)
27
+ end
28
+
29
+ def test_should_append_style_if_class_is_already_populated
30
+ expected = {'type' => 'text', 'class' => 'selected text'}
31
+ assert_equal expected, styled_input('input', {'type' => 'text', 'class' => 'selected'})
32
+ end
33
+
34
+ def test_should_style_general_tag_builder
35
+ assert_equal '<input class="text" type="text" />', tag('input', {'type' => 'text'})
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class TagHelperTest < ActionView::TestCase
4
+ def test_should_allow_no_options_to_be_specified
5
+ assert_equal '<br />', tag('br')
6
+ end
7
+
8
+ def test_should_allow_options_to_be_specified
9
+ assert_equal '<input class="text" disabled="disabled" type="text" />', tag('input', {:type => 'text', :disabled => true})
10
+ end
11
+
12
+ def test_should_allow_open_to_be_specified
13
+ assert_equal '<br>', tag('br', nil, true)
14
+ end
15
+
16
+ def test_should_allow_escape_to_be_specified
17
+ assert_equal '<img src="open &amp; shut.png" />', tag('img', {:src => 'open &amp; shut.png'}, false, false)
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ # Load the plugin testing framework
2
+ $:.unshift("#{File.dirname(__FILE__)}/../../plugin_test_helper/lib")
3
+ require 'rubygems'
4
+ require 'plugin_test_helper'
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pluginaweek-styled_inputs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Pfeifer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Adds automated styling of input fields with css classes in Rails
17
+ email: aaron@pluginaweek.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/styled_inputs
26
+ - lib/styled_inputs/extensions
27
+ - lib/styled_inputs/extensions/tag_helper.rb
28
+ - lib/styled_inputs/extensions/instance_tag.rb
29
+ - lib/styled_inputs.rb
30
+ - test/helpers
31
+ - test/helpers/styled_inputs_test.rb
32
+ - test/helpers/date_helper_test.rb
33
+ - test/helpers/form_helper_test.rb
34
+ - test/helpers/tag_helper_test.rb
35
+ - test/helpers/form_tag_helper_test.rb
36
+ - test/test_helper.rb
37
+ - CHANGELOG.rdoc
38
+ - init.rb
39
+ - LICENSE
40
+ - Rakefile
41
+ - README.rdoc
42
+ has_rdoc: true
43
+ homepage: http://www.pluginaweek.org
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project: pluginaweek
64
+ rubygems_version: 1.2.0
65
+ signing_key:
66
+ specification_version: 2
67
+ summary: Adds automated styling of input fields with css classes in Rails
68
+ test_files:
69
+ - test/helpers/styled_inputs_test.rb
70
+ - test/helpers/date_helper_test.rb
71
+ - test/helpers/form_helper_test.rb
72
+ - test/helpers/tag_helper_test.rb
73
+ - test/helpers/form_tag_helper_test.rb