aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/generators/rails/plugin/plugin_generator.rb
blob: 903f720e12538f01c96cc7ab00226e5cfb2b7f79 (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
33
34
35
36
37
38
39
40
41
42
43
44
module Rails
  module Generators
    class PluginGenerator < NamedBase
      class_option :tasks, :type => :boolean, :aliases => "-t", :default => false,
                           :desc => "When supplied creates tasks base files."

      class_option :generator, :type => :boolean, :aliases => "-g", :default => false,
                               :desc => "When supplied creates generator base files."

      check_class_collision

      def create_root_files
        directory '.', plugin_dir, false # non-recursive
      end

      def create_lib_files
        directory 'lib', plugin_dir('lib'), false # non-recursive
      end

      hook_for :test_framework

      def create_tasks_files
        return unless options[:tasks]
        directory 'tasks', plugin_dir('tasks')
      end

      def create_generator_files
        return unless options[:generator]
        directory 'lib/generators', plugin_dir('lib/generators')
      end

      protected

        def plugin_dir(join=nil)
          if join
            File.join(plugin_dir, join)
          else
            "vendor/plugins/#{file_name}"
          end
        end

    end
  end
end