Merge pull request #43 from indentlabs/add-gravatars

Add user profile images
This commit is contained in:
Andrew Brown 2016-09-23 22:58:14 +02:00 committed by GitHub
commit e97d44ecb1
4 changed files with 35 additions and 7 deletions

View File

@ -1,3 +1,5 @@
require 'digest/md5'
##
# a person using the Indent web application. Owns all other content.
class User < ActiveRecord::Base
@ -35,6 +37,10 @@ class User < ActiveRecord::Base
super(options)
end
def name
self[:name] || 'Anonymous author'
end
def content
{
characters: characters,
@ -57,6 +63,12 @@ class User < ActiveRecord::Base
].sum
end
def image_url(size=80)
email_md5 = Digest::MD5.hexdigest(email.downcase)
# 80px is Gravatar's default size
"https://www.gravatar.com/avatar/#{email_md5}?d=identicon&s=#{size}".html_safe
end
private
# Attributes that are non-public, and should be blacklisted from any public

View File

@ -1,12 +1,15 @@
<script type="application/ld+json">
<%
set_meta_tags title: @user.name, description: "#{@user.name}s profile on notebook.ai"
set_meta_tags title: @user.name,
description: "#{@user.name}s profile on notebook.ai",
image_src: @user.image_url(120)
content_jsonld = {
'@id': user_url,
'@type': 'http://schema.org/Person',
'http://schema.org/name': @user.name,
'http://schema.org/description': "#{@user.name}s profile on notebook.ai"
'http://schema.org/description': "#{@user.name}s profile on notebook.ai",
'https://schema.org/image': @user.image_url(120)
}
%>
<%= content_jsonld.to_json.html_safe %> %>
@ -22,13 +25,14 @@ content_jsonld = {
%>
<div class="row">
<div class="col s4">
<div class="col m3 s4">
<div class="hoverable card">
<div class="card-image">
<%= image_tag 'card-headers/universes.jpg', style: 'height: 190px' %>
<span class="card-title"><%= @user.name.present? ? @user.name : 'Anonymous author' %></span>
<div class="card-image waves-effect waves-block waves-light">
<%= image_tag @user.image_url(500).html_safe, class: 'activator' %>
</div>
<div class="card-content">
<div class="card-title"><b><%= @user.name %></b></div>
<p>
I'm creating universes on Notebook! I'm currently sharing the following public content:
</p>
@ -42,6 +46,11 @@ content_jsonld = {
</div>
</div>
<div class="card-reveal">
<span class="card-title grey-text text-darken-4">Profile Picture<i class="material-icons right">close</i></span>
<p>Profile pictures are powered by <%= link_to 'Gravatar', 'https://gravatar.com/', target: "_blank" %>, using the email you provided in your <%= link_to 'account settings', edit_user_registration_path %>.</p>
<p>For the prettiest profile, use an avatar at least 250 pixels wide.</p>
</div>
<div class="card-action">
<a href="#">Author links coming soon</a>
</div>

View File

@ -26,5 +26,8 @@ module PlanCharacters
# Filter sensitive parameters out of logs
config.filter_parameters << :password
config.filter_parameters << :password_confirmation
# Don't encode ampersands into \u0026 when creating JSON
config.active_support.escape_html_entities_in_json = false
end
end

View File

@ -2,5 +2,9 @@ require 'test_helper'
# Tests for the User model class
class UserTest < ActiveSupport::TestCase
# Blank, for now
test 'user has a Gravatar profile image' do
user = build(:user, email: 'profile.image.test@example.com')
assert_match 'https://www.gravatar.com/avatar/d2fd00e79c471f49c33b6bcb6b08d08d', user.image_url
end
end