summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-08-03 11:30:02 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2015-08-03 13:37:35 +0200
commit96b84e4cb99df7703f52f472b40ce6328f433465 (patch)
tree73635fc2e711e8244668d7390df883471fca33bb /app
parent9cf47eb6ee0dbd7ab5ce40b76a8cdb22253ec907 (diff)
downloadgitlab-ci-96b84e4cb99df7703f52f472b40ce6328f433465.tar.gz
Use avatars from GitLab
Rewrite Gravatar URLs if needed in order to have images in different size
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/generic/avatar.scss29
-rw-r--r--app/assets/stylesheets/main/variables.scss5
-rw-r--r--app/helpers/application_helper.rb12
-rw-r--r--app/helpers/user_helper.rb13
-rw-r--r--app/views/layouts/_nav.html.haml2
-rw-r--r--app/views/user_sessions/show.html.haml2
6 files changed, 49 insertions, 14 deletions
diff --git a/app/assets/stylesheets/generic/avatar.scss b/app/assets/stylesheets/generic/avatar.scss
new file mode 100644
index 0000000..fc0914c
--- /dev/null
+++ b/app/assets/stylesheets/generic/avatar.scss
@@ -0,0 +1,29 @@
+.avatar {
+ float: left;
+ margin-right: 12px;
+ width: 40px;
+ height: 40px;
+ padding: 0;
+ @include border-radius($avatar_radius);
+
+ &.avatar-inline {
+ float: none;
+ margin-left: 4px;
+ margin-bottom: 2px;
+
+ &.s16 { margin-right: 4px; }
+ &.s24 { margin-right: 4px; }
+ }
+
+ &.avatar-tile {
+ @include border-radius(0px);
+ }
+
+ &.s16 { width: 16px; height: 16px; margin-right: 6px; }
+ &.s24 { width: 24px; height: 24px; margin-right: 8px; }
+ &.s26 { width: 26px; height: 26px; margin-right: 8px; }
+ &.s32 { width: 32px; height: 32px; margin-right: 10px; }
+ &.s60 { width: 60px; height: 60px; margin-right: 12px; }
+ &.s90 { width: 90px; height: 90px; margin-right: 15px; }
+ &.s160 { width: 160px; height: 160px; margin-right: 20px; }
+}
diff --git a/app/assets/stylesheets/main/variables.scss b/app/assets/stylesheets/main/variables.scss
index bd79ca3..a8c672a 100644
--- a/app/assets/stylesheets/main/variables.scss
+++ b/app/assets/stylesheets/main/variables.scss
@@ -37,3 +37,8 @@ $border_warning: #EB9532;
$font-size-base: 13px !default;
$nav-pills-active-link-hover-bg: $bg_style_color;
$pagination-active-bg: $bg_style_color;
+
+/**
+ * Avatar variables
+ */
+$avatar_radius: 50%;
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 8eeb409..297ee5b 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -3,18 +3,6 @@ module ApplicationHelper
image_tag 'loader.gif', alt: 'Loading'
end
- def gravatar_icon(user_email = '', size = nil)
- size = 40 if size.nil? || size <= 0
-
- if !GitlabCi.config.gravatar.enabled || user_email.blank?
- 'no_avatar.png'
- else
- gravatar_url = request.ssl? || GitlabCi.config.gitlab_ci.https ? GitlabCi.config.gravatar.ssl_url : GitlabCi.config.gravatar.plain_url
-
- user_email.strip!
- sprintf gravatar_url, hash: Digest::MD5.hexdigest(user_email.downcase), size: size
- end
- end
# Navigation link helper
#
# Returns an `li` element with an 'active' class if the supplied
diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb
new file mode 100644
index 0000000..7fa0c9c
--- /dev/null
+++ b/app/helpers/user_helper.rb
@@ -0,0 +1,13 @@
+module UserHelper
+ def user_avatar_url(user = nil, size = nil, default = 'identicon')
+ size = 40 if size.nil? || size <= 0
+
+ if user.blank? || user.avatar_url.blank?
+ 'no_avatar.png'
+ elsif /^(http(s?):\/\/(www|secure)\.gravatar\.com\/avatar\/(\w*))/ =~ user.avatar_url
+ Regexp.last_match[0] + "?s=#{size}&d=#{default}"
+ else
+ user.avatar_url
+ end
+ end
+end
diff --git a/app/views/layouts/_nav.html.haml b/app/views/layouts/_nav.html.haml
index d571716..636485a 100644
--- a/app/views/layouts/_nav.html.haml
+++ b/app/views/layouts/_nav.html.haml
@@ -21,7 +21,7 @@
%li
= link_to user_sessions_path do
.profile-holder
- = image_tag gravatar_icon(current_user.email, 64), alt: ''
+ = image_tag user_avatar_url(current_user, 64), class: 'avatar s32', alt: ''
%span= current_user.name
%li
= link_to user_sessions_path, class: "logout", method: :delete do
diff --git a/app/views/user_sessions/show.html.haml b/app/views/user_sessions/show.html.haml
index 0faf2f7..43f64a4 100644
--- a/app/views/user_sessions/show.html.haml
+++ b/app/views/user_sessions/show.html.haml
@@ -1,4 +1,4 @@
-= image_tag gravatar_icon(current_user.email, 120), class: 'img-polaroid', alt: ''
+= image_tag user_avatar_url(current_user, 90), class: 'avatar avatar-inline avatar-tile s90', alt: ''
%h3
Hi, #{@user.name}