aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
blob: aa9b45c5a50c27f64164c7d3905b9c2adc3e4222 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'rails/generators/rails/resource/resource_generator'

module Rails
  module Generators
    class ScaffoldGenerator < ResourceGenerator #metagenerator
      remove_hook_for :resource_controller
      remove_class_option :actions

      class_option :stylesheets, :type => :boolean, :desc => "Generate Stylesheets"
      class_option :stylesheet_engine, :desc => "Engine for Stylesheets"

      hook_for :scaffold_controller, :required => true

      def copy_stylesheets_file
        if behavior == :invoke && options.stylesheets?
          template "scaffold.#{stylesheet_extension}", "app/assets/stylesheets/scaffold.#{stylesheet_extension}"
        end
      end

      hook_for :assets do |assets|
        invoke assets, [controller_name]
      end

      private

      def stylesheet_extension
        options.stylesheet_engine.present? ?
          "css.#{options.stylesheet_engine}" : "css"
      end
    end
  end
end