Class: Maglev::SectionGenerator::SectionSetting

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/maglev/section_generator.rb

Direct Known Subclasses

BlockSetting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type, label = nil) ⇒ SectionSetting

Returns a new instance of SectionSetting.



100
101
102
103
104
# File 'lib/generators/maglev/section_generator.rb', line 100

def initialize(id, type, label = nil)
  @id = id
  @type = type || 'text'
  @label = label || id.humanize
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



98
99
100
# File 'lib/generators/maglev/section_generator.rb', line 98

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label.



98
99
100
# File 'lib/generators/maglev/section_generator.rb', line 98

def label
  @label
end

#typeObject (readonly)

Returns the value of attribute type.



98
99
100
# File 'lib/generators/maglev/section_generator.rb', line 98

def type
  @type
end

Instance Method Details

#defaultObject

rubocop:disable Metrics/CyclomaticComplexity



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/generators/maglev/section_generator.rb', line 107

def default
  case type
  when 'text' then label
  when 'image' then '"/theme/image-placeholder.jpg"'
  when 'checkbox' then true
  when 'link' then '{ text: "Link", href: "#" }'
  when 'color' then '#E5E7EB'
  when 'radio', 'select' then 'option_1'
  when 'icon' then 'default-icon-class'
  when 'collection_item' then 'any'
  end
end

#value?Boolean

rubocop:enable Metrics/CyclomaticComplexity

Returns:

  • (Boolean)


121
122
123
# File 'lib/generators/maglev/section_generator.rb', line 121

def value?
  !%w[hint content_type].include?(type)
end