Class: Ramaze::Controller
- Inherits:
-
Object
show all
- Includes:
- Innate::Node, Innate::Traited
- Defined in:
- lib/ramaze/controller.rb
Constant Summary
collapse
- CONTROLLER_LIST =
Set.new
- IRREGULAR_MAPPING =
{
'Controller' => nil,
'MainController' => '/'
}
Class Method Summary
collapse
Class Method Details
93
94
95
|
# File 'lib/ramaze/controller.rb', line 93
def self.app
App[ancestral_trait[:app]]
end
|
.engine(name) ⇒ Object
57
58
59
|
# File 'lib/ramaze/controller.rb', line 57
def self.engine(name)
provide(:html, name.to_sym)
end
|
.generate_mapping(klass_name = self.name) ⇒ Object
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/ramaze/controller.rb', line 70
def self.generate_mapping(klass_name = self.name)
chunks = klass_name.to_s.split(/::/)
return if chunks.empty?
last = chunks.last
return IRREGULAR_MAPPING[last] if IRREGULAR_MAPPING.key?(last)
last.sub!(/Controller$/, '')
'/' << chunks.map{|chunk| chunk.snake_case }.join('/')
end
|
.inherited(into) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/ramaze/controller.rb', line 20
def self.inherited(into)
Innate::Node.included(into)
into.helper(:layout)
CONTROLLER_LIST << into
into.trait :skip_node_map => true
end
|
.map(location, app_name = nil) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/ramaze/controller.rb', line 81
def self.map(location, app_name = nil)
if app_name
trait :app => app_name
else
app_name = ancestral_trait[:app]
end
trait :skip_controller_map => true
App.find_or_create(app_name).map(location, self)
end
|
61
62
63
|
# File 'lib/ramaze/controller.rb', line 61
def self.mapping
Ramaze.to(self)
end
|
97
98
99
100
|
# File 'lib/ramaze/controller.rb', line 97
def self.options
return unless app = self.app
app.options
end
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/ramaze/controller.rb', line 27
def self.setup
case CONTROLLER_LIST.size
when 0
require 'ramaze/controller/default'
when 1
controller = CONTROLLER_LIST.to_a.first
begin
controller.mapping
rescue
controller.map '/'
end
controller.setup_procedure
else
CONTROLLER_LIST.each do |controller|
controller.setup_procedure
end
end
end
|
.setup_procedure ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/ramaze/controller.rb', line 48
def self.setup_procedure
unless ancestral_trait[:provide_set]
engine(:Etanni)
trait(:provide_set => false)
end
map(generate_mapping(name)) unless trait[:skip_controller_map]
end
|