Sha256: 48b9f8a447d53a60f2afd17b8bb830e78b81556285e25c9e38c6c259466ced7e

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require 'generators/resource_helpers'

module EasyCms
  module Generators
    class NamespaceGenerator < Rails::Generators::Base
      include ResourceHelpers

      source_root File.expand_path("../templates", __FILE__)
      desc "This generator create a Namespace to CMS"
      argument :namespace, :type => :string, :required => :true

      def generate_base_controller
        file_name = "app/controllers/#{namespace}/base_controller.rb"
        template './controllers/base_controller.erb', file_name, options_params unless File.exist?(file_name)
      end

      def generate_layout
        file_name = "app/views/layouts/#{namespace}.html.erb"
        template "./layouts/layout.html.erb", file_name, options_params unless File.exist?(file_name)
      end

      def generate_assets
        file_name_js = "app/assets/javascripts/#{namespace}.js"
        file_name_stylesheet = "app/assets/stylesheets/#{namespace}.scss"

        template "./assets/base_javascript.erb", file_name_js   unless File.exist?(file_name_js)
        template "./assets/base_scss.erb", file_name_stylesheet unless File.exist?(file_name_stylesheet)
      end

      def add_initializers_assets
        prepend_to_file 'config/initializers/assets.rb' do 
          "Rails.application.config.assets.precompile += %w( #{namespace}.js )\n"
        end
        prepend_to_file 'config/initializers/assets.rb' do 
          "Rails.application.config.assets.precompile += %w( #{namespace}.scss )\n"
        end
      end

    private
      def options_params
        { :namespace => namespace }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
easy_cms-0.1.0 lib/generators/easy_cms/namespace/namespace_generator.rb