forked from padrino/padrino-framework
/
padrino-gen.rb
67 lines (58 loc) · 1.77 KB
/
padrino-gen.rb
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'padrino-core/tasks'
module Padrino
##
# This module it's used for register generators
#
# Can be useful for 3rd party generators:
#
# # custom_generator.rb
# class CustomGenerator < Thor::Group
# Padrino::Generators.add_generator(:custom_generator, self)
# end
#
# Now for handle generators in padrino you need to add it to into +load_paths+
#
# Padrino::Generators.load_paths << "custom_generator.rb"
#
module Generators
DEV_PATH = File.expand_path("../../", File.dirname(__FILE__))
class << self
##
# Here we store our generators paths
#
def load_paths
@_files ||= []
end
##
# Return a ordered list of task with their class
#
def mappings
@_mappings ||= SupportLite::OrderedHash.new
end
##
# Gloabl add a new generator class to +padrino-gen+
#
def add_generator(name, klass)
mappings[name] = klass
end
##
# Load Global Actions and Component Actions then all files in +load_path+.
#
def load_components!
require 'padrino-gen/generators/actions'
require 'padrino-gen/generators/components/actions'
# Require all generator components
Dir[File.dirname(__FILE__) + '/padrino-gen/generators/components/**/*.rb'].each { |file| require file }
load_paths.flatten.each { |file| require file }
end
end
end # Generators
end # Padrino
##
# We add our generators to Padrino::Genererator
#
Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/padrino-gen/generators/{project,app,mailer,controller,model,migration}.rb']
##
# We add our tasks to padrino-core
#
Padrino::Tasks.files << Dir[File.dirname(__FILE__) + "/padrino-gen/padrino-tasks/**/*.rb"]