generic_form_builder 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.
@@ -0,0 +1,12 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ s.name = "generic_form_builder"
4
+ s.version = '0.1.0'
5
+ s.platform = Gem::Platform::RUBY
6
+ s.authors = ["Elliot Crosby-McCullough", "George Brocklehurst", "Elise Huard", "Tom Stuart"]
7
+ s.email = ["elliot.cm@gmail.com"]
8
+ s.homepage = ""
9
+ s.summary = "Generic Rails 3 form builder"
10
+ s.files = `git ls-files`.split("\n")
11
+ s.require_paths = ["lib"]
12
+ end
@@ -0,0 +1,50 @@
1
+ class GenericFormBuilder < ActionView::Helpers::FormBuilder
2
+ include ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
3
+
4
+ %w[
5
+ text_field
6
+ password_field
7
+ text_area
8
+ email_field
9
+ file_field
10
+ ].each do |method|
11
+ define_method(method.to_sym) do |field, *args|
12
+ options, *args = args
13
+ options ||= {:label => field.to_s.humanize}
14
+ note = content_tag(:span, options[:note], :class => 'note') if options[:note]
15
+ button = ' '+content_tag(:button, content_tag(:span, options[:button])) if options[:button]
16
+ errors = ' '+@object.errors[field].join(' and ') if @object.errors[field].any?
17
+ content_tag(:p, label(field, "#{options[:label]}#{errors}") + note + super(field, *args) + button.try(:html_safe))
18
+ end
19
+ end
20
+
21
+ def collection_select(field, collection, value_method, name_method, options = {})
22
+ label_text = options[:label] || field.to_s.humanize
23
+ content_tag(:p, label(field, "#{label_text} #{errors_text(field)}") + super(field, collection, value_method, name_method))
24
+ end
25
+
26
+ def check_box(field, options = {})
27
+ label_text = options[:label] || field.to_s.humanize
28
+ content_tag(:p, label(field, super + " #{label_text} #{errors_text(field)}", :class => 'checkbox'))
29
+ end
30
+
31
+ def radio_button(field, value, options = {})
32
+ label_text = options.delete(:label) || field.to_s.humanize
33
+ content_tag(:p, label(field, super + " #{label_text} #{errors_text(field)}"))
34
+ end
35
+
36
+ def buttons(options = {})
37
+ buttons = content_tag(:button, content_tag(:span, options[:submit_text] || 'Save'), :type => 'submit')
38
+ buttons << link_to('Cancel', options[:cancel_link], :class => 'cancel button') if options[:cancel_link]
39
+
40
+ content_tag(:div, buttons, :class => 'actions')
41
+ end
42
+
43
+ protected
44
+
45
+ def errors_text(field)
46
+ return '' if @object.errors[field].empty?
47
+ @object.errors[field]
48
+ end
49
+
50
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: generic_form_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Elliot Crosby-McCullough
9
+ - George Brocklehurst
10
+ - Elise Huard
11
+ - Tom Stuart
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2012-01-10 00:00:00.000000000Z
16
+ dependencies: []
17
+ description:
18
+ email:
19
+ - elliot.cm@gmail.com
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - generic_form_builder.gemspec
25
+ - lib/generic_form_builder.rb
26
+ homepage: ''
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.10
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Generic Rails 3 form builder
50
+ test_files: []