users may specify a theme in their preferences

pull/778/head
Philipp Tessenow 11 years ago
parent 01b53912fa
commit a9dbaf862c
  1. 2
      app/helpers/application_helper.rb
  2. 13
      lib/open_project/themes.rb
  3. 2
      lib/open_project/themes/view_helpers.rb
  4. 12
      spec/lib/open_project/themes_spec.rb

@ -473,7 +473,7 @@ module ApplicationHelper
# Returns the theme, controller name, and action as css classes for the
# HTML body.
def body_css_classes
theme = OpenProject::Themes.current_theme
theme = OpenProject::Themes.current_theme user: User.current
css = ['theme-' + theme.identifier.to_s]

@ -45,11 +45,18 @@ module OpenProject
DefaultTheme.instance
end
def current_theme
theme(current_theme_identifier)
##
# Returns the currently active theme.
# Params: options (Hash)
# - user: Users may define a theme in their preferences
# if the user has done so, return that theme
def current_theme(options = {})
user_theme = options[:user].try(:preference)
.try(:[], :theme)
theme(user_theme || application_theme_identifier)
end
def current_theme_identifier
def application_theme_identifier
Setting.ui_theme.to_s.to_sym.presence
end

@ -36,7 +36,7 @@ module OpenProject
# if none is configured or one cannot be found it returns the default theme
# which means this helper always returns a OpenProject::Themes::Theme subclass
def current_theme
OpenProject::Themes.current_theme
OpenProject::Themes.current_theme user: User.current
end
# overrides image_tag defined in ActionView::Helpers::AssetTagHelpers (Rails 4)

@ -102,30 +102,30 @@ module OpenProject
theme = Themes.new_theme do |theme|
theme.identifier = :new_theme
end
Themes.stub(:current_theme_identifier).and_return :new_theme
Themes.stub(:application_theme_identifier).and_return :new_theme
expect(Themes.current_theme).to eq theme
end
it "returns the default theme if configured theme wasn't found" do
Themes.stub(:current_theme_identifier).and_return :missing_theme
Themes.stub(:application_theme_identifier).and_return :missing_theme
expect(Themes.current_theme).to eq Themes.default_theme
end
end
describe '.current_theme_identifier' do
describe '.application_theme_identifier' do
it "normalizes current theme setting to a symbol" do
Setting.stub(:ui_theme).and_return 'new_theme'
expect(Themes.current_theme_identifier).to eq :new_theme
expect(Themes.application_theme_identifier).to eq :new_theme
end
it "returns nil for an empty string" do
Setting.stub(:ui_theme).and_return ''
expect(Themes.current_theme_identifier).to be_nil
expect(Themes.application_theme_identifier).to be_nil
end
it "returns nil for nil" do
Setting.stub(:ui_theme).and_return nil
expect(Themes.current_theme_identifier).to be_nil
expect(Themes.application_theme_identifier).to be_nil
end
end
end

Loading…
Cancel
Save