Sha256: 243361b3d5de8d1de1b7a5d476bd585ff8cd144e6b9552e9f883a9844c7f7ae3

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module BaseEditingBootstrap
  module Generators
    class FieldOverrideGenerator < ::Rails::Generators::Base
      source_root File.expand_path("../../../../app/views/base_editing", __dir__)
      argument :name, type: :string, banner: "Post", required: true
      argument :attributes, type: :array, default: [], banner: "field field:type"

      TYPES = %i[base date datetime decimal integer enum]

      desc <<-DESCRIPTION.strip_heredoc
             Description:   
                Copy partial files for a defined fields, 
                the possible types are #{TYPES}
                Default to base
      DESCRIPTION

      def copy_form_partials
        if attributes.empty?
          say "Need one field"
        else
          singular_name = name.underscore.downcase.singularize
          plural_name = singular_name.pluralize
          attributes.each do |a|
            attr_name, type = a.split(":")

            type = :base if type.nil?
            type = type.to_sym
            raise "Type #{type} not found in #{TYPES}" unless TYPES.include?(type)
            copy_file "form_field/_#{type}.html.erb", File.join("app/views", plural_name, singular_name, 'form_field', "_#{attr_name}.html.erb")
          end
        end

      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
base_editing_bootstrap-0.13.0 lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb
base_editing_bootstrap-0.12.0 lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb
base_editing_bootstrap-0.11.0 lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb
base_editing_bootstrap-0.10.2 lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb
base_editing_bootstrap-0.10.1 lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb
base_editing_bootstrap-0.10.0 lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb
base_editing_bootstrap-0.9.1 lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb
base_editing_bootstrap-0.9.0 lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb
base_editing_bootstrap-0.8.0 lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb
base_editing_bootstrap-0.7.0 lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb