Class: UltraLightWizard::Generators::WizardGenerator

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

Instance Method Summary collapse

Instance Method Details

#argumentsObject



5
6
7
8
9
10
# File 'lib/generators/ultra_light_wizard/wizard_generator.rb', line 5

def arguments
  args.inject({}) do |output, arg|
    arg_parts = arg.split(':')
    output.merge(arg_parts.first => arg_parts.last)
  end
end

#copy_configObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/ultra_light_wizard/wizard_generator.rb', line 21

def copy_config
  template "app/controllers/wizard_steps_controller.rb.erb", "app/controllers/#{file_path}_#{step_alias.pluralize}_controller.rb"
  template "app/helpers/wizard_steps_helper.rb.erb", "app/helpers/#{file_path}_#{step_alias.pluralize}_helper.rb"
  template "app/views/wizard_step_navigation_view.html.erb", "app/views/#{file_path}_#{step_alias.pluralize}/_#{step_alias}_navigation.html.erb"
  steps.each do |step|
    @wizard_step = step
    template "app/models/wizard_step_model.rb.erb", "app/models/#{file_path}/#{step}.rb"
    template "app/views/wizard_step_view.html.erb", "app/views/#{file_path}_#{step_alias.pluralize}/#{step}.html.erb"
  end
  wizard_route_content = <<-CONTENT
resources :#{plural_file_name}, only: [:create, :show] do
    resources :#{file_path}_#{step_alias.pluralize}, only: [:edit, :update]
  end
  CONTENT
  routes_content = File.new(Rails.root.join('config', 'routes.rb')).read
  route wizard_route_content unless routes_content.include?(wizard_route_content)
end

#step_aliasObject



12
13
14
# File 'lib/generators/ultra_light_wizard/wizard_generator.rb', line 12

def step_alias
  arguments['step_alias'] || 'step'
end

#stepsObject



16
17
18
# File 'lib/generators/ultra_light_wizard/wizard_generator.rb', line 16

def steps
  arguments['steps'].to_s.split(',').map(&:strip)
end