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

Instance Method Summary collapse

Class Attribute Details

.builder(name = nil) ⇒ Object



26
27
28
29
30
# File 'lib/formular/helper.rb', line 26

def builder(name = nil)
  name ||= :basic
  require "formular/builders/#{name}"
  self.builder = Formular::Builders.const_get(BUILDERS.fetch(name)) # Formular::Builders::Bootstrap3
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