From 07c2ba8fdebdcee1fe79d6e3aded5ea79ebfb19f Mon Sep 17 00:00:00 2001 From: Mike Dvorkin Date: Tue, 17 Aug 2010 20:20:00 -0700 Subject: [PATCH] Added PrependEngineViews library module to let Fat Free CRM plugins override default views --- lib/fat_free_crm.rb | 3 +++ lib/fat_free_crm/plugin_views.rb | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/fat_free_crm/plugin_views.rb diff --git a/lib/fat_free_crm.rb b/lib/fat_free_crm.rb index 2b26d294ec..e9b1edb3d8 100644 --- a/lib/fat_free_crm.rb +++ b/lib/fat_free_crm.rb @@ -28,6 +28,7 @@ require "fat_free_crm/tabs" require "fat_free_crm/callback" require "fat_free_crm/plugin" +require "fat_free_crm/plugin_views" ActionView::Base.send(:include, FatFreeCRM::I18n) ActionController::Base.send(:include, FatFreeCRM::I18n) @@ -37,3 +38,5 @@ ActiveRecord::Base.send(:include, FatFreeCRM::Permissions) ActiveRecord::Base.send(:include, FatFreeCRM::Sortable) + + Rails::Plugin::Loader.send(:include, FatFreeCRM::PrependEngineViews) diff --git a/lib/fat_free_crm/plugin_views.rb b/lib/fat_free_crm/plugin_views.rb new file mode 100644 index 0000000000..cef9a6a5e2 --- /dev/null +++ b/lib/fat_free_crm/plugin_views.rb @@ -0,0 +1,40 @@ +# Fat Free CRM +# Copyright (C) 2008-2010 by Michael Dvorkin +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------ + +module FatFreeCRM + # The following is taken from PrependEngineViews plugin for Redmine + # (see http://github.com/edavis10/prepend_engine_views/blob/master/init.rb) + # It basically lets any Fat Free CRM plugin override default views. + module PrependEngineViews + def self.included(base) + base.send(:include, InstanceMethods) + base.class_eval do + alias_method_chain :add_engine_view_paths, :prepend + end + end + + module InstanceMethods + # Patch Rails so engine's views are prepended to the view_path, + # thereby letting plugins override application views + def add_engine_view_paths_with_prepend + paths = ActionView::PathSet.new(engines.collect(&:view_path)) + ActionController::Base.view_paths.unshift(*paths) + ActionMailer::Base.view_paths.unshift(*paths) if configuration.frameworks.include?(:action_mailer) + end + end + end +end