Sha256: 050adee1a0980d703fde03b371219cd6a0f350cfa3af8ed46ee4af36fda1f872

Contents?: true

Size: 1.2 KB

Versions: 42

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'rails'
require 'rails/generators'

module Solidus
  module Views
    class OverrideGenerator < ::Rails::Generators::Base
      def self.views_folder
        Spree::Frontend::Engine.root.join('app', 'views', 'spree')
      end

      VIEWS = Dir.glob(views_folder.join('**', '*'))

      desc "Override solidus frontend views in your app. You can either provide single files or complete folders."

      class_option :only,
        type: :string,
        default: nil,
        desc: "Name of file or folder to copy exclusively. Can be a substring."

      source_root views_folder

      def copy_views
        views_to_copy.each do |file|
          next if File.directory?(file)
          dest_file = Pathname.new(file).relative_path_from(source_dir)
          copy_file file, Rails.root.join('app', 'views', 'spree', dest_file)
        end
      end

      private

      def views_to_copy
        if @options['only']
          VIEWS.select do |v|
            Pathname.new(v).relative_path_from(source_dir).to_s.include?(@options['only'])
          end
        else
          VIEWS
        end
      end

      def source_dir
        self.class.views_folder
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
solidus_frontend-2.9.6 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.8.6 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.9.5 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.9.4 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.6.6 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.7.4 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.8.5 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.9.3 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.9.2 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.10.0.beta1 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.7.3 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.6.5 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.9.1 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.9.0 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.9.0.rc.1 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.8.4 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.8.3 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.7.2 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.6.4 lib/generators/solidus/views/override_generator.rb
solidus_frontend-2.8.2 lib/generators/solidus/views/override_generator.rb