Module: Koi::Helpers::AdminGeneratorAttributes

Extended by:
ActiveSupport::Concern
Included in:
AdminControllerGenerator, AdminViewsGenerator
Defined in:
lib/generators/koi/helpers/admin_generator_attributes.rb

Instance Method Summary collapse

Instance Method Details

#collection_attribute_for(attribute) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/generators/koi/helpers/admin_generator_attributes.rb', line 48

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

#govuk_input_for(attribute) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/koi/helpers/admin_generator_attributes.rb', line 8

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

#index_attribute_for(attribute) ⇒ Object Also known as: summary_attribute_for



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/koi/helpers/admin_generator_attributes.rb', line 27

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

#index_attributesObject



61
62
63
# File 'lib/generators/koi/helpers/admin_generator_attributes.rb', line 61

def index_attributes
  attributes
end