Class: Workarea::ContentBlockTypeGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/workarea/content_block_type/content_block_type_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_block_iconObject



21
22
23
24
# File 'lib/generators/workarea/content_block_type/content_block_type_generator.rb', line 21

def create_block_icon
  file_path = "app/assets/images/workarea/admin/content_block_types/#{file_name}.svg"
  template('block.svg', file_path)
end

#create_storefront_viewObject



7
8
9
# File 'lib/generators/workarea/content_block_type/content_block_type_generator.rb', line 7

def create_storefront_view
  template 'storefront_view.html.haml.erb', view_path
end

#create_stylesheetObject



11
12
13
14
15
16
17
18
19
# File 'lib/generators/workarea/content_block_type/content_block_type_generator.rb', line 11

def create_stylesheet
  relative_file_path = "workarea/storefront/components/_#{file_name}_block"
  absolute_file_path = "app/assets/stylesheets/#{relative_file_path}.scss"
  template 'stylesheet.scss.erb', absolute_file_path

  append_to_file 'config/initializers/workarea.rb' do
    "\nWorkarea::Plugin.append_stylesheets('storefront.components', '#{relative_file_path}')\n"
  end
end

#create_view_modelObject



26
27
28
29
30
# File 'lib/generators/workarea/content_block_type/content_block_type_generator.rb', line 26

def create_view_model
  return if options['skip-view-model']
  file_path = "app/view_models/workarea/storefront/content_blocks/#{file_name}_view_model.rb"
  template('view_model.rb.erb', file_path)
end

#update_configurationObject



32
33
34
35
36
37
38
# File 'lib/generators/workarea/content_block_type/content_block_type_generator.rb', line 32

def update_configuration
  unless File.exist?("#{destination_root}/#{initializer_path}")
    template('initializer.rb', initializer_path)
  end

  inject_into_file initializer_path, configuration, before: "\nend"
end