Class: Milk::SemanticFormBuilder
- Inherits:
-
Formtastic::SemanticFormBuilder
- Object
- Formtastic::SemanticFormBuilder
- Milk::SemanticFormBuilder
- Defined in:
- lib/milk/semantic_form_builder.rb
Constant Summary collapse
- @@all_fields_required_by_default =
false
- @@i18n_lookups_by_default =
true
- @@input_class =
'b_field'
- @@inputs_class =
'b_fields_set'
'b_buttons_set'
Instance Method Summary collapse
- #buttons(*args, &block) ⇒ Object
- #input(method, options = {}) ⇒ Object
- #inputs(*args, &block) ⇒ Object
- #save_or_create_button_text(prefix = 'Submit') ⇒ Object
Instance Method Details
#buttons(*args, &block) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/milk/semantic_form_builder.rb', line 61 def (*args, &block) = args. [:class] ||= @@buttons_class if block_given? field_set_and_list_wrapping(, &block) else args = [:commit] if args.empty? contents = args.map { || send(:"#{}_button") } field_set_and_list_wrapping(, contents) end end |
#input(method, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/milk/semantic_form_builder.rb', line 10 def input(method, = {}) [:required] = method_required?(method) unless .key?(:required) [:as] ||= default_input_type(method) html_class = [ [:as], ([:required] ? :required : :optional) ] html_class << 'error' if @object && @object.respond_to?(:errors) && @object.errors[method.to_sym] wrapper_html = .delete(:wrapper_html) || {} wrapper_html[:id] ||= generate_html_id(method) wrapper_html[:class] = "#{@@input_class} #{(html_class << wrapper_html[:class]).flatten.compact.map{ |klass| "#{@@input_class}-#{klass}" }.join(' ')}" if [:boolean_select, :boolean_radio].include?([:as]) ::ActiveSupport::Deprecation.warn(":as => :#{[:as]} is deprecated, use :as => :#{[:as].to_s[8..-1]} instead", caller[3..-1]) end if [:input_html] && [:input_html][:id] [:label_html] ||= {} [:label_html][:for] ||= [:input_html][:id] end input_parts = @@inline_order.dup input_parts.delete(:errors) if [:as] == :hidden list_item_content = input_parts.map do |type| send(:"inline_#{type}_for", method, ) end.compact.join("\n") return template.content_tag(:li, list_item_content, wrapper_html) end |
#inputs(*args, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/milk/semantic_form_builder.rb', line 40 def inputs(*args, &block) = args. [:class] ||= @@inputs_class if [:for] inputs_for_nested_attributes(args, , &block) elsif block_given? field_set_and_list_wrapping(, &block) else if @object && args.empty? args = @object.class.reflections.map { |n,_| n if _.macro == :belongs_to } args += @object.class.content_columns.map(&:name) args -= %w[created_at updated_at created_on updated_on lock_version] args.compact! end contents = args.map { |method| input(method.to_sym) } field_set_and_list_wrapping(, contents) end end |
#save_or_create_button_text(prefix = 'Submit') ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/milk/semantic_form_builder.rb', line 74 def (prefix = 'Submit') if @object prefix = @object.new_record? ? 'Create' : 'Save' object_name = @object.class.name.underscore i18n_prefix = prefix.downcase else object_name = @object_name.to_s.underscore end i18n_prefix = prefix.downcase I18n.t("formtastic.buttons.#{object_name}.#{i18n_prefix}", :default => [ :"formtastic.buttons.#{i18n_prefix}", prefix]) end |