Module: SexyForm

Defined in:
lib/sexy_form.rb,
lib/sexy_form/themes.rb,
lib/sexy_form/builder.rb,
lib/sexy_form/version.rb,
lib/sexy_form/themes/default.rb,
lib/sexy_form/themes/milligram.rb,
lib/sexy_form/themes/base_theme.rb,
lib/sexy_form/themes/foundation.rb,
lib/sexy_form/themes/materialize.rb,
lib/sexy_form/themes/bulma_vertical.rb,
lib/sexy_form/themes/bulma_horizontal.rb,
lib/sexy_form/themes/bootstrap_2_inline.rb,
lib/sexy_form/themes/bootstrap_3_inline.rb,
lib/sexy_form/themes/bootstrap_4_inline.rb,
lib/sexy_form/themes/semantic_ui_inline.rb,
lib/sexy_form/themes/bootstrap_2_vertical.rb,
lib/sexy_form/themes/bootstrap_3_vertical.rb,
lib/sexy_form/themes/bootstrap_4_vertical.rb,
lib/sexy_form/themes/semantic_ui_vertical.rb,
lib/sexy_form/themes/bootstrap_2_horizontal.rb,
lib/sexy_form/themes/bootstrap_3_horizontal.rb,
lib/sexy_form/themes/bootstrap_4_horizontal.rb

Defined Under Namespace

Modules: Themes Classes: Builder

Constant Summary collapse

VERSION =
"0.9.0"

Class Method Summary collapse

Class Method Details

.form(action: nil, method: "post", theme: nil, form_html: {}) ⇒ 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
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sexy_form.rb', line 13

def self.form(action: nil, method: "post", theme: nil, form_html: {})
  self.verify_argument_type(arg_name: :form_html, value: form_html, expected_type: Hash)

  action = action.to_s
  method = method.to_s

  builder = SexyForm::Builder.new(theme: theme)

  themed_form_html = builder.theme.form_html_attributes(html_attrs: self.safe_string_hash(form_html))

  themed_form_html["method"] = method.to_s == "get" ? "get" : "post"

  if themed_form_html["multipart"] == true
    themed_form_html.delete("multipart")
    themed_form_html["enctype"] = "multipart/form-data"
  end

  str = ""

  str << %Q(<form #{self.build_html_attr_string(themed_form_html)}>)

  unless ["get", "post"].include?(method.to_s)
    str << %Q(<input type="hidden" name="_method" value="#{method}")
  end

  if block_given?
    yield builder
  end

  unless builder.html_string.empty?
    str << builder.html_string
  end

  str << "</form>"

  str
end