Sha256: 9e7595e422d10d58dbd20159ee2bc5357d9893b66a4f28ccc6b2a948af909e87

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

module Formtastic

  # Modify existing inputs, subclass them, or create your own from scratch.
  # @example
  # !!!shell
  #   $ rails generate formtastic:input HatSize

  # @example Define input name using underscore convention
  # !!!shell
  #   $ rails generate formtastic:input hat_size

  # @example Override an existing input behavior
  # !!!shell
  #   $ rails generate formtastic:input string --extend

  # @example Extend an existing input behavior
  # !!!shell
  #   $ rails generate formtastic:input FlexibleText --extend string
  class InputGenerator < Rails::Generators::NamedBase

    argument :name, :type => :string, :required => true, :banner => 'FILE_NAME'

    source_root File.expand_path('../../../templates', __FILE__)

    class_option :extend

    def create
      normalize_file_name
      define_extension_sentence
      template "input.rb", "app/inputs/#{name.underscore}_input.rb"
    end

    protected

    def normalize_file_name
      name.chomp!("Input")  if name.ends_with?("Input")
      name.chomp!("_input") if name.ends_with?("_input")
      name.chomp!("input")  if name.ends_with?("input")
    end

    def define_extension_sentence
      @extension_sentence = "< Formtastic::Inputs::#{name.camelize}Input" if options[:extend] == "extend"
      @extension_sentence ||= "< Formtastic::Inputs::#{options[:extend].camelize}Input" if options[:extend]
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/formtastic-4.0.0/lib/generators/formtastic/input/input_generator.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/formtastic-4.0.0/lib/generators/formtastic/input/input_generator.rb
formtastic-4.0.0 lib/generators/formtastic/input/input_generator.rb
formtastic-4.0.0.rc1 lib/generators/formtastic/input/input_generator.rb
formtastic-3.1.5 lib/generators/formtastic/input/input_generator.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/formtastic-3.1.4/lib/generators/formtastic/input/input_generator.rb
formtastic-3.1.4 lib/generators/formtastic/input/input_generator.rb