Module: Rad::Controller::Abstract::Render::ClassMethods

Defined in:
lib/rad/controller/_abstract/render.rb

Instance Method Summary collapse

Instance Method Details

#_find_relative_template(tname, prefixes, format, exact_format, current_dir) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/rad/controller/_abstract/render.rb', line 125

def _find_relative_template tname, prefixes, format, exact_format, current_dir
  tname.must_be.present

  path = nil

  # own templates
  ["/#{controller_name.underscore}/#{tname}", "/#{controller_name.gsub('::', '/')}/#{tname}"].each do |name|
    path ||= rad.template.find_file(name, prefixes, format, exact_format, rad.template.paths)
  end

  # own :actions templates
  ["/#{controller_name.underscore}/actions", "/#{controller_name.gsub('::', '/')}/actions"].each do |name|
    unless path
      path = rad.template.find_file(name, prefixes, format, exact_format, rad.template.paths)
      path = nil if path and (File.read(path) !~ /^.*when.+[^_a-zA-Z0-9]#{tname}[^_a-zA-Z0-9].*$/)
    end
  end

  # superclasses templates
  unless path
    parent = ancestors[1..-1].find{|a| a.respond_to?(:find_relative_template)} #  and a.instance_methods.include?(action)
    if parent and parent != Rad::Controller::Abstract
      path = parent.find_relative_template(tname, prefixes, format, exact_format, current_dir)
    end
  end

  # relative template
  if !path and current_dir
    path = rad.template.relative_path_resolver.find_relative_template(tname, prefixes, format, exact_format, current_dir)
  end

  return path
end

#context_classObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rad/controller/_abstract/render.rb', line 97

def context_class
  unless @context_class
    parent_context_class = nil
    ancestors[1..-1].each do |anc|
      break if parent_context_class = anc.respond_to(:context_class)
    end
    parent_context_class ||= Rad::Controller::Context

    class_name = "#{self.name}::#{self.name.split('::').last}Context"

    # raise "Tempate context #{class_name} already defined!" if Object.const_defined? class_name
    eval "class #{class_name} < #{parent_context_class}; end", TOPLEVEL_BINDING, __FILE__, __LINE__
    @context_class = class_name.constantize
  end
  @context_class
end

#find_relative_template(*args) ⇒ Object



114
115
116
117
118
119
120
121
122
123
# File 'lib/rad/controller/_abstract/render.rb', line 114

def find_relative_template *args
  return _find_relative_template *args unless rad.production?

  # use cache
  @relative_template ||= {}
  unless @relative_template.include? args
    @relative_template[args] = _find_relative_template *args
  end
  @relative_template[args]
end

#layout(layout, options = {}) ⇒ Object



91
92
93
94
95
# File 'lib/rad/controller/_abstract/render.rb', line 91

def layout layout, options = {}
  before options do |controller|
    controller._layout = layout
  end
end