Sha256: d7109f539c3d46cd747ab32349bdb5e967f710e82d6639899f3bbf04fcff5220

Contents?: true

Size: 1.97 KB

Versions: 25

Compression:

Stored size: 1.97 KB

Contents

require 'rails/generators/active_record'

module Lalala
  module Generators

    # This class is stolen from active admin
    class InstallGenerator < ::ActiveRecord::Generators::Base

      desc "Installs Active Admin and generates the necessary migrations"
      argument :name, :type => :string, :default => "AdminUser"

      hook_for :users, :default => "devise", :desc => "Admin user generator to run. Skip with --skip-users"

      def self.source_root
        @_active_admin_source_root ||= File.expand_path("../templates", __FILE__)
      end

      def setup_routes
        remove_file("config/routes.rb")
        template 'routes.rb.erb', 'config/routes.rb'
      end

      def copy_initializer
        @underscored_user_name = name.underscore
        template 'active_admin.rb.erb', 'config/initializers/active_admin.rb'
      end

      def setup_errors
        empty_directory "app/controllers"
        template 'errors_controller.rb', 'app/controllers/errors_controller.rb'
      end

      def setup_pages
        empty_directory "app/pages"
        template 'application_page.rb', 'app/pages/application_page.rb'
        empty_directory "app/controllers"
        template 'pages_controller.rb', 'app/controllers/pages_controller.rb'
        empty_directory "app/admin"
        template 'admin_pages.rb', 'app/admin/admin_pages.rb'
      end

      def setup_directory
        empty_directory "app/admin"
        template 'dashboard.rb', 'app/admin/dashboard.rb'
        if options[:users].present?
          @user_class = name
          template 'admin_user.rb.erb', "app/admin/#{name.underscore.pluralize}.rb"
        end
      end

      def create_assets
        generate "lalala:assets"
      end

      def create_migrations
        Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
          name = File.basename(filepath)
          migration_template "migrations/#{name}", "db/migrate/#{name.gsub(/^\d+_/,'')}"
          sleep 1
        end
      end

    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
lalala-4.0.0.dev.94 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.92 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.90 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.84 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.80 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.79 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.78 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.77 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.74 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.73 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.72 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.71 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.66 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.65 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.64 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.63 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.62 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.61 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.60 lib/generators/lalala/install/install_generator.rb
lalala-4.0.0.dev.59 lib/generators/lalala/install/install_generator.rb