Module: Formular::Helper

Included in:
RailsHelper
Defined in:
lib/formular/helper.rb

Overview

TODO: indirectly tested in erb_test and slim_test. Should probably test directly

Constant Summary collapse

BUILDERS =
{
  basic: 'Formular::Builders::Basic',
  bootstrap3: 'Formular::Builders::Bootstrap3',
  bootstrap4: 'Formular::Builders::Bootstrap4',
  bootstrap3_inline: 'Formular::Builders::Bootstrap3Inline',
  bootstrap4_inline: 'Formular::Builders::Bootstrap4Inline',
  bootstrap3_horizontal: 'Formular::Builders::Bootstrap3Horizontal',
  bootstrap4_horizontal: 'Formular::Builders::Bootstrap4Horizontal',
  foundation6: 'Formular::Builders::Foundation6'
}.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.builder(name) ⇒ Object


29
30
31
# File 'lib/formular/helper.rb', line 29

def builder(name)
  self.builder = name
end

Class Method Details

._builderObject


24
25
26
# File 'lib/formular/helper.rb', line 24

def _builder
  @builder || :basic
end

.load_builder(name) ⇒ Object


33
34
35
36
37
38
39
# File 'lib/formular/helper.rb', line 33

def load_builder(name)
  builder_const = BUILDERS.fetch(name, nil)
  return name unless builder_const

  require "formular/builders/#{name}"
  Formular::Builders.const_get(builder_const)
end

Instance Method Details

#form(model, url, **options, &block) ⇒ Object


4
5
6
7
8
9
10
# File 'lib/formular/helper.rb', line 4

def form(model, url, **options, &block)
  form_options = options
  builder_options = form_options.select { |k, v| form_options.delete(k) || true if [:builder, :model, :path_prefix, :errors, :elements].include?(k) }

  form_options[:action] ||= url
  builder(model, builder_options).form(form_options, &block)
end