module Formular::Helper

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

Constants

BUILDERS

Attributes

builder[W]

Public Class Methods

_builder() click to toggle source
# File lib/formular/helper.rb, line 24
def _builder
  @builder || :basic
end
builder(name) click to toggle source
# File lib/formular/helper.rb, line 29
def builder(name)
  self.builder = name
end
load_builder(name) click to toggle source
# 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

Public Instance Methods

form(model, url, **options, &block) click to toggle source
# 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

Private Instance Methods

builder(model, **options) click to toggle source
# File lib/formular/helper.rb, line 44
def builder(model, **options)
  builder_name = options.delete(:builder)
  builder_name ||= Formular::Helper._builder

  builder = Formular::Helper.load_builder(builder_name)

  options[:model] ||= model

  builder.new(options)
end