diff --git a/app/assets/stylesheets/color_themes/dark_green.scss b/app/assets/stylesheets/color_themes/dark_green.scss new file mode 100644 index 000000000..2570d2aa7 --- /dev/null +++ b/app/assets/stylesheets/color_themes/dark_green.scss @@ -0,0 +1,6 @@ +body > header { + background: rgb(0,35,0); + box-shadow: 0 1px 3px rgba(0,0,0,0.9), + 0 25px 35px -30px rgba(255,255,255,0.4) inset; + border-color: rgb(0,35,0); +} diff --git a/app/assets/stylesheets/color_themes/original.scss b/app/assets/stylesheets/color_themes/original.scss new file mode 100644 index 000000000..d20e293eb --- /dev/null +++ b/app/assets/stylesheets/color_themes/original.scss @@ -0,0 +1,5 @@ +body > header { + background: rgb(30,30,30); + box-shadow: 0 1px 3px rgba(0,0,0,0.9), + 0 25px 30px -25px rgba(255,255,255,0.4) inset; +} diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index eaa03b62b..f929728ae 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -69,6 +69,12 @@ class UsersController < ApplicationController else flash[:error] = I18n.t 'users.update.follow_settings_not_changed' end + elsif u[:color_theme] + if @user.update_attributes(u) + flash[:notice] = I18n.t "users.update.color_theme_changed" + else + flash[:error] = I18n.t "users.update.color_theme_not_changed" + end end end set_email_preferences @@ -181,6 +187,7 @@ class UsersController < ApplicationController :password, :password_confirmation, :language, + :color_theme, :disable_mail, :invitation_service, :invitation_identifier, diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 0b81a4a3d..f19556686 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -6,4 +6,48 @@ module UsersHelper def owner_image_link person_image_link(current_user.person, :size => :thumb_small) end + + # Returns the path of the current color theme so that it + # can be loaded in app/views/layouts/application.html.haml + # and app/views/layouts/application.mobile.haml. If the user + # is not signed in or has not specified a color theme, the + # default (original) color theme is loaded. + # + # ==== Examples + # + # # if user is not signed in + # current_color_theme # => "color_themes/original" + # # if user Alice has not selected a color theme + # current_color_theme # => "color_themes/original" + # # if user Alice has selected a "magenta" theme + # current_color_theme # => "color_themes/magenta" + def current_color_theme + if user_signed_in? + color_theme = current_user.color_theme + end + color_theme ||= DEFAULT_COLOR_THEME + current_color_theme = "color_themes/" + color_theme + end + + # Returns an array of the color themes available, as + # specified from AVAILABLE_COLOR_THEMES in + # config/initializers/color_themes.rb. + # + # ==== Examples + # + # # if config/color_themes.yml is: + # available: + # original: "Original dark" + # dark_green: "Dark green" + # # and AVAILABLE_COLOR_THEMES is accordingly initialized, + # # then: + # available_color_themes + # # => [["Original dark", "original"], ["Dark green", "dark_green"]] + def available_color_themes + opts = [] + AVAILABLE_COLOR_THEMES.each do |theme_code, theme_name| + opts << [theme_name, theme_code] + end + opts + end end diff --git a/app/models/user.rb b/app/models/user.rb index 8e569df21..41c51af51 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,12 +23,14 @@ class User < ActiveRecord::Base before_validation :strip_and_downcase_username before_validation :set_current_language, :on => :create + before_validation :set_default_color_theme, :on => :create validates :username, :presence => true, :uniqueness => true validates_format_of :username, :with => /\A[A-Za-z0-9_]+\z/ validates_length_of :username, :maximum => 32 validates_exclusion_of :username, :in => AppConfig.settings.username_blacklist validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES + validates_inclusion_of :color_theme, :in => AVAILABLE_COLOR_THEME_CODES, :allow_blank => true validates_format_of :unconfirmed_email, :with => Devise.email_regexp, :allow_blank => true validates_presence_of :person, :unless => proc {|user| user.invitation_token.present?} @@ -198,6 +200,10 @@ class User < ActiveRecord::Base self.language = I18n.locale.to_s if self.language.blank? end + def set_default_color_theme + self.color_theme ||= DEFAULT_COLOR_THEME + end + # This override allows a user to enter either their email address or their username into the username field. # @return [User] The user that matches the username/email condition. # @return [nil] if no user matches that condition. @@ -428,6 +434,8 @@ class User < ActiveRecord::Base self.email = opts[:email] self.language = opts[:language] self.language ||= I18n.locale.to_s + self.color_theme = opts[:color_theme] + self.color_theme ||= DEFAULT_COLOR_THEME self.valid? errors = self.errors errors.delete :person diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index e40ee1abd..d4f6a3948 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -26,6 +26,8 @@ - if rtl? = stylesheet_link_tag :rtl, media: 'all' + = stylesheet_link_tag current_color_theme, :media => "all" + = old_browser_js_support