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.



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

def blocks
  @blocks
end

#categoryObject (readonly)

Returns the value of attribute category.



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

def category
  @category
end

#section_nameObject (readonly)

Returns the value of attribute section_name.



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

def section_name
  @section_name
end

#settingsObject (readonly)

Returns the value of attribute settings.



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

def settings
  @settings
end

#theme_nameObject (readonly)

Returns the value of attribute theme_name.



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

def theme_name
  @theme_name
end

Instance Method Details

#build_settingsObject



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

def build_settings
  @settings = extract_section_settings
  @blocks = extract_blocks
end

#create_section_filesObject



42
43
44
# File 'lib/generators/maglev/section_generator.rb', line 42

def create_section_files
  directory 'app'
end

#select_categoryObject



27
28
29
30
31
32
33
34
35
# File 'lib/generators/maglev/section_generator.rb', line 27

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

#set_section_nameObject



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

def set_section_name
  @section_name = options['name'] || file_name.humanize
end

#verify_categories_existObject

Raises:

  • (Thor::Error)


23
24
25
# File 'lib/generators/maglev/section_generator.rb', line 23

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)


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

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