#!/usr/bin/env ruby #-- # Copyright (c) 2006 Jeff Barczewski # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ # # Setup hook to insert MasterView changed-template reparsing # into the Rails request dispatching handler in ActionController::Base. # # Ensures that masterview output files are always current while running a # Rails application. Should generally be enabled/disabled in conjunction # with Rails class load caching, which is normally off in a development # environment configuration. Requires that masterview templates be # parsed at application startup to properly initialize the mechanism # to detect template changes after application startup. # #-- # DBC-style notation per DbC - rubydbc-0.1 (Andy Hunt's Design by Contract) #pre( MasterView::ParseMasterViewTemplatesAtStartup ) #pre( MasterView::ReparseChangedMasterViewTemplates ) #pre( defined?(ActionController) && ActionController::Base.perform_caching ) #++ # MasterView::Log.info { 'Adding hook to allow MasterView to check for templates that have changed when processing a request' } module ActionController #:nodoc: class Base #:nodoc # Install hook to enable MasterView to detect and automatically reparse # changed templates during Rails request dispatching. alias :process_pre_mv :process #:nodoc: def process(request, response, method = :perform_action, *arguments) #:nodoc: MasterView::TemplateWatcher.check_updated(MasterView::IOMgr.template, MasterView::TemplateFilenamePattern ) do |mio| MasterView::Parser.parse_mio( mio, MasterView::IOMgr.erb ) end process_pre_mv(request, response, method, *arguments) end end end MasterView::LoadedFeatures[:rails_reparse_checking] = true