Sha256: cc6a782937e0db9f1c368637478b487c755deda7c5f05e71b489846ecfc0baa1

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

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

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

      source_root File.expand_path("templates", __dir__)

      desc "Eject layout views into your own project"

      class_option :rodauth, type: :boolean

      def start
        destination_dir = (destination_portal == "main_app") ? "app/views/" : "packages/#{destination_portal}/app/views/"
        [
          "layouts/resource.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
        portal_option(:dest, prompt: "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

6 entries across 6 versions & 1 rubygems

Version Path
plutonium-0.19.2 lib/generators/pu/eject/layout/layout_generator.rb
plutonium-0.19.1 lib/generators/pu/eject/layout/layout_generator.rb
plutonium-0.19.0 lib/generators/pu/eject/layout/layout_generator.rb
plutonium-0.18.8 lib/generators/pu/eject/layout/layout_generator.rb
plutonium-0.18.7 lib/generators/pu/eject/layout/layout_generator.rb
plutonium-0.18.6 lib/generators/pu/eject/layout/layout_generator.rb