Changeset 3861
- Timestamp:
- 03/13/06 15:54:33 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/layout.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r3856 r3861 1 1 *SVN* 2 3 * Avoid hitting the filesystem when using layouts by using a File.directory? cache. [Stefan Kaes, Nicholas Seckar] 4 5 * Simplify ActionController::Base#controller_path [Nicholas Seckar] 2 6 3 7 * Added simple alert() notifications for RJS exceptions when config.action_view.debug_rjs = true. [Sam Stephenson] trunk/actionpack/lib/action_controller/base.rb
r3860 r3861 349 349 # Converts the class name from something like "OneModule::TwoModule::NeatController" to "one_module/two_module/neat". 350 350 def controller_path 351 unless @controller_path 352 components = self.name.to_s.split('::') 353 components[-1] = $1 if /^(.*)Controller$/ =~ components.last 354 @controller_path = components.map { |name| name.underscore }.join('/') 355 end 356 357 @controller_path 351 @controller_path ||= name.gsub(/Controller$/, '').underscore 358 352 end 359 353 trunk/actionpack/lib/action_controller/layout.rb
r3852 r3861 193 193 conditions.inject({}) {|hash, (key, value)| hash.merge(key => [value].flatten.map {|action| action.to_s})} 194 194 end 195 196 def layout_directory_exists_cache 197 @@layout_directory_exists_cache ||= Hash.new do |h, dirname| 198 h[dirname] = File.directory? dirname 199 end 200 end 195 201 end 196 202 … … 203 209 204 210 active_layout = case layout 211 when String then layout 205 212 when Symbol then send(layout) 206 213 when Proc then layout.call(self) 207 when String then layout208 214 end 209 215 … … 211 217 # but auto-discovered layouts derived from a nested controller will contain a slash, though be relative 212 218 # to the 'layouts' directory so we have to check the file system to infer which case the layout name came from. 213 nested_controller = File.directory?(File.dirname(File.join(self.class.template_root, 'layouts', active_layout))) if active_layout 214 active_layout.include?('/') && !nested_controller ? active_layout : "layouts/#{active_layout}" if active_layout 219 if active_layout 220 if active_layout.include?('/') && ! layout_directory?(active_layout) 221 active_layout 222 else 223 "layouts/#{active_layout}" 224 end 225 end 215 226 end 216 227 … … 281 292 end 282 293 end 294 295 # Does a layout directory for this class exist? 296 # we cache this info in a class level hash 297 def layout_directory?(layout_name) 298 template_path = File.join(self.class.view_root, 'layouts', layout_name) 299 dirname = File.dirname(template_path) 300 self.class.send(:layout_directory_exists_cache)[dirname] 301 end 283 302 end 284 303 end