Class: Ramaze::Controller

Inherits:
Object show all
Includes:
Innate::Node, Innate::Traited
Defined in:
lib/ramaze/controller.rb

Direct Known Subclasses

Controller, DefaultController

Constant Summary collapse

CONTROLLER_LIST =
Set.new
IRREGULAR_MAPPING =
{
  'Controller' => nil,
  'MainController' => '/'
}

Class Method Summary collapse

Class Method Details

.appObject



95
96
97
# File 'lib/ramaze/controller.rb', line 95

def self.app
  App[ancestral_trait[:app]]
end

.engine(name) ⇒ Object



59
60
61
# File 'lib/ramaze/controller.rb', line 59

def self.engine(name)
  provide(:html, name.to_sym)
end

.generate_mapping(klass_name = self.name) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/ramaze/controller.rb', line 72

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



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ramaze/controller.rb', line 83

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

.mappingObject



63
64
65
# File 'lib/ramaze/controller.rb', line 63

def self.mapping
  Ramaze.to(self)
end

.optionsObject



99
100
101
102
# File 'lib/ramaze/controller.rb', line 99

def self.options
  return unless app = self.app
  app.options
end

.setupObject



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.first

    begin
      controller.mapping
    rescue
      controller.map '/'
    end

    controller.setup_procedure
  else
    CONTROLLER_LIST.each do |controller|
      controller.setup_procedure
    end
  end
end

.setup_procedureObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/ramaze/controller.rb', line 48

def self.setup_procedure
  unless ancestral_trait[:provide_set]
    engine(:Etanni)
    trait(:provide_set => false)
  end

  return if trait[:skip_controller_map]

  map(generate_mapping(name))
end