theme_loader_helper.rb
1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module ThemeLoaderHelper
def current_theme
@current_theme ||=
begin
if session[:theme]
session[:theme]
else
# utility for developers: set the theme to 'random' in development mode and
# you will get a different theme every request. This is interesting for
# testing
if Rails.env.development? && environment.theme == 'random'
@random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand
@random_theme
elsif Rails.env.development? && respond_to?(:params) && params[:theme] && File.exists?(Rails.root.join('public/designs/themes', params[:theme]))
params[:theme]
else
if profile && !profile.theme.nil?
profile.theme
elsif environment
environment.theme
else
if logger
logger.warn("No environment found. This is weird.")
logger.warn("Request environment: %s" % request.env.inspect)
logger.warn("Request parameters: %s" % params.inspect)
end
# could not determine the theme, so return the default one
'default'
end
end
end
end
end
def theme_path
if session[:theme]
'/user_themes/' + current_theme
else
'/designs/themes/' + current_theme
end
end
end