Class: SolidusOpenPay::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/solidus_open_pay/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#alert_no_classic_frontend_supportObject



80
81
82
83
84
85
86
87
88
89
# File 'lib/generators/solidus_open_pay/install/install_generator.rb', line 80

def alert_no_classic_frontend_support
  support_code_for(:classic_frontend) do
    message = <<~TEXT
      For solidus_frontend compatibility, please use the deprecated version 0.x.
      The new version of this extension only supports Solidus Starter Frontend.
      No frontend code has been copied to your application.
    TEXT
    say_status :error, set_color(message.tr("\n", ' '), :red), :red
  end
end

#install_solidus_backend_supportObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/solidus_open_pay/install/install_generator.rb', line 31

def install_solidus_backend_support
  support_code_for(:backend) do
    append_file(
      'vendor/assets/javascripts/spree/backend/all.js',
      "//= require spree/backend/solidus_open_pay\n"
    )
    inject_into_file(
      'vendor/assets/stylesheets/spree/backend/all.css',
      " *= require spree/backend/solidus_open_pay\n",
      before: %r{\*/},
      verbose: true
    )
  end
end

#install_solidus_core_supportObject



24
25
26
27
28
29
# File 'lib/generators/solidus_open_pay/install/install_generator.rb', line 24

def install_solidus_core_support
  directory 'config/initializers', 'config/initializers'
  rake 'railties:install:migrations FROM=solidus_open_pay'
  run 'bin/rails db:migrate' if options[:migrate]
  route "mount SolidusOpenPay::Engine, at: '#{solidus_mount_point}solidus_open_pay'"
end

#install_solidus_starter_frontend_supportObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/generators/solidus_open_pay/install/install_generator.rb', line 46

def install_solidus_starter_frontend_support
  support_code_for(:starter_frontend) do
    directory 'app', 'app'
    append_file(
      'app/assets/javascripts/solidus_starter_frontend.js',
      "//= require spree/frontend/solidus_open_pay\n"
    )
    inject_into_file(
      'app/assets/stylesheets/solidus_starter_frontend.css',
      " *= require spree/frontend/solidus_open_pay\n",
      before: %r{\*/},
      verbose: true
    )

    spec_paths =
      case options[:specs]
      when 'all' then %w[spec]
      when 'frontend'
        %w[
          spec/spec_helper.rb
          spec/support
        ]
      end

    spec_paths.each do |path|
      if engine.root.join(path).directory?
        directory engine.root.join(path), path
      else
        template engine.root.join(path), path
      end
    end
  end
end

#normalize_components_optionsObject



16
17
18
19
20
21
22
# File 'lib/generators/solidus_open_pay/install/install_generator.rb', line 16

def normalize_components_options
  @components = {
    backend: options[:backend],
    starter_frontend: options[:frontend] == 'starter',
    classic_frontend: options[:frontend] == 'classic'
  }
end