Issue #4297: Enable color theme setup
This commit is contained in:
parent
c054d17bbb
commit
57d766346c
14 changed files with 116 additions and 0 deletions
6
app/assets/stylesheets/color_themes/dark_green.scss
Normal file
6
app/assets/stylesheets/color_themes/dark_green.scss
Normal file
|
|
@ -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);
|
||||
}
|
||||
5
app/assets/stylesheets/color_themes/original.scss
Normal file
5
app/assets/stylesheets/color_themes/original.scss
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
- if rtl?
|
||||
= stylesheet_link_tag :rtl, media: 'all'
|
||||
|
||||
= stylesheet_link_tag current_color_theme, :media => "all"
|
||||
|
||||
= old_browser_js_support
|
||||
<!--[if IE]>
|
||||
= javascript_include_tag :ie
|
||||
|
|
|
|||
|
|
@ -61,6 +61,14 @@
|
|||
|
||||
%hr
|
||||
|
||||
%h3= t(".change_color_theme")
|
||||
= form_for "user", url: user_path, html: {method: :put} do |f|
|
||||
.form-inline.clearfix
|
||||
= f.select :color_theme, available_color_themes, {}, {class: "form-control form-group"}
|
||||
= f.submit t(".change_color_theme"), class: "btn btn-primary pull-right"
|
||||
|
||||
%hr
|
||||
|
||||
%h3#stream-preferences
|
||||
= t('.stream_preferences')
|
||||
= form_for current_user, url: user_path, html: { method: :put } do |f|
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ module Diaspora
|
|||
mobile/mobile.css
|
||||
rtl.css
|
||||
home.css
|
||||
color_themes/*.css
|
||||
}
|
||||
|
||||
# Version of your assets, change this if you want to expire all your assets
|
||||
|
|
|
|||
3
config/color_themes.yml
Normal file
3
config/color_themes.yml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
available:
|
||||
original: "Original dark"
|
||||
dark_green: "Dark green"
|
||||
18
config/initializers/color_themes.rb
Normal file
18
config/initializers/color_themes.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
require 'pathname'
|
||||
|
||||
# Generate the path to the .yml file with the available color themes.
|
||||
color_themes_file = Pathname.new(__FILE__).dirname.join('..').expand_path.join("color_themes.yml")
|
||||
# Check in case config/color_themes.yml does not exist.
|
||||
if color_themes_file.exist?
|
||||
# Load the file specified by the generated path.
|
||||
color_themes = YAML.load_file(color_themes_file)
|
||||
# If the file contains one or more color themes, include them in AVAILABLE_COLOR_THEMES, else include the original theme.
|
||||
AVAILABLE_COLOR_THEMES = (color_themes["available"].length > 0) ? color_themes["available"] : { "original" => "original.scss" }
|
||||
else
|
||||
AVAILABLE_COLOR_THEMES = { "original" => "original.scss" }
|
||||
end
|
||||
# Get all codes from available themes into a separate variable, so that they can be called easier.
|
||||
AVAILABLE_COLOR_THEME_CODES = AVAILABLE_COLOR_THEMES.keys
|
||||
|
||||
# The default color theme, that will be called when no color theme is specified.
|
||||
DEFAULT_COLOR_THEME = "original"
|
||||
|
|
@ -1323,6 +1323,7 @@ en:
|
|||
current_password_expl: "the one you sign in with..."
|
||||
character_minimum_expl: "must be at least six characters"
|
||||
change_language: "Change language"
|
||||
change_color_theme: "Change color theme"
|
||||
close_account_text: "Close account"
|
||||
stream_preferences: "Stream preferences"
|
||||
show_community_spotlight: "Show “community spotlight” in stream"
|
||||
|
|
@ -1401,6 +1402,8 @@ en:
|
|||
unconfirmed_email_not_changed: "Email change failed"
|
||||
follow_settings_changed: "Follow settings changed"
|
||||
follow_settings_not_changed: "Follow settings change failed."
|
||||
color_theme_changed: "Color theme successfully changed."
|
||||
color_theme_not_changed: "An error occurred while changing the color theme."
|
||||
public:
|
||||
does_not_exist: "User %{username} does not exist!"
|
||||
confirm_email:
|
||||
|
|
|
|||
9
db/migrate/20150523004437_enable_color_themes.rb
Normal file
9
db/migrate/20150523004437_enable_color_themes.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class EnableColorThemes < ActiveRecord::Migration
|
||||
def up
|
||||
add_column(:users, :color_theme, :string)
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column(:users, :color_theme)
|
||||
end
|
||||
end
|
||||
|
|
@ -566,6 +566,7 @@ ActiveRecord::Schema.define(version: 20150531005120) do
|
|||
t.string "exported_photos_file", limit: 255
|
||||
t.datetime "exported_photos_at"
|
||||
t.boolean "exporting_photos", default: false
|
||||
t.string "color_theme", limit: 255
|
||||
end
|
||||
|
||||
add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree
|
||||
|
|
|
|||
|
|
@ -1009,6 +1009,7 @@ describe User, :type => :model do
|
|||
unconfirmed_email
|
||||
confirm_email_token
|
||||
last_seen
|
||||
color_theme
|
||||
}.sort)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue