Class: Heya::CampaignGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/heya/campaign/campaign_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_campaign_templateObject



8
9
10
11
12
13
14
# File 'lib/generators/heya/campaign/campaign_generator.rb', line 8

def copy_campaign_template
  application_campaign = "app/campaigns/application_campaign.rb"
  unless File.exist?(application_campaign)
    template File.expand_path("../install/templates/application_campaign.rb", __dir__), application_campaign
  end
  template "campaign.rb", "app/campaigns/#{file_name.underscore}_campaign.rb"
end

#copy_test_templatesObject



47
48
49
50
51
# File 'lib/generators/heya/campaign/campaign_generator.rb', line 47

def copy_test_templates
  if preview_path
    template "preview.rb", preview_path.join("#{file_name.underscore}_campaign_preview.rb")
  end
end

#copy_view_templatesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/heya/campaign/campaign_generator.rb', line 16

def copy_view_templates
  selection =
    if defined?(Maildown)
      puts <<~MSG
        What type of views would you like to generate?
          1. Multipart (text/html)
          2. Maildown (markdown)
      MSG

      ask(">")
    else
      "1"
    end

  template_method =
    case selection
    when "1"
      method(:action_mailer_template)
    when "2"
      method(:maildown_template)
    else
      abort "Error: must be a number [1-2]"
    end

  steps.each do |step|
    step, _wait = step.split(":")
    @step = step
    template_method.call(step)
  end
end