Skip to content

Commit

Permalink
Added PrependEngineViews library module to let Fat Free CRM plugins o…
Browse files Browse the repository at this point in the history
…verride

default views
  • Loading branch information
Mike Dvorkin committed Aug 18, 2010
1 parent 5ea3724 commit 07c2ba8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/fat_free_crm.rb
Expand Up @@ -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)
Expand All @@ -37,3 +38,5 @@

ActiveRecord::Base.send(:include, FatFreeCRM::Permissions)
ActiveRecord::Base.send(:include, FatFreeCRM::Sortable)

Rails::Plugin::Loader.send(:include, FatFreeCRM::PrependEngineViews)
40 changes: 40 additions & 0 deletions 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 <http:#www.gnu.org/licenses/>.
#------------------------------------------------------------------------------

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

0 comments on commit 07c2ba8

Please sign in to comment.