Class: ShopifyApp::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#create_and_inject_into_omniauth_initializerObject


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/shopify_app/install/install_generator.rb', line 27

def create_and_inject_into_omniauth_initializer
  unless File.exist?("config/initializers/omniauth.rb")
    copy_file('omniauth.rb', 'config/initializers/omniauth.rb')
  end

  inject_into_file(
    'config/initializers/omniauth.rb',
    File.read(File.expand_path(find_in_source_paths('shopify_provider.rb'))),
    after: "Rails.application.config.middleware.use(OmniAuth::Builder) do\n"
  )
end

#create_embedded_app_layoutObject


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/shopify_app/install/install_generator.rb', line 39

def create_embedded_app_layout
  return unless embedded_app?

  copy_file('embedded_app.html.erb', 'app/views/layouts/embedded_app.html.erb')
  copy_file('_flash_messages.html.erb', 'app/views/layouts/_flash_messages.html.erb')

  if ShopifyApp.use_webpacker?
    copy_file('shopify_app.js', 'app/javascript/shopify_app/shopify_app.js')
    copy_file('flash_messages.js', 'app/javascript/shopify_app/flash_messages.js')
    copy_file('shopify_app_index.js', 'app/javascript/shopify_app/index.js')
    append_to_file('app/javascript/packs/application.js', "require(\"shopify_app\")\n")
  else
    copy_file('shopify_app.js', 'app/assets/javascripts/shopify_app.js')
    copy_file('flash_messages.js', 'app/assets/javascripts/flash_messages.js')
  end
end

#create_session_store_initializerObject


23
24
25
# File 'lib/generators/shopify_app/install/install_generator.rb', line 23

def create_session_store_initializer
  copy_file('session_store.rb', 'config/initializers/session_store.rb')
end

#create_shopify_app_initializerObject


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

def create_shopify_app_initializer
  @application_name = format_array_argument(options['application_name'])
  @scope = format_array_argument(options['scope'])
  @api_version = options['api_version'] || ShopifyAPI::Meta.admin_versions.find(&:latest_supported).handle

  template('shopify_app.rb', 'config/initializers/shopify_app.rb')
end

#create_user_agent_initializerObject


56
57
58
# File 'lib/generators/shopify_app/install/install_generator.rb', line 56

def create_user_agent_initializer
  template('user_agent.rb', 'config/initializers/user_agent.rb')
end

#insert_hosts_into_development_configObject


64
65
66
67
68
69
70
# File 'lib/generators/shopify_app/install/install_generator.rb', line 64

def insert_hosts_into_development_config
  inject_into_file(
    'config/environments/development.rb',
    "  config.hosts = (config.hosts rescue []) << /\\h+.ngrok.io/\n",
    after: "Rails.application.configure do\n"
  )
end

#mount_engineObject


60
61
62
# File 'lib/generators/shopify_app/install/install_generator.rb', line 60

def mount_engine
  route("mount ShopifyApp::Engine, at: '/'")
end