Sha256: 864f22a55113255c7998cec94555d3c21c96972930cbc276ccbce737ab6ef855

Contents?: true

Size: 1.72 KB

Versions: 5

Compression:

Stored size: 1.72 KB

Contents

require 'rails'

module Alchemy
  module Generators
    class ScaffoldGenerator < ::Rails::Generators::Base

      ALCHEMY_VIEWS = %w(breadcrumb language_links messages navigation notifications search)

      desc "This generator generates the Alchemy scaffold."
      class_option :copy_views, :default => false, :type => :boolean, :desc => "Copy all Alchemy views into your app.", :aliases => '-v'
      source_root File.expand_path('templates', File.dirname(__FILE__))

      def create_config_dir
        empty_directory "#{Rails.root}/config/alchemy"
      end

      def create_view_dirs
        empty_directory Rails.root.join("app/views/alchemy/elements")
        empty_directory Rails.root.join("app/views/alchemy/page_layouts")
      end

      def copy_view_dirs
        copy_alchemy_views if @options['copy_views']
      end

      def copy_config
        copy_file "#{config_path}/config.yml", "#{Rails.root}/config/alchemy/config.yml"
      end

      def copy_files
        copy_file "#{File.dirname(__FILE__)}/files/elements.yml", "#{Rails.root}/config/alchemy/elements.yml"
        template "page_layouts.yml.tt", "#{Rails.root}/config/alchemy/page_layouts.yml"
        copy_file "#{File.dirname(__FILE__)}/files/application.html.erb", "#{Rails.root}/app/views/layouts/application.html.erb"
      end

    private

      def config_path
        @config_path ||= File.expand_path('../../../../../config/alchemy', File.dirname(__FILE__))
      end

      def copy_alchemy_views
        ALCHEMY_VIEWS.each do |dir|
          src = File.expand_path("../../../../../app/views/alchemy/#{dir}", File.dirname(__FILE__))
          dest = Rails.root.join('app/views/alchemy', dir)
          directory src, dest
        end
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alchemy_cms-2.6.3 lib/rails/generators/alchemy/scaffold/scaffold_generator.rb
alchemy_cms-2.6.2.1 lib/rails/generators/alchemy/scaffold/scaffold_generator.rb
alchemy_cms-2.6.2 lib/rails/generators/alchemy/scaffold/scaffold_generator.rb
alchemy_cms-2.6.1 lib/rails/generators/alchemy/scaffold/scaffold_generator.rb
alchemy_cms-2.6.0 lib/rails/generators/alchemy/scaffold/scaffold_generator.rb