module SimpleForm

Constants

CUSTOM_INPUT_DEPRECATION_WARN
FILE_METHODS_DEPRECATION_WARN
VERSION

Public Class Methods

additional_classes_for(component) { |: []| ... } click to toggle source
# File lib/simple_form.rb, line 260
def self.additional_classes_for(component)
  generate_additional_classes_for.include?(component) ? yield : []
end
build(options = {}) { |builder| ... } click to toggle source

Builds a new wrapper using SimpleForm::Wrappers::Builder.

# File lib/simple_form.rb, line 238
def self.build(options = {})
  options[:tag] = :div if options[:tag].nil?
  builder = SimpleForm::Wrappers::Builder.new(options)
  yield builder
  SimpleForm::Wrappers::Root.new(builder.to_a, options)
end
default_input_size=(*) click to toggle source

SETUP

# File lib/simple_form.rb, line 266
def self.default_input_size=(*)
  ActiveSupport::Deprecation.warn "[SIMPLE_FORM] SimpleForm.default_input_size= is deprecated and has no effect", caller
end
eager_load!() click to toggle source
Calls superclass method
# File lib/simple_form.rb, line 23
def self.eager_load!
  super
  SimpleForm::Inputs.eager_load!
  SimpleForm::Components.eager_load!
end
file_methods() click to toggle source
# File lib/simple_form.rb, line 280
def self.file_methods
  ActiveSupport::Deprecation.warn(FILE_METHODS_DEPRECATION_WARN, caller)
  @@file_methods
end
file_methods=(file_methods) click to toggle source
# File lib/simple_form.rb, line 275
def self.file_methods=(file_methods)
  ActiveSupport::Deprecation.warn(FILE_METHODS_DEPRECATION_WARN, caller)
  @@file_methods = file_methods
end
form_class=(value) click to toggle source
# File lib/simple_form.rb, line 270
def self.form_class=(value)
  ActiveSupport::Deprecation.warn "[SIMPLE_FORM] SimpleForm.form_class= is deprecated and will be removed in 4.x. Use SimpleForm.default_form_class= instead", caller
  @@form_class = value
end
include_component(component) click to toggle source

Includes a component to be used by Simple Form. Methods defined in a component will be exposed to be used in the wrapper as Simple::Components

Examples

# The application needs to tell where the components will be.
Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }

# Create a custom component in the path specified above.
# lib/components/input_group_component.rb
module InputGroupComponent
  def prepend
    ...
  end

  def append
    ...
  end
end

SimpleForm.setup do |config|
  # Create a wrapper using the custom component.
  config.wrappers :input_group, tag: :div, error_class: :error do |b|
    b.use :label
    b.optional :prepend
    b.use :input
    b.use :append
  end
end

# Using the custom component in the form.
<%= simple_form_for @blog, wrapper: input_group do |f| %>
  <%= f.input :title, prepend: true %>
<% end %>
# File lib/simple_form.rb, line 327
def self.include_component(component)
  if Module === component
    SimpleForm::Inputs::Base.include(component)
  else
    raise TypeError, "SimpleForm.include_component expects a module but got: #{component.class}"
  end
end
setup() { |self| ... } click to toggle source

Default way to setup Simple Form. Run rails generate simple_form:install to create a fresh initializer with all configuration values.

# File lib/simple_form.rb, line 287
def self.setup
  @@configured = true
  yield self
end
wrapper(name) click to toggle source

Retrieves a given wrapper

# File lib/simple_form.rb, line 217
def self.wrapper(name)
  @@wrappers[name.to_s] or raise WrapperNotFound, "Couldn't find wrapper with name #{name}"
end
wrappers(*args, &block) click to toggle source

Define a new wrapper using SimpleForm::Wrappers::Builder and store it in the given name.

# File lib/simple_form.rb, line 227
def self.wrappers(*args, &block)
  if block_given?
    options                 = args.extract_options!
    name                    = args.first || :default
    @@wrappers[name.to_s]   = build(options, &block)
  else
    @@wrappers
  end
end