Module: Edifice::Controller

Defined in:
lib/edifice/controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(controller) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/edifice/controller.rb', line 3

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
end

Instance Method Details

#layout_nameObject



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

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



13
14
15
16
17
18
19
20
21
# File 'lib/edifice/controller.rb', line 13

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



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

def view_name
  @view_name || 'no_view'
end

#view_name_normalizedObject



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

def view_name_normalized
  view_name.camelcase(:lower)
end

#view_pathObject



29
30
31
# File 'lib/edifice/controller.rb', line 29

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

#view_path_normalizedObject



33
34
35
# File 'lib/edifice/controller.rb', line 33

def view_path_normalized
  view_path.camelcase(:lower)
end

#write_edifice_headersObject



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

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