Changeset 964
- Timestamp:
- 11/12/07 08:18:38 (1 year ago)
- Files:
-
- trunk/lib/merb/abstract_controller.rb (modified) (2 diffs)
- trunk/lib/merb/mixins/render.rb (modified) (1 diff)
- trunk/lib/merb/server.rb (modified) (2 diffs)
- trunk/spec/fixtures/controllers/render_spec_controllers.rb (modified) (1 diff)
- trunk/spec/merb/abstract_controller_spec.rb (added)
- trunk/spec/merb/mail_controller_spec.rb (modified) (1 diff)
- trunk/spec/merb/responder_spec.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/merb/abstract_controller.rb
r907 r964 10 10 11 11 cattr_accessor :_abstract_subclasses 12 cattr_accessor :_ globs12 cattr_accessor :_template_path_cache 13 13 self._abstract_subclasses = [] 14 self._template_path_cache 14 15 15 16 class << self … … 54 55 call_filters(after_filters) 55 56 @_benchmarks[:after_filters_time] = Time.now - start if after_filters 57 end 58 59 60 # Adds a path to the template path cache. This is requried for 61 # any view templates or layouts to be found during renering. 62 # 63 # Example 64 # 65 # Merb::ActiveController.add_path_to_template_cache('/full/path/to/template.html.erb') 66 def self.add_path_to_template_cache(template) 67 arry = template.split("/").last.split(".") 68 return false if template == "" || arry.size != 3 69 key = template.split(".")[0..-2].join(".") 70 self._template_path_cache[key] = template 71 end 72 73 # Resets the template_path_cache to an empty hash 74 def self.reset_template_path_cache! 75 self._template_path_cache = {} 56 76 end 57 77 trunk/lib/merb/mixins/render.rb
r958 r964 402 402 def glob_template(path, opts = {}) 403 403 the_template = "#{path}.#{@_template_format}" 404 Merb::AbstractController._ globs[the_template] || (@_merb_unmatched = (the_template + ".*"); nil)404 Merb::AbstractController._template_path_cache[the_template] || (@_merb_unmatched = (the_template + ".*"); nil) 405 405 end 406 406 trunk/lib/merb/server.rb
r918 r964 271 271 end 272 272 273 def load_controller_globs 273 def load_controller_template_path_cache 274 275 # This gets all templates set in the controllers template roots 274 276 template_paths = Merb::AbstractController._abstract_subclasses.map do |klass| 275 277 Object.full_const_get(klass)._template_root 276 278 end.uniq.map do |path| 277 279 Dir["#{path}/**/*"] 278 end.flatten.compact.uniq 279 280 out = {} 280 end 281 282 # This gets the templates that might be created outside controllers 283 # template roots. eg app/views/shared/* 284 template_paths << Dir["#{MERB_ROOT}/app/views/**/*"] 285 286 template_paths = template_paths.flatten.compact.uniq 287 288 Merb::AbstractController.reset_template_path_cache! 289 281 290 template_paths.each do |template| 282 arry = template.split("/").last.split(".") 283 next if template == "" || arry.size != 3 284 285 key = template.split(".")[0..-2].join(".") 286 out[key] = template 287 end 288 Merb::AbstractController._globs = out 291 Merb::AbstractController.add_path_to_template_cache(template) 292 end 289 293 end 290 294 … … 294 298 end 295 299 load_action_arguments 296 load_controller_ globs300 load_controller_template_path_cache 297 301 @app_loaded = true 298 302 (@after_app_blocks || []).each { |b| b.call } trunk/spec/fixtures/controllers/render_spec_controllers.rb
r911 r964 113 113 114 114 Merb::Server.load_action_arguments 115 Merb::Server.load_controller_ globs115 Merb::Server.load_controller_template_path_cache trunk/spec/merb/mail_controller_spec.rb
r913 r964 6 6 end 7 7 end 8 Merb::Server.load_controller_ globs8 Merb::Server.load_controller_template_path_cache 9 9 10 10 class Merb::Mailer trunk/spec/merb/responder_spec.rb
r904 r964 244 244 245 245 Merb::Server.load_action_arguments 246 Merb::Server.load_controller_ globs246 Merb::Server.load_controller_template_path_cache 247 247 248 248 describe "A Merb Responder's Content Negotiation" do
