mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-11 07:15:55 +08:00
ADD auto generate user avatar
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -36,6 +36,7 @@ public/react/yarn.lock
|
||||
/.idea/*
|
||||
|
||||
# Ignore react node_modules
|
||||
public/system/*
|
||||
public/react/*
|
||||
/public/react/.cache
|
||||
/public/react/node_modules/
|
||||
@@ -82,4 +83,5 @@ docker/
|
||||
educoder.sql
|
||||
redis_data/
|
||||
Dockerfile
|
||||
dump.rdb
|
||||
dump.rdb
|
||||
.tags*
|
||||
|
||||
2
Gemfile
2
Gemfile
@@ -126,3 +126,5 @@ gem 'request_store'
|
||||
gem 'harmonious_dictionary', '~> 0.0.1'
|
||||
|
||||
gem 'parallel', '~> 1.19', '>= 1.19.1'
|
||||
|
||||
gem 'letter_avatar'
|
||||
|
||||
@@ -162,6 +162,7 @@ GEM
|
||||
activerecord
|
||||
kaminari-core (= 1.2.0)
|
||||
kaminari-core (1.2.0)
|
||||
letter_avatar (0.3.8)
|
||||
listen (3.1.5)
|
||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||
rb-inotify (~> 0.9, >= 0.9.7)
|
||||
@@ -456,6 +457,7 @@ DEPENDENCIES
|
||||
jbuilder (~> 2.5)
|
||||
jquery-rails
|
||||
kaminari (~> 1.1, >= 1.1.1)
|
||||
letter_avatar
|
||||
listen (>= 3.0.5, < 3.2)
|
||||
mysql2 (>= 0.4.4, < 0.6.0)
|
||||
oauth2
|
||||
|
||||
@@ -149,12 +149,7 @@ module ApplicationHelper
|
||||
File.join("images/avatars", ["#{source.class}", "#{source.id}"]) + "?t=#{ctime}"
|
||||
end
|
||||
elsif source.class.to_s == 'User'
|
||||
str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g"
|
||||
File.join(relative_path, "#{source.class}", str)
|
||||
elsif source.class.to_s == 'Subject'
|
||||
File.join("images","educoder", "index", "subject", "subject#{rand(17)}.jpg")
|
||||
elsif source.class.to_s == 'Shixun'
|
||||
File.join("images","educoder", "index", "shixun", "shixun#{rand(23)}.jpg")
|
||||
source.letter_avatar_url
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ class User < Owner
|
||||
include Likeable
|
||||
include BaseModel
|
||||
include Droneable
|
||||
include User::Avatar
|
||||
# include Searchable::Dependents::User
|
||||
|
||||
# devops step
|
||||
|
||||
32
app/models/user/avatar.rb
Normal file
32
app/models/user/avatar.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
require 'letter_avatar/has_avatar'
|
||||
|
||||
class User
|
||||
module Avatar
|
||||
extend ActiveSupport::Concern
|
||||
include LetterAvatar::HasAvatar
|
||||
|
||||
def name
|
||||
lastname.blank? ? login : Pinyin.t(lastname)
|
||||
end
|
||||
|
||||
def letter_avatar_url(size = :lg)
|
||||
avatar_url(avatar_size(size))
|
||||
end
|
||||
|
||||
# 返回头像尺寸
|
||||
# xs: 22px
|
||||
# sm: 32px
|
||||
# md: 48px
|
||||
# lg: 120px
|
||||
def avatar_size(size)
|
||||
case size
|
||||
when :xs then 22
|
||||
when :sm then 32
|
||||
when :md then 48
|
||||
when :lg then 120
|
||||
else size
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
7
config/initializers/letter_avatar.rb
Normal file
7
config/initializers/letter_avatar.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
LetterAvatar.setup do |config|
|
||||
config.fill_color = 'rgba(255, 255, 255, 1)' # default is 'rgba(255, 255, 255, 0.65)'
|
||||
config.cache_base_path = 'public/system/lets' # default is 'public/system'
|
||||
config.colors_palette = :iwanthue # default is :google
|
||||
config.annotate_position = '-0+10' # default is -0+5
|
||||
config.letters_count = 2 # default is 1
|
||||
end
|
||||
Reference in New Issue
Block a user