Class: Maglev::SectionGenerator

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

Defined Under Namespace

Classes: BlockSetting, SectionSetting

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



12
13
14
# File 'lib/generators/maglev/section_generator.rb', line 12

def blocks
  @blocks
end

#categoryObject (readonly)

Returns the value of attribute category.



12
13
14
# File 'lib/generators/maglev/section_generator.rb', line 12

def category
  @category
end

#settingsObject (readonly)

Returns the value of attribute settings.



12
13
14
# File 'lib/generators/maglev/section_generator.rb', line 12

def settings
  @settings
end

#theme_nameObject (readonly)

Returns the value of attribute theme_name.



12
13
14
# File 'lib/generators/maglev/section_generator.rb', line 12

def theme_name
  @theme_name
end

Instance Method Details

#build_settingsObject



32
33
34
35
# File 'lib/generators/maglev/section_generator.rb', line 32

def build_settings
  @settings = extract_section_settings
  @blocks = extract_blocks
end

#create_section_filesObject



37
38
39
# File 'lib/generators/maglev/section_generator.rb', line 37

def create_section_files
  directory 'app'
end

#select_categoryObject



22
23
24
25
26
27
28
29
30
# File 'lib/generators/maglev/section_generator.rb', line 22

def select_category
  @category = options['category']

  return if @category.present? && categories.include?(@category)

  say 'You have to select a category for your section. Please check your Maglev theme.yml file to manage them.',
      :blue
  @category = ask 'Please choose a category', limited_to: categories, default: categories.first
end

#verify_categories_existObject

Raises:

  • (Thor::Error)


18
19
20
# File 'lib/generators/maglev/section_generator.rb', line 18

def verify_categories_exist
  raise Thor::Error, set_color('ERROR: You must add categories to your theme.', :red) if categories.blank?
end

#verify_theme_existsObject

Raises:

  • (Thor::Error)


14
15
16
# File 'lib/generators/maglev/section_generator.rb', line 14

def verify_theme_exists
  raise Thor::Error, set_color('ERROR: You must first create a theme.', :red) if theme.nil?
end