From d64ea158911885e6d3dd02bb92226b8691819fc9 Mon Sep 17 00:00:00 2001 From: efstrian Date: Thu, 4 Jun 2015 16:38:49 +0300 Subject: [PATCH] Issue #4297: Style fixes - Default theme is configurable --- app/helpers/users_helper.rb | 31 ++++++++--------------- app/models/user.rb | 8 +++--- app/views/layouts/application.html.haml | 2 +- app/views/layouts/application.mobile.haml | 2 +- config/defaults.yml | 1 + config/diaspora.yml.example | 6 +++++ config/initializers/color_themes.rb | 19 +++++++------- spec/controllers/users_controller_spec.rb | 2 +- spec/helpers/users_helper_spec.rb | 9 ++++--- 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index f19556686..d79b6b059 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -13,39 +13,30 @@ module UsersHelper # 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" + # @example if user is not signed in + # current_color_theme #=> "color_themes/original" + # @example if user Alice has not selected a color theme + # current_color_theme #=> "color_themes/original" + # @example 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 + color_theme ||= AppConfig.settings.default_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: + # @example if AVAILABLE_COLOR_THEMES = {"original"=>"Original dark", "dark_green" => "Dark green"} # available_color_themes - # # => [["Original dark", "original"], ["Dark green", "dark_green"]] + # #=> [["Original dark", "original"], ["Dark green", "dark_green"]] def available_color_themes opts = [] - AVAILABLE_COLOR_THEMES.each do |theme_code, theme_name| + AVAILABLE_COLOR_THEMES.map do |theme_code, theme_name| opts << [theme_name, theme_code] end opts diff --git a/app/models/user.rb b/app/models/user.rb index 41c51af51..e7685cd6e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,14 +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 + 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 :color_theme, inclusion: {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?} @@ -201,7 +201,7 @@ class User < ActiveRecord::Base end def set_default_color_theme - self.color_theme ||= DEFAULT_COLOR_THEME + self.color_theme ||= AppConfig.settings.default_color_theme end # This override allows a user to enter either their email address or their username into the username field. @@ -435,7 +435,7 @@ class User < ActiveRecord::Base self.language = opts[:language] self.language ||= I18n.locale.to_s self.color_theme = opts[:color_theme] - self.color_theme ||= DEFAULT_COLOR_THEME + self.color_theme ||= AppConfig.settings.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 d4f6a3948..37029070d 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -26,7 +26,7 @@ - if rtl? = stylesheet_link_tag :rtl, media: 'all' - = stylesheet_link_tag current_color_theme, :media => "all" + = stylesheet_link_tag current_color_theme, media: "all" = old_browser_js_support