Class: Toppings::Generators::Install::GroupGenerator

Inherits:
BaseGenerator
  • Object
show all
Includes:
Helper::BaseFileHelper
Defined in:
lib/toppings/generators/install/group_generator.rb

Overview

the GroupGenerator class provides some default behavior for a given generator, that extends the GroupGenerator.

For each groupfile a new group folder is created and a relative base file is added to it, where included templates will be registered with appropriate import statements.

Template pathes and target pathes become available by convention over the given specific classes base name, where the base name is build upon the classes name with stripped Generator suffix.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseGenerator

#notify_invoke

Methods included from Helper::PathHelper

#root_file_path, #stylesheets_path

Class Method Details

.source_rootString

provides a path build upon the base name of a class as source root for the thor template engine.

Returns:

  • (String)

    path to the class namespaced template folder



29
30
31
# File 'lib/toppings/generators/install/group_generator.rb', line 29

def source_root
  template_path.join(base_name)
end

.templatesSet

registered templates for a group, that will be made available in the setup

Returns:

  • (Set)

    of registered templates



58
59
60
# File 'lib/toppings/generators/install/group_generator.rb', line 58

def templates
  @templates ||= Set.new
end

.with_template(file, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/toppings/generators/install/group_generator.rb', line 42

def with_template(file, options = {})
  options = options.reverse_merge(namespaced: true)

  library    = options[:vendor_library]
  namespaced = options[:namespaced]
  path       = options[:template_folder]

  Toppings::SASS_DEPENDENCIES.add(library) if library
  file = library && namespaced ? "#{library}.#{file}" : file.to_s
  file = Pathname.new(path).join(file) if path
  templates << file
end

.with_templates(*files) ⇒ Array

dsl method to register certain template files, that should be made available for the specific generator.

Parameters:

  • files (*String)

    one or more template names

Returns:

  • (Array)

    returns the list of registered templates



38
39
40
# File 'lib/toppings/generators/install/group_generator.rb', line 38

def with_templates(*files)
  files.each { |file| templates << file }
end

Instance Method Details

#create_base_import_fileObject

creating the relative base file for a generator group and appending it to the root file located in the stylesheet root.



65
66
67
68
# File 'lib/toppings/generators/install/group_generator.rb', line 65

def create_base_import_file
  create_file index_file_path, skip: true
  append_import relative_index_name, root_file_path
end

#create_template_filesObject

building templated files based on the beforehand registered template files



71
72
73
# File 'lib/toppings/generators/install/group_generator.rb', line 71

def create_template_files
  templates.each { |file| group_template_file(file) } if self.templates?
end