Module: Edifice::Controller

Defined in:
lib/edifice/controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(controller) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/edifice/controller.rb', line 4

def self.included(controller)
  controller.helper_method(:view_path, :view_path_normalized, 
    :view_name, :view_name_normalized, :layout_name)
  
  unless (controller == ActionMailer::Base)
    controller.after_filter(:write_edifice_headers)
  end
  
  controller.class_eval do
    def self.responder
      Edifice::Responder
    end
  end
end

Instance Method Details

#layout_nameObject



52
53
54
# File 'lib/edifice/controller.rb', line 52

def layout_name
  @layout || 'no_layout'
end

#set_edifice_names(view_name, view_path, layout) ⇒ Object

this will get called once per template. So we make sure it only writes for the first



20
21
22
23
24
25
26
27
28
# File 'lib/edifice/controller.rb', line 20

def set_edifice_names(view_name, view_path, layout)
  unless @edifice_names_set
    @view_name = view_name
    @view_path = view_path
    @layout = layout
    
    @edifice_names_set = true
  end
end

#view_nameObject



44
45
46
# File 'lib/edifice/controller.rb', line 44

def view_name
  @view_name || 'no_view'
end

#view_name_normalizedObject



48
49
50
# File 'lib/edifice/controller.rb', line 48

def view_name_normalized
  view_name.camelcase(:lower)
end

#view_pathObject



36
37
38
# File 'lib/edifice/controller.rb', line 36

def view_path
  (@view_path || 'no_controller').gsub('/', '_')
end

#view_path_normalizedObject



40
41
42
# File 'lib/edifice/controller.rb', line 40

def view_path_normalized
  view_path.camelcase(:lower)
end

#write_edifice_headersObject



30
31
32
33
34
# File 'lib/edifice/controller.rb', line 30

def write_edifice_headers
  response.headers['x-edifice-view_path'] = view_path_normalized
  response.headers['x-edifice-view_name'] = view_name_normalized
  response.headers['x-edifice-layout'] = layout_name
end