Class: FormtasticExtensions::SemanticFormBuilder

Inherits:
Formtastic::SemanticFormBuilder
  • Object
show all
Defined in:
lib/formtastic_extensions/semantic_form_builder.rb

Constant Summary collapse

@@input_class =
'b_field'
@@inputs_class =
'b_fields_set'
@@buttons_class =
'b_buttons_set'

Instance Method Summary collapse

Instance Method Details

#buttons(*args, &block) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/formtastic_extensions/semantic_form_builder.rb', line 61

def buttons(*args, &block)
  html_options = args.extract_options!
  html_options[:class] ||= @@buttons_class

  if block_given?
    field_set_and_list_wrapping(html_options, &block)
  else
    args = [:commit] if args.empty?
    contents = args.map { |button_name| send(:"#{button_name}_button") }
    field_set_and_list_wrapping(html_options, contents)
  end
end

#input(method, options = {}) ⇒ Object



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/formtastic_extensions/semantic_form_builder.rb', line 13

def input(method, options = {})
  options[:required] = method_required?(method) unless options.key?(:required)
  options[:as]     ||= default_input_type(method)

  html_class = [ options[:as], (options[:required] ? :required : :optional) ]
  html_class << 'error' if @object && @object.respond_to?(:errors) && !@object.errors[method.to_sym].blank?
  html_class << method.to_s

  wrapper_html = options.delete(:wrapper_html) || {}
  wrapper_html[:id]  ||= generate_html_id(method)
  wrapper_html[:class] = class_with_modifiers(@@input_class, html_class << wrapper_html[:class])

  if options[:input_html] && options[:input_html][:id]
    options[:label_html] ||= {}
    options[:label_html][:for] ||= options[:input_html][:id]
  end

  input_parts = @@inline_order.dup
  input_parts.delete(:errors) if options[:as] == :hidden

  list_item_content = input_parts.map do |type|
    send(:"inline_#{type}_for", method, options)
  end.compact.join("\n")

  return template.(: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/formtastic_extensions/semantic_form_builder.rb', line 40

def inputs(*args, &block)
  html_options = args.extract_options!
  html_options[:class] ||= @@inputs_class

  if html_options[:for]
    inputs_for_nested_attributes(args, html_options, &block)
  elsif block_given?
    field_set_and_list_wrapping(html_options, &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 version]
      args.compact!
    end
    contents = args.map { |method| input(method.to_sym) }

    field_set_and_list_wrapping(html_options, contents)
  end
end

#wysiwyg_input(method, options = {}) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/formtastic_extensions/semantic_form_builder.rb', line 74

def wysiwyg_input(method, options = {})
  html_options = options.delete(:input_html) || {}
  html_options[:class] ||= ''
  html_options[:class] << ' mceEditor'

  self.label(method, options_for_label(options)) +
  self.text_area(method, html_options)
end