Commit f7ebcca898ecdf428ba409652ee237a7b38d0409
Committed by
Rodrigo Souto
1 parent
54df9315
Exists in
master
and in
29 other branches
Do not build view_paths on each request
Add plugin view paths at initialization. Calling prepend_view_path on each request is too slow. Do not include theme dir at view path. Themes must use theme_include method to render rhtml files (instead of using render directly). This avoids conflict of files with same name at different themes and reduces the amount of paths in view_paths.
Showing
3 changed files
with
22 additions
and
15 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base |
2 | 2 | |
3 | 3 | before_filter :setup_multitenancy |
4 | 4 | before_filter :detect_stuff_by_domain |
5 | - before_filter :init_noosfero_plugins | |
5 | + before_filter :init_noosfero_plugins_controller_filters | |
6 | 6 | before_filter :allow_cross_domain_access |
7 | 7 | |
8 | 8 | def allow_cross_domain_access |
... | ... | @@ -21,8 +21,12 @@ class ApplicationController < ActionController::Base |
21 | 21 | include ApplicationHelper |
22 | 22 | layout :get_layout |
23 | 23 | def get_layout |
24 | - prepend_view_path('public/' + theme_path) | |
25 | - theme_option(:layout) || 'application' | |
24 | + theme_layout = theme_option(:layout) | |
25 | + if theme_layout | |
26 | + theme_view_file('layouts/'+theme_layout) || theme_layout | |
27 | + else | |
28 | + 'application' | |
29 | + end | |
26 | 30 | end |
27 | 31 | |
28 | 32 | filter_parameter_logging :password |
... | ... | @@ -122,13 +126,6 @@ class ApplicationController < ActionController::Base |
122 | 126 | |
123 | 127 | include Noosfero::Plugin::HotSpot |
124 | 128 | |
125 | - def init_noosfero_plugins | |
126 | - plugins.each do |plugin| | |
127 | - prepend_view_path(plugin.class.view_path) | |
128 | - end | |
129 | - init_noosfero_plugins_controller_filters | |
130 | - end | |
131 | - | |
132 | 129 | # This is a generic method that initialize any possible filter defined by a |
133 | 130 | # plugin to the current controller being initialized. |
134 | 131 | def init_noosfero_plugins_controller_filters | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -399,16 +399,23 @@ module ApplicationHelper |
399 | 399 | end |
400 | 400 | end |
401 | 401 | |
402 | - def theme_include(template) | |
402 | + def theme_view_file(template) | |
403 | 403 | ['.rhtml', '.html.erb'].each do |ext| |
404 | - file = (RAILS_ROOT + '/public' + theme_path + '/' + template + ext) | |
405 | - if File.exists?(file) | |
406 | - return render :file => file, :use_full_path => false | |
407 | - end | |
404 | + file = (RAILS_ROOT + '/public' + theme_path + '/' + template + ext) | |
405 | + return file if File.exists?(file) | |
408 | 406 | end |
409 | 407 | nil |
410 | 408 | end |
411 | 409 | |
410 | + def theme_include(template) | |
411 | + file = theme_view_file(template) | |
412 | + if file | |
413 | + render :file => file, :use_full_path => false | |
414 | + else | |
415 | + nil | |
416 | + end | |
417 | + end | |
418 | + | |
412 | 419 | def theme_favicon |
413 | 420 | return '/designs/themes/' + current_theme + '/favicon.ico' if profile.nil? || profile.theme.nil? |
414 | 421 | if File.exists?(File.join(RAILS_ROOT, 'public', theme_path, 'favicon.ico')) | ... | ... |
lib/noosfero/plugin.rb
... | ... | @@ -57,6 +57,9 @@ class Noosfero::Plugin |
57 | 57 | path << File.join(dir, 'lib') |
58 | 58 | end |
59 | 59 | |
60 | + # add view path | |
61 | + ActionController::Base.view_paths.unshift(File.join(dir, 'views')) | |
62 | + | |
60 | 63 | # load vendor/plugins |
61 | 64 | Dir.glob(File.join(dir, '/vendor/plugins/*')).each do |vendor_plugin| |
62 | 65 | [ ActiveSupport::Dependencies.load_paths, $:].each{ |path| path << "#{vendor_plugin}/lib" } | ... | ... |