Sha256: ef5a2e73e82dbe02e068cbddb3046906b8fbb4f93cbf8e989fb79064b5129d84

Contents?: true

Size: 1.87 KB

Versions: 28

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

module Koi
  module Helpers
    module AdminGeneratorAttributes
      extend ActiveSupport::Concern

      def govuk_input_for(attribute)
        case attribute.type
        when :string
          %(<%= form.govuk_text_field :#{attribute.name} %>)
        when :integer
          %(<%= form.govuk_number_field :#{attribute.name} %>)
        when :boolean
          %(<%= form.govuk_check_box_field :#{attribute.name} %>)
        when :date
          %(<%= form.govuk_date_field :#{attribute.name}, legend: { size: "s" } %>)
        when :rich_text, :text
          %(<%= form.govuk_rich_text_area :#{attribute.name} %>)
        when :attachment
          %(<%= form.govuk_image_field :#{attribute.name} %>)
        else
          ""
        end
      end

      def index_attribute_for(attribute)
        case attribute.type
        when :integer
          %(<% row.number :#{attribute.name} %>)
        when :boolean
          %(<% row.boolean :#{attribute.name} %>)
        when :date
          %(<% row.date :#{attribute.name} %>)
        when :datetime
          %(<% row.datetime :#{attribute.name} %>)
        when :rich_text
          %(<% row.rich_text :#{attribute.name} %>)
        when :attachment
          %(<% row.attachment :#{attribute.name} %>)
        else
          %(<% row.text :#{attribute.name} %>)
        end
      end

      alias_method :summary_attribute_for, :index_attribute_for

      def collection_attribute_for(attribute)
        case attribute.type
        when :string
          %(attribute :#{attribute.name}, :string)
        when :integer
          %(attribute :#{attribute.name}, :integer)
        when :boolean
          %(attribute :#{attribute.name}, :boolean)
        when :date, :datetime
          %(attribute :#{attribute.name}, :date)
        end
      end

      def index_attributes
        attributes
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
katalyst-koi-4.15.1 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.15.0 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.14.3 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.14.2 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.14.1 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.14.0 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.13.2 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.13.0 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.12.6 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.12.5 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.12.4 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.12.3 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.12.2 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.12.1 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.12.0 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.11.2 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.11.1 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.11.0 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.10.3 lib/generators/koi/helpers/admin_generator_attributes.rb
katalyst-koi-4.10.2 lib/generators/koi/helpers/admin_generator_attributes.rb