Sha256: 144656265538baa18d424b40742e51a43f0a62c4afcb9a00c332ec75487ff90a

Contents?: true

Size: 1.37 KB

Versions: 27

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true
require 'rails/generators/base'

module ShopifyApp
  module Generators
    class HomeControllerGenerator < Rails::Generators::Base
      source_root File.expand_path('../templates', __FILE__)

      class_option :with_cookie_authentication, type: :boolean, default: false
      class_option :embedded, type: :string, default: 'true'

      def create_home_controller
        template(home_controller_template, 'app/controllers/home_controller.rb')
      end

      def create_products_controller
        generate("shopify_app:products_controller") unless with_cookie_authentication?
      end

      def create_home_index_view
        template('index.html.erb', 'app/views/home/index.html.erb')
      end

      def add_home_index_route
        route("root :to => 'home#index'")
      end

      private

      def embedded?
        options['embedded'] == 'true'
      end

      def embedded_app?
        ShopifyApp.configuration.embedded_app?
      end

      def with_cookie_authentication?
        options['with_cookie_authentication']
      end

      def home_controller_template
        return 'unauthenticated_home_controller.rb' unless authenticated_home_controller_required?

        'home_controller.rb'
      end

      def authenticated_home_controller_required?
        with_cookie_authentication? || !embedded? || !embedded_app?
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
ruby_shopify_app-1.3.3 lib/generators/shopify_app/home_controller/home_controller_generator.rb
ruby_shopify_app-1.3.2 lib/generators/shopify_app/home_controller/home_controller_generator.rb
ruby_shopify_app-1.3.1 lib/generators/shopify_app/home_controller/home_controller_generator.rb
ruby_shopify_app-1.3.0 lib/generators/shopify_app/home_controller/home_controller_generator.rb
ruby_shopify_app-1.2.0 lib/generators/shopify_app/home_controller/home_controller_generator.rb
ruby_shopify_app-1.1.0 lib/generators/shopify_app/home_controller/home_controller_generator.rb
ruby_shopify_app-1.0.0 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-18.1.3 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-18.1.2 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-18.1.1 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-18.1.0 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-18.0.4 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-18.0.3 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-18.0.2 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-18.0.1 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-18.0.0 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-17.2.1 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-17.2.0 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-17.1.1 lib/generators/shopify_app/home_controller/home_controller_generator.rb
shopify_app-17.1.0 lib/generators/shopify_app/home_controller/home_controller_generator.rb