Sha256: 3aa7cdcaa045de7cd59cbe16dd8fd55d41780aa53bf9c2f90553e4330866f386

Contents?: true

Size: 1.38 KB

Versions: 29

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require_relative "../../lib/plutonium_generators"

module Pu
  module Eject
    class ShellGenerator < Rails::Generators::Base
      include PlutoniumGenerators::Generator

      source_root File.expand_path("templates", __dir__)

      desc "Eject layout shell (i.e header, sidebar) into your own project"

      class_option :dest, type: :string

      def start
        destination_dir = (destination_portal == "main_app") ? "app/views/" : "packages/#{destination_portal}/app/views"
        [
          "plutonium/_resource_header.html.erb",
          "plutonium/_resource_sidebar.html.erb"
        ].each do |file|
          copy_file Plutonium.root.join("app", "views", file), Rails.root.join(destination_dir, file)
        end
      rescue => e
        exception "#{self.class} failed:", e
      end

      private

      def destination_portal
        @destination_portal || select_portal(options[:dest], msg: "Select destination portal")
      end

      def copy_file(source_path, destination_path)
        if File.exist?(source_path)
          FileUtils.mkdir_p(File.dirname(destination_path))
          FileUtils.cp(source_path, destination_path)
          say_status("info", "Copied #{source_path} to #{destination_path}", :green)
        else
          say_status("error", "Source file #{source_path} does not exist", :red)
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
plutonium-0.18.5 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.18.4 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.18.3 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.18.2 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.18.1 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.18.0 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.16.5 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.16.4 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.16.3 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.16.1 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.16.0 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.15.24 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.15.23 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.15.22 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.15.21 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.15.20 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.15.19 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.15.18 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.15.17 lib/generators/pu/eject/shell/shell_generator.rb
plutonium-0.15.16 lib/generators/pu/eject/shell/shell_generator.rb