From f7ebcca898ecdf428ba409652ee237a7b38d0409 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 18 Nov 2013 12:04:22 -0300 Subject: [PATCH] Do not build view_paths on each request --- app/controllers/application_controller.rb | 17 +++++++---------- app/helpers/application_helper.rb | 17 ++++++++++++----- lib/noosfero/plugin.rb | 3 +++ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ab3c9cf..14e729c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base before_filter :setup_multitenancy before_filter :detect_stuff_by_domain - before_filter :init_noosfero_plugins + before_filter :init_noosfero_plugins_controller_filters before_filter :allow_cross_domain_access def allow_cross_domain_access @@ -21,8 +21,12 @@ class ApplicationController < ActionController::Base include ApplicationHelper layout :get_layout def get_layout - prepend_view_path('public/' + theme_path) - theme_option(:layout) || 'application' + theme_layout = theme_option(:layout) + if theme_layout + theme_view_file('layouts/'+theme_layout) || theme_layout + else + 'application' + end end filter_parameter_logging :password @@ -122,13 +126,6 @@ class ApplicationController < ActionController::Base include Noosfero::Plugin::HotSpot - def init_noosfero_plugins - plugins.each do |plugin| - prepend_view_path(plugin.class.view_path) - end - init_noosfero_plugins_controller_filters - end - # This is a generic method that initialize any possible filter defined by a # plugin to the current controller being initialized. def init_noosfero_plugins_controller_filters diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f3d61bf..8b90249 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -399,16 +399,23 @@ module ApplicationHelper end end - def theme_include(template) + def theme_view_file(template) ['.rhtml', '.html.erb'].each do |ext| - file = (RAILS_ROOT + '/public' + theme_path + '/' + template + ext) - if File.exists?(file) - return render :file => file, :use_full_path => false - end + file = (RAILS_ROOT + '/public' + theme_path + '/' + template + ext) + return file if File.exists?(file) end nil end + def theme_include(template) + file = theme_view_file(template) + if file + render :file => file, :use_full_path => false + else + nil + end + end + def theme_favicon return '/designs/themes/' + current_theme + '/favicon.ico' if profile.nil? || profile.theme.nil? if File.exists?(File.join(RAILS_ROOT, 'public', theme_path, 'favicon.ico')) diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb index 765a260..c66cb09 100644 --- a/lib/noosfero/plugin.rb +++ b/lib/noosfero/plugin.rb @@ -57,6 +57,9 @@ class Noosfero::Plugin path << File.join(dir, 'lib') end + # add view path + ActionController::Base.view_paths.unshift(File.join(dir, 'views')) + # load vendor/plugins Dir.glob(File.join(dir, '/vendor/plugins/*')).each do |vendor_plugin| [ ActiveSupport::Dependencies.load_paths, $:].each{ |path| path << "#{vendor_plugin}/lib" } -- libgit2 0.21.2