better_form 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Nicholas Firth-McCoy
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.md ADDED
File without changes
@@ -0,0 +1,43 @@
1
+ module BetterForm
2
+ class Builder < ActionView::Helpers::FormBuilder
3
+ include ActionView::Helpers::UrlHelper
4
+
5
+ helpers = field_helpers - %w(label hidden_field fields_for)
6
+ helpers.each do |name|
7
+ define_method(name) do |field_name, *args|
8
+ options = args.last.is_a?(Hash) ? args.pop : {}
9
+ label = options.delete(:label)
10
+ if label == false
11
+ super(field_name, *args)
12
+ elsif label
13
+ generate_label(field_name, label) + super(field_name, *args)
14
+ elsif @template.label_all? == false
15
+ super(field_name, *args)
16
+ else
17
+ generate_label(field_name, label) + super(field_name, *args)
18
+ end
19
+ end
20
+ end
21
+
22
+ def submit(options = {})
23
+ value = options.delete(:value)
24
+ cancel_url = options.delete(:cancel)
25
+ if cancel_url
26
+ super(value, options) + 'or' + link_to('Cancel', cancel_url)
27
+ else
28
+ super(value, options)
29
+ end
30
+ end
31
+
32
+ private
33
+ def generate_label(method, label)
34
+ if label
35
+ label_text = label
36
+ else
37
+ label_text = method.to_s.gsub(/_/, ' ').capitalize
38
+ end
39
+
40
+ label(method, label_text)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module BetterForm
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,13 @@
1
+ module BetterForm
2
+ module ViewHelper
3
+ def better_form_for(record_or_name_or_array, *args, &proc)
4
+ options = args.extract_options!.reverse_merge(:builder => BetterForm::Builder)
5
+ @label_all = options[:label]
6
+ form_for(record_or_name_or_array, *(args << options), &proc)
7
+ end
8
+
9
+ def label_all?
10
+ @label_all
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ require "better_form/view_helper"
2
+ require "better_form/builder"
3
+
4
+ ActiveSupport.on_load(:action_view) do
5
+ include BetterForm::ViewHelper
6
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: better_form
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Nicholas Firth-McCoy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-10 00:00:00 +11:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email:
19
+ - nicholas@2suggestions.com.au
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - lib/better_form/version.rb
28
+ - lib/better_form/view_helper.rb
29
+ - lib/better_form/builder.rb
30
+ - lib/better_form.rb
31
+ - LICENSE
32
+ - README.md
33
+ has_rdoc: true
34
+ homepage: http://github.com/2suggestions/better_form
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.3.6
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.5.0
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: A Better Rails 3 FormBuilder
61
+ test_files: []
62
+