diff options
Diffstat (limited to 'config/initializers/theme_loader.rb')
-rw-r--r-- | config/initializers/theme_loader.rb | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/config/initializers/theme_loader.rb b/config/initializers/theme_loader.rb index 877149e9d..9c79e513c 100644 --- a/config/initializers/theme_loader.rb +++ b/config/initializers/theme_loader.rb @@ -2,12 +2,24 @@ # It is used by our config/routes.rb to decide which route extension files to load. $alaveteli_route_extensions = [] -if ENV["RAILS_ENV"] != "test" # Don't let the themes interfere with Alaveteli specs - for url in Configuration::theme_urls.reverse - theme_name = url.sub(/.*\/(.*).git/, "\\1") - theme_main_include = File.expand_path "../../../vendor/plugins/#{theme_name}/lib/alavetelitheme.rb", __FILE__ - if File.exists? theme_main_include - require theme_main_include - end +def require_theme(theme_name) + theme_lib = Rails.root.join 'lib', 'themes', theme_name, 'lib' + $LOAD_PATH.unshift theme_lib.to_s + theme_main_include = Rails.root.join theme_lib, "alavetelitheme.rb" + if File.exists? theme_main_include + require theme_main_include + end +end + +if Rails.env == "test" + # By setting this ALAVETELI_TEST_THEME to a theme name, theme tests can run in the Rails + # context with the theme loaded. Otherwise the themes from the config aren't loaded in testing + # so they don't interfere with core Alaveteli tests + if defined? ALAVETELI_TEST_THEME + require_theme(ALAVETELI_TEST_THEME) + end +else + for url in AlaveteliConfiguration::theme_urls.reverse + require_theme theme_url_to_theme_name(url) end end |