Sha256: 5990751fefd29cd347865fd7145567f9610223e04fa47c563def950940dcd2ae

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

module Stationed
  module Generators
    module Plugins
      module SimpleForm
        def self.prepended(base)
          base.class_option :simple_form,
            type: :boolean,
            default: true,
            desc: 'Include and configure simple_form as FormBuilder'
        end

        def finish_template
          return super unless options[:simple_form]
          gem 'simple_form'
          super
        end

        def run_bundle
          super
          return unless options[:simple_form]
          generate 'simple_form:install'
          remove_file 'config/initializers/simple_form.rb'
          copy_file 'simple_form.rb', 'config/initializers/simple_form.rb'
          application do
            <<-RUBY
# Remove Rails' default error wrapper tags and rely solely on SimpleForm
    # and its generated markup.
    config.action_view.field_error_proc = lambda do |html_tag, instance|
      html_tag.html_safe
    end

    # Always use SimpleForm for forms without needing the simple_form_for
    # helper.
    config.action_view.default_form_builder = SimpleForm::FormBuilder
            RUBY
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
stationed-0.6.0 lib/stationed/generators/plugins/simple_form.rb
stationed-0.5.0 lib/stationed/generators/plugins/simple_form.rb
stationed-0.4.0 lib/stationed/generators/plugins/simple_form.rb
stationed-0.3.0 lib/stationed/generators/plugins/simple_form.rb
stationed-0.2.0 lib/stationed/generators/plugins/simple_form.rb
stationed-0.1.0 lib/stationed/generators/plugins/simple_form.rb