Sha256: 4723b3aac7a48e186e0da9c3e765af118beced19eb5b5845c3e577707210e471

Contents?: true

Size: 1.64 KB

Versions: 40

Compression:

Stored size: 1.64 KB

Contents

require_relative "base_generator"

module Generators
  module Avo
    class EjectGenerator < BaseGenerator
      argument :filename, type: :string, required: true

      source_root ::Avo::Engine.root

      namespace "avo:eject"

      TEMPLATES = {
        logo: "app/views/avo/partials/_logo.html.erb",
        head: "app/views/avo/partials/_head.html.erb",
        header: "app/views/avo/partials/_header.html.erb",
        footer: "app/views/avo/partials/_footer.html.erb",
        pre_head: "app/views/avo/partials/_pre_head.html.erb",
        scripts: "app/views/avo/partials/_scripts.html.erb",
        sidebar_extra: "app/views/avo/partials/_sidebar_extra.html.erb",
        profile_menu_extra: "app/views/avo/partials/_profile_menu_extra.html.erb",
      }

      def handle
        if @filename.starts_with?(":")
          template_id = path_to_sym @filename
          template_path = TEMPLATES[template_id]

          if path_exists? template_path
            eject template_path
          else
            say("Failed to find the `#{template_id.to_sym}` template.", :yellow)
          end
        elsif path_exists? @filename
          eject @filename
        else
          say("Failed to find the `#{@filename}` template.", :yellow)
        end
      end

      no_tasks do
        def path_to_sym(filename)
          template_id = filename.dup
          template_id[0] = ""
          template_id.to_sym
        end

        def path_exists?(path)
          path.present? && File.file?(::Avo::Engine.root.join(path))
        end

        def eject(path)
          copy_file ::Avo::Engine.root.join(path), ::Rails.root.join(path)
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
avo-2.53.0 lib/generators/avo/eject_generator.rb
avo-2.52.0 lib/generators/avo/eject_generator.rb
avo-2.49.0 lib/generators/avo/eject_generator.rb
avo-2.48.0 lib/generators/avo/eject_generator.rb
avo-2.47.0 lib/generators/avo/eject_generator.rb
avo-3.0.1.beta2 lib/generators/avo/eject_generator.rb
avo-3.0.0.beta1 lib/generators/avo/eject_generator.rb
avo-3.0.1.beta1 lib/generators/avo/eject_generator.rb
avo-3.0.0.pre17 lib/generators/avo/eject_generator.rb
avo-3.0.0.pre18 lib/generators/avo/eject_generator.rb
avo-3.0.0.pre14 lib/generators/avo/eject_generator.rb
avo-3.0.0.pre16 lib/generators/avo/eject_generator.rb
avo-3.0.0.pre15 lib/generators/avo/eject_generator.rb
avo-3.0.0.pre13 lib/generators/avo/eject_generator.rb
avo-2.46.0 lib/generators/avo/eject_generator.rb
avo-2.45.0 lib/generators/avo/eject_generator.rb
avo-2.44.0 lib/generators/avo/eject_generator.rb
avo-2.43.0 lib/generators/avo/eject_generator.rb
avo-2.42.2 lib/generators/avo/eject_generator.rb
avo-2.42.1 lib/generators/avo/eject_generator.rb