generic_form_for 0.0.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.
Files changed (150) hide show
  1. data/.document +5 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +123 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.textile +217 -0
  8. data/Rakefile +52 -0
  9. data/VERSION +1 -0
  10. data/generic_form_for.gemspec +232 -0
  11. data/generic_form_for.tmproj +166 -0
  12. data/lib/generators/generic_form_for/form_builder/form_builder_generator.rb +16 -0
  13. data/lib/generators/generic_form_for/form_builder/templates/form_builder.erb +37 -0
  14. data/lib/generators/generic_form_for/form_builder/templates/helper.erb +15 -0
  15. data/lib/generators/generic_form_for/install/install_generator.rb +20 -0
  16. data/lib/generators/generic_form_for/install/templates/_form.html.erb +11 -0
  17. data/lib/generators/generic_form_for/install/templates/_form.html.haml +8 -0
  18. data/lib/generators/generic_form_for/install/templates/form_for.en.yml +11 -0
  19. data/lib/generators/generic_form_for/install/templates/initializer.rb +5 -0
  20. data/lib/generic_form_for.rb +22 -0
  21. data/lib/generic_form_for/actions.rb +10 -0
  22. data/lib/generic_form_for/actions/base.rb +63 -0
  23. data/lib/generic_form_for/actions/base/icon.rb +24 -0
  24. data/lib/generic_form_for/actions/button_action.rb +14 -0
  25. data/lib/generic_form_for/actions/input_action.rb +11 -0
  26. data/lib/generic_form_for/engine.rb +11 -0
  27. data/lib/generic_form_for/form_builder.rb +111 -0
  28. data/lib/generic_form_for/helpers.rb +10 -0
  29. data/lib/generic_form_for/helpers/action_helper.rb +52 -0
  30. data/lib/generic_form_for/helpers/actions_helper.rb +35 -0
  31. data/lib/generic_form_for/helpers/fieldset_helper.rb +48 -0
  32. data/lib/generic_form_for/helpers/form_helper.rb +64 -0
  33. data/lib/generic_form_for/helpers/input_helper.rb +77 -0
  34. data/lib/generic_form_for/i18n.rb +44 -0
  35. data/lib/generic_form_for/inputs.rb +22 -0
  36. data/lib/generic_form_for/inputs/base.rb +98 -0
  37. data/lib/generic_form_for/inputs/base/error_message.rb +30 -0
  38. data/lib/generic_form_for/inputs/base/hint.rb +28 -0
  39. data/lib/generic_form_for/inputs/base/label.rb +42 -0
  40. data/lib/generic_form_for/inputs/base/number.rb +18 -0
  41. data/lib/generic_form_for/inputs/base/placeholder.rb +20 -0
  42. data/lib/generic_form_for/inputs/base/string.rb +17 -0
  43. data/lib/generic_form_for/inputs/base/validations.rb +42 -0
  44. data/lib/generic_form_for/inputs/boolean_input.rb +35 -0
  45. data/lib/generic_form_for/inputs/email_input.rb +19 -0
  46. data/lib/generic_form_for/inputs/file_input.rb +13 -0
  47. data/lib/generic_form_for/inputs/hidden_input.rb +23 -0
  48. data/lib/generic_form_for/inputs/number_input.rb +20 -0
  49. data/lib/generic_form_for/inputs/password_input.rb +13 -0
  50. data/lib/generic_form_for/inputs/phone_input.rb +19 -0
  51. data/lib/generic_form_for/inputs/range_input.rb +19 -0
  52. data/lib/generic_form_for/inputs/search_input.rb +19 -0
  53. data/lib/generic_form_for/inputs/select_input.rb +32 -0
  54. data/lib/generic_form_for/inputs/string_input.rb +13 -0
  55. data/lib/generic_form_for/inputs/text_input.rb +20 -0
  56. data/lib/generic_form_for/inputs/url_input.rb +19 -0
  57. data/sample_app/.gitignore +15 -0
  58. data/sample_app/Gemfile +15 -0
  59. data/sample_app/Gemfile.lock +130 -0
  60. data/sample_app/README.rdoc +261 -0
  61. data/sample_app/Rakefile +7 -0
  62. data/sample_app/app/assets/images/rails.png +0 -0
  63. data/sample_app/app/assets/javascripts/application.js +14 -0
  64. data/sample_app/app/assets/javascripts/posts.js.coffee +3 -0
  65. data/sample_app/app/assets/javascripts/samples.js.coffee +3 -0
  66. data/sample_app/app/assets/stylesheets/application.css +14 -0
  67. data/sample_app/app/assets/stylesheets/posts.css.scss +3 -0
  68. data/sample_app/app/assets/stylesheets/samples.css.scss +3 -0
  69. data/sample_app/app/assets/stylesheets/scaffolds.css.scss +56 -0
  70. data/sample_app/app/controllers/application_controller.rb +3 -0
  71. data/sample_app/app/controllers/samples_controller.rb +83 -0
  72. data/sample_app/app/form_builders/sample_form_builder.rb +17 -0
  73. data/sample_app/app/helpers/application_helper.rb +2 -0
  74. data/sample_app/app/helpers/sample_form_builder_helper.rb +15 -0
  75. data/sample_app/app/helpers/samples_helper.rb +2 -0
  76. data/sample_app/app/mailers/.gitkeep +0 -0
  77. data/sample_app/app/models/.gitkeep +0 -0
  78. data/sample_app/app/models/sample.rb +29 -0
  79. data/sample_app/app/views/layouts/application.html.erb +16 -0
  80. data/sample_app/app/views/samples/_form.html.erb +49 -0
  81. data/sample_app/app/views/samples/edit.html.erb +6 -0
  82. data/sample_app/app/views/samples/index.html.erb +21 -0
  83. data/sample_app/app/views/samples/new.html.erb +5 -0
  84. data/sample_app/app/views/samples/show.html.erb +5 -0
  85. data/sample_app/config.ru +4 -0
  86. data/sample_app/config/application.rb +65 -0
  87. data/sample_app/config/boot.rb +6 -0
  88. data/sample_app/config/database.yml +25 -0
  89. data/sample_app/config/environment.rb +5 -0
  90. data/sample_app/config/environments/development.rb +37 -0
  91. data/sample_app/config/environments/production.rb +67 -0
  92. data/sample_app/config/environments/test.rb +37 -0
  93. data/sample_app/config/initializers/backtrace_silencers.rb +7 -0
  94. data/sample_app/config/initializers/generic_form_for.rb +5 -0
  95. data/sample_app/config/initializers/inflections.rb +15 -0
  96. data/sample_app/config/initializers/mime_types.rb +5 -0
  97. data/sample_app/config/initializers/secret_token.rb +7 -0
  98. data/sample_app/config/initializers/session_store.rb +8 -0
  99. data/sample_app/config/initializers/wrap_parameters.rb +14 -0
  100. data/sample_app/config/locales/en.yml +22 -0
  101. data/sample_app/config/locales/form_for.en.yml +13 -0
  102. data/sample_app/config/routes.rb +61 -0
  103. data/sample_app/db/migrate/20120203082117_create_samples.rb +22 -0
  104. data/sample_app/db/schema.rb +36 -0
  105. data/sample_app/db/seeds.rb +7 -0
  106. data/sample_app/lib/assets/.gitkeep +0 -0
  107. data/sample_app/lib/tasks/.gitkeep +0 -0
  108. data/sample_app/lib/templates/erb/scaffold/_form.html.erb +11 -0
  109. data/sample_app/log/.gitkeep +0 -0
  110. data/sample_app/public/404.html +26 -0
  111. data/sample_app/public/422.html +26 -0
  112. data/sample_app/public/500.html +25 -0
  113. data/sample_app/public/favicon.ico +0 -0
  114. data/sample_app/public/robots.txt +5 -0
  115. data/sample_app/script/rails +6 -0
  116. data/sample_app/vendor/assets/javascripts/.gitkeep +0 -0
  117. data/sample_app/vendor/assets/stylesheets/.gitkeep +0 -0
  118. data/sample_app/vendor/plugins/.gitkeep +0 -0
  119. data/spec/actions/base/icon_spec.rb +38 -0
  120. data/spec/actions/button_action_spec.rb +43 -0
  121. data/spec/actions/input_action_spec.rb +66 -0
  122. data/spec/helpers/action_helper_spec.rb +32 -0
  123. data/spec/helpers/actions_helper_spec.rb +60 -0
  124. data/spec/helpers/fieldset_helper_spec.rb +83 -0
  125. data/spec/helpers/form_helper_spec.rb +101 -0
  126. data/spec/helpers/input_helper_spec.rb +66 -0
  127. data/spec/i18n_spec.rb +46 -0
  128. data/spec/inputs/base/error_message_spec.rb +86 -0
  129. data/spec/inputs/base/hint_spec.rb +77 -0
  130. data/spec/inputs/base/label_spec.rb +99 -0
  131. data/spec/inputs/base/number_spec.rb +32 -0
  132. data/spec/inputs/base/placeholder_spec.rb +32 -0
  133. data/spec/inputs/base/string_spec.rb +25 -0
  134. data/spec/inputs/base/validations_spec.rb +53 -0
  135. data/spec/inputs/base_spec.rb +69 -0
  136. data/spec/inputs/boolean_input_spec.rb +95 -0
  137. data/spec/inputs/email_input_spec.rb +30 -0
  138. data/spec/inputs/file_input_spec.rb +30 -0
  139. data/spec/inputs/hidden_input_spec.rb +30 -0
  140. data/spec/inputs/number_input_spec.rb +37 -0
  141. data/spec/inputs/password_input_spec.rb +30 -0
  142. data/spec/inputs/phone_input_spec.rb +30 -0
  143. data/spec/inputs/range_input_spec.rb +37 -0
  144. data/spec/inputs/search_input_spec.rb +30 -0
  145. data/spec/inputs/select_input_spec.rb +51 -0
  146. data/spec/inputs/string_input_spec.rb +115 -0
  147. data/spec/inputs/text_input_spec.rb +30 -0
  148. data/spec/inputs/url_input_spec.rb +30 -0
  149. data/spec/spec_helper.rb +122 -0
  150. metadata +374 -0
@@ -0,0 +1,11 @@
1
+ module GenericFormFor
2
+ # @private
3
+ class Engine < ::Rails::Engine
4
+ initializer 'generic_form_for.initialize' do
5
+ ActiveSupport.on_load(:action_view) do
6
+ include GenericFormFor::Helpers::FormHelper
7
+ end
8
+ ActionView::Base.field_error_proc = proc { |input, instance| input }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,111 @@
1
+ module GenericFormFor
2
+ class FormBuilder < ActionView::Helpers::FormBuilder
3
+
4
+ attr_accessor :template
5
+
6
+ def self.configure(name, value = nil)
7
+ class_attribute(name)
8
+ self.send(:"#{name}=", value)
9
+ end
10
+
11
+ configure :html5_browser_validate, :true
12
+ configure :html5_browser_autofocus, :true
13
+ configure :default_text_field_size, 40
14
+ configure :required_string, "<abbr>*</abbr>"
15
+ configure :use_translations, false
16
+
17
+ include GenericFormFor::Helpers::FormHelper
18
+ include GenericFormFor::Helpers::InputHelper
19
+ include GenericFormFor::Helpers::FieldsetHelper
20
+ include GenericFormFor::Helpers::ActionHelper
21
+ include GenericFormFor::Helpers::ActionsHelper
22
+
23
+ class_attribute :form_wrapper_proc
24
+
25
+ self.form_wrapper_proc = Proc.new{form_html}
26
+
27
+ # form_wrapper do
28
+ # form :class => "form-vertical"
29
+ # end
30
+ # =>
31
+ # <form class="form-vertical" ...>
32
+ # </form>
33
+ #
34
+ def self.form_wrapper(&block)
35
+ self.form_wrapper_proc = block
36
+ end
37
+
38
+ class_attribute :input_wrapper_proc
39
+
40
+ self.input_wrapper_proc = Proc.new{wrap_in{label_html; input_html; error_html; hint_html}}
41
+
42
+ class_attribute :fieldset_wrapper_proc
43
+
44
+ self.fieldset_wrapper_proc = Proc.new{fieldset_html{legend_html}}
45
+ # fieldset_wrapper do
46
+ # fieldset_html
47
+ # end
48
+ # =>
49
+ # <fieldset>
50
+ # </fieldset>
51
+ #
52
+ # fieldset_wrapper do
53
+ # fieldset_html :tag => "div", :class => "fieldset" do
54
+ # legend_html :tag => "span", :class => "legend"
55
+ # end
56
+ # end
57
+ # =>
58
+ # <div class="fieldset">
59
+ # <span class="legend"></span>
60
+ # </div>
61
+ #
62
+ def self.fieldset_wrapper(&block)
63
+ self.fieldset_wrapper_proc = block
64
+ end
65
+
66
+ # input_wrapper do
67
+ # wrap_in :class => "controls" do
68
+ # label_html
69
+ # input_html
70
+ # error_html
71
+ # end
72
+ # end
73
+ # =>
74
+ # <div class="controls" ...>
75
+ # <label for="one">My Column</label>
76
+ # <input id="one" type="text" value="1"/>
77
+ # <span class="errors">can not be blank</span>
78
+ # </div>
79
+ #
80
+ def self.input_wrapper(&block)
81
+ self.input_wrapper_proc = block
82
+ end
83
+
84
+ class_attribute :actions_wrapper_proc
85
+
86
+ self.actions_wrapper_proc = Proc.new{actions_html}
87
+ # actions_wrapper do
88
+ # actions_html
89
+ # end
90
+ # =>
91
+ # <div>
92
+ # </div>
93
+ #
94
+ def self.actions_wrapper(&block)
95
+ self.actions_wrapper_proc = block
96
+ end
97
+
98
+ class_attribute :action_wrapper_proc
99
+
100
+ self.action_wrapper_proc = Proc.new{action_html{icon_html}}
101
+ # action_wrapper do
102
+ # action_html
103
+ # end
104
+ # =>
105
+ # <input type="submit" value="Save"/>
106
+ #
107
+ def self.action_wrapper(&block)
108
+ self.action_wrapper_proc = block
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,10 @@
1
+ module GenericFormFor
2
+ # @private
3
+ module Helpers
4
+ autoload :FormHelper, 'generic_form_for/helpers/form_helper'
5
+ autoload :InputHelper, 'generic_form_for/helpers/input_helper'
6
+ autoload :ActionHelper, 'generic_form_for/helpers/action_helper'
7
+ autoload :FieldsetHelper, 'generic_form_for/helpers/fieldset_helper'
8
+ autoload :ActionsHelper, 'generic_form_for/helpers/actions_helper'
9
+ end
10
+ end
@@ -0,0 +1,52 @@
1
+ module GenericFormFor
2
+ module Helpers
3
+ module ActionHelper
4
+
5
+ def action(name, options = {})
6
+ options = options.dup
7
+ options[:as] ||= default_action_type(name, options)
8
+
9
+ klass = action_class(options[:as])
10
+ klass.new(self, template, @object, @object_name, name, options).to_html
11
+ end
12
+
13
+ protected
14
+
15
+ def default_action_type(name, options = {}) #:nodoc:
16
+ case name
17
+ when :submit then :input
18
+ when :reset then :input
19
+ when :button then :button
20
+ when :cancel then :link
21
+ when :back then :link
22
+ end
23
+ end
24
+
25
+ def action_class(as)
26
+ @input_classes_cache ||= {}
27
+ @input_classes_cache[as] ||= begin
28
+ begin
29
+ begin
30
+ standard_action_class_name(as).constantize
31
+ rescue NameError
32
+ generic_action_class_name(as).constantize
33
+ end
34
+ rescue NameError => e
35
+ raise GenericFormFor::UnknownActionError, e.message
36
+ end
37
+ end
38
+ end
39
+
40
+ # :as => :string # => MyFormBuilder::Inputs::StringInput
41
+ def standard_action_class_name(as)
42
+ "#{self.class.to_s.split("::").first}::Actions::#{as.to_s.camelize}Action"
43
+ end
44
+
45
+ # :as => :string # => GenericFormFor::Inputs::StringInput
46
+ def generic_action_class_name(as)
47
+ "GenericFormFor::Actions::#{as.to_s.camelize}Action"
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,35 @@
1
+ module GenericFormFor
2
+ module Helpers
3
+ module ActionsHelper
4
+ include I18n
5
+
6
+ attr_accessor :args, :block
7
+
8
+ def actions(*args, &block)
9
+ self.args, self.block = [*args], block
10
+ instance_exec &builder.actions_wrapper_proc
11
+ ""
12
+ end
13
+
14
+ protected
15
+
16
+ def actions_html(config_options={})
17
+ options = args.last.is_a?(Hash) ? args.dup.pop : {}
18
+ template.concat(
19
+ template.content_tag(
20
+ options.delete(:tag) || :div,
21
+ merge_actions_options(options,config_options)
22
+ ) do
23
+ template.concat(template.capture(&self.block)) if self.block
24
+ end
25
+ )
26
+ end
27
+
28
+ def merge_actions_options(runtime_options,config_options)
29
+ runtime_options[:class] = [*runtime_options[:class], *config_options[:class]].compact.join(' ').strip
30
+ config_options.merge(runtime_options)
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,48 @@
1
+ module GenericFormFor
2
+ module Helpers
3
+ module FieldsetHelper
4
+ include I18n
5
+
6
+ attr_accessor :args, :block
7
+
8
+ def fieldset(*args, &block)
9
+ self.args, self.block = [*args], block
10
+ instance_exec &builder.fieldset_wrapper_proc
11
+ ""
12
+ end
13
+
14
+ protected
15
+
16
+ def fieldset_html(config_options={}, &html_block)
17
+ options = args.last.is_a?(Hash) ? args.dup.pop : {}
18
+ template.concat(
19
+ template.content_tag(
20
+ options.delete(:tag) || :fieldset,
21
+ merge_fieldset_options(options.except(:legend_html),config_options)
22
+ ) do
23
+ template.concat(template.capture(&html_block)) if block_given?
24
+ template.concat(template.capture(&self.block)) if self.block
25
+ end
26
+ )
27
+ end
28
+
29
+ def legend_html(config_options={})
30
+ options = args.last.is_a?(Hash) ? args.pop : {}
31
+ return "" unless args.first
32
+ # template.concat(
33
+ template.content_tag(
34
+ config_options.delete(:tag) || :legend,
35
+ translate_legend(args.first),
36
+ merge_fieldset_options(options[:legend_html] || {},config_options)
37
+ )
38
+ # )
39
+ end
40
+
41
+ def merge_fieldset_options(runtime_options,config_options)
42
+ runtime_options[:class] = [*runtime_options[:class], *config_options[:class]].compact.join(' ').strip
43
+ config_options.merge(runtime_options).except(:legend_html)
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,64 @@
1
+ module GenericFormFor
2
+ module Helpers
3
+ # FormHelper is a wrapper around Rails' built-in form helper
4
+ module FormHelper
5
+
6
+ mattr_accessor :builder
7
+
8
+ attr_accessor :autofocus
9
+ attr_accessor :record, :args, :proc
10
+
11
+ # = generic_form_for @post, :html => {:novalidate => true} do |f|
12
+ # ..form content
13
+ # Behaves the same as form form.
14
+ # Adittional options:
15
+ # autofocus: false - will tur off autofocus for this form
16
+ # by default autofocus is on and will set autofocus attribute to first visible element
17
+ def generic_form_for(record, *args, &proc)
18
+ options = args.last.is_a?(Hash) ? args.pop : {}
19
+ options[:builder] ||= GenericFormFor::FormBuilder
20
+ self.builder = options[:builder]
21
+ options[:html] ||= {}
22
+ self.record, self.args, self.proc = record, *(args << options), proc
23
+ instance_exec &builder.form_wrapper_proc
24
+ end
25
+
26
+ def generic_fields_for(name, *args, &proc)
27
+ options = args.last.is_a?(Hash) ? args.pop : {}
28
+ options[:builder] ||= GenericFormFor::FormBuilder
29
+ fields_for(name, *(args << options), &proc)
30
+ end
31
+
32
+ protected
33
+
34
+ def _generic_form_for(record, *args, &proc)
35
+ form_for(record, *args, &proc)
36
+ end
37
+
38
+ def form_html(options={})
39
+ self.args[:html][:class] = [[*self.args[:html][:class]],options.delete(:class)].compact.join(" ").strip
40
+
41
+ if self.args.key?(:autofocus)
42
+ self.autofocus = self.args.delete(:autofocus)
43
+ elsif options.key?(:autofocus)
44
+ self.autofocus = options.delete(:autofocus)
45
+ else
46
+ self.autofocus = @@builder.html5_browser_autofocus
47
+ end
48
+
49
+ unless self.args[:html].key?(:novalidate)
50
+ if self.args.key?(:novalidate)
51
+ self.args[:html][:novalidate] ||= self.args.delete(:novalidate)
52
+ elsif options.key?(:novalidate)
53
+ self.args[:html][:novalidate] ||= options.delete(:novalidate)
54
+ else
55
+ self.args[:html][:novalidate] ||= !@@builder.html5_browser_validate
56
+ end
57
+ end
58
+
59
+ _generic_form_for(self.record, (options || {}).deep_merge(self.args || {}), &self.proc)
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,77 @@
1
+ module GenericFormFor
2
+ module Helpers
3
+ module InputHelper
4
+
5
+ def input(method, options = {})
6
+ options = options.dup
7
+ options[:as] ||= default_input_type(method, options)
8
+
9
+ klass = input_class(options[:as])
10
+ klass.new(self, template, @object, @object_name, method, column_for(method), options).to_html
11
+ end
12
+
13
+ protected
14
+
15
+ def default_input_type(method, options = {}) #:nodoc:
16
+ return :select if options.key?(:collection)
17
+ return :select if @object && reflection_for(method)
18
+
19
+ if column = column_for(method)
20
+ case column.type
21
+ when :string
22
+ return :password if method.to_s =~ /password/
23
+ return :email if method.to_s =~ /email/
24
+ return :url if method.to_s =~ /^url$|^website$|_url$/
25
+ return :phone if method.to_s =~ /(phone|fax|mobile)/
26
+ return :search if method.to_s =~ /^search$/
27
+ when :integer
28
+ return :number
29
+ when :float, :decimal
30
+ return :number
31
+ when :timestamp
32
+ return :datetime
33
+ end
34
+ # Try 3: Assume the input name will be the same as the column type (e.g. string_input).
35
+ return column.type
36
+ else
37
+ return :password if method.to_s =~ /password/
38
+ return :string
39
+ end
40
+ end
41
+
42
+ def column_for(method) #:nodoc:
43
+ @object.column_for_attribute(method) if @object.respond_to?(:column_for_attribute)
44
+ end
45
+
46
+ def reflection_for(method) #:nodoc:
47
+ @object.class.reflect_on_association(method) if @object.class.respond_to?(:reflect_on_association)
48
+ end
49
+
50
+ def input_class(as)
51
+ @input_classes_cache ||= {}
52
+ @input_classes_cache[as] ||= begin
53
+ begin
54
+ begin
55
+ standard_input_class_name(as).constantize
56
+ rescue NameError
57
+ generic_input_class_name(as).constantize
58
+ end
59
+ rescue NameError => e
60
+ raise GenericFormFor::UnknownInputError, e.message
61
+ end
62
+ end
63
+ end
64
+
65
+ # :as => :string # => MyFormBuilder::Inputs::StringInput
66
+ def standard_input_class_name(as)
67
+ "#{self.class.to_s.split("::").first}::Inputs::#{as.to_s.camelize}Input"
68
+ end
69
+
70
+ # :as => :string # => GenericFormFor::Inputs::StringInput
71
+ def generic_input_class_name(as)
72
+ "GenericFormFor::Inputs::#{as.to_s.camelize}Input"
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,44 @@
1
+ module GenericFormFor
2
+ module I18n
3
+
4
+ def translate_placeholder(value)
5
+ translate(value) do
6
+ ::I18n.translate(value, :scope => "form_for.#{object_name}.placeholders")
7
+ end
8
+ end
9
+
10
+ def translate_hint(value)
11
+ translate(value) do
12
+ ::I18n.translate(value, :scope => "form_for.#{object_name}.hints")
13
+ end
14
+ end
15
+
16
+ def translate_label(value)
17
+ translate(value) do
18
+ ::I18n.translate(value, :scope => "activerecord.attributes.#{object_name}", :default => Proc.new{:"form_for.#{object_name}.attributes.#{value}"})
19
+ end
20
+ end
21
+
22
+ def translate_action(value)
23
+ translate(value) do
24
+ ::I18n.translate(value, :scope => "form_for.actions", :default => Proc.new{:"actions.#{value}"})
25
+ end
26
+ end
27
+
28
+ def translate_legend(value)
29
+ translate(value) do
30
+ ::I18n.translate(value, :scope => "form_for.#{object_name}.legends", :default => Proc.new{:"legends.#{value}"})
31
+ end
32
+ end
33
+
34
+ def translate(value, &block)
35
+ if value.is_a?(Symbol)
36
+ return yield if builder.use_translations
37
+ value.to_s.camelize
38
+ else
39
+ value
40
+ end
41
+ end
42
+
43
+ end
44
+ end