profile now knows about three images sizes, even in federation case
This commit is contained in:
parent
ec5145777e
commit
ec05c21472
10 changed files with 90 additions and 30 deletions
|
|
@ -77,6 +77,8 @@ class PeopleController < ApplicationController
|
|||
|
||||
photo = current_user.post(:photo, params[:profile_image_hash])
|
||||
params[:person][:profile][:image_url] = photo.url(:thumb_large)
|
||||
params[:person][:profile][:image_url_medium] = photo.url(:thumb_medium)
|
||||
params[:person][:profile][:image_url_small] = photo.url(:thumb_small)
|
||||
end
|
||||
|
||||
if current_user.update_profile params[:person][:profile]
|
||||
|
|
|
|||
|
|
@ -105,8 +105,9 @@ module ApplicationHelper
|
|||
</a>".html_safe
|
||||
end
|
||||
|
||||
def image_or_default(person)
|
||||
image_location = person.profile.image_url if person.profile
|
||||
def image_or_default(person, size=:thumb_large)
|
||||
image_location = person.profile.image_url(size) if person.profile
|
||||
image_location ||= person.profile.image_url(:thumb_large) if person.profile #backwards compatability for old profile pictures
|
||||
image_location ||= "/images/user/default.png"
|
||||
image_location
|
||||
end
|
||||
|
|
|
|||
|
|
@ -130,6 +130,8 @@ class Person
|
|||
new_person.profile = Profile.new( :first_name => hcard[:given_name],
|
||||
:last_name => hcard[:family_name],
|
||||
:image_url => hcard[:photo],
|
||||
:image_url_medium => hcard[:photo_medium],
|
||||
:image_url_small => hcard[:photo_small],
|
||||
:searchable => hcard[:searchable])
|
||||
|
||||
new_person.save! ? new_person : nil
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ class Profile
|
|||
xml_reader :first_name
|
||||
xml_reader :last_name
|
||||
xml_reader :image_url
|
||||
xml_reader :image_url_small
|
||||
xml_reader :image_url_medium
|
||||
xml_reader :birthday
|
||||
xml_reader :gender
|
||||
xml_reader :bio
|
||||
|
|
@ -21,6 +23,8 @@ class Profile
|
|||
key :first_name, String
|
||||
key :last_name, String
|
||||
key :image_url, String
|
||||
key :image_url_small, String
|
||||
key :image_url_medium, String
|
||||
key :birthday, Date
|
||||
key :gender, String
|
||||
key :bio, String
|
||||
|
|
@ -32,7 +36,7 @@ class Profile
|
|||
|
||||
before_save :strip_names
|
||||
|
||||
attr_accessible :first_name, :last_name, :image_url, :birthday, :gender, :bio, :searchable
|
||||
attr_accessible :first_name, :last_name, :image_url, :image_url_medium, :image_url_small, :birthday, :gender, :bio, :searchable
|
||||
|
||||
|
||||
def person
|
||||
|
|
@ -44,6 +48,17 @@ class Profile
|
|||
(self._parent_document) ? self.person.diaspora_handle : self[:diaspora_handle]
|
||||
end
|
||||
|
||||
def image_url(size = :thumb_large)
|
||||
if size == :thumb_medium
|
||||
self[:image_url_medium]
|
||||
elsif size == :thumb_small
|
||||
self[:image_url_small]
|
||||
else
|
||||
self[:image_url]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def image_url= url
|
||||
return image_url if url == ''
|
||||
if url.nil? || url.match(/^https?:\/\//)
|
||||
|
|
@ -53,6 +68,24 @@ class Profile
|
|||
end
|
||||
end
|
||||
|
||||
def image_url_small= url
|
||||
return image_url if url == ''
|
||||
if url.nil? || url.match(/^https?:\/\//)
|
||||
super(url)
|
||||
else
|
||||
super(absolutify_local_url(url))
|
||||
end
|
||||
end
|
||||
|
||||
def image_url_medium= url
|
||||
return image_url if url == ''
|
||||
if url.nil? || url.match(/^https?:\/\//)
|
||||
super(url)
|
||||
else
|
||||
super(absolutify_local_url(url))
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def strip_names
|
||||
|
|
|
|||
|
|
@ -32,7 +32,17 @@
|
|||
%dl.entity_photo
|
||||
%dt Photo
|
||||
%dd
|
||||
%img.photo.avatar{:src=>image_or_default(@person), :width=>'100px', :height=>'100px'}
|
||||
%img.photo.avatar{:src=>image_or_default(@person), :width=>'300px', :height=>'300px'}
|
||||
|
||||
%dl.entity_photo_medium
|
||||
%dt Photo
|
||||
%dd
|
||||
%img.photo.avatar{:src=>image_or_default(@person, :thumb_medium), :width=>'100px', :height=>'100px'}
|
||||
|
||||
%dl.entity_photo_small
|
||||
%dt Photo
|
||||
%dd
|
||||
%img.photo.avatar{:src=>image_or_default(@person, :thumb_small), :width=>'50px', :height=>'50px'}
|
||||
|
||||
%dl.entity_searchable
|
||||
%dt Searchable
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
default:
|
||||
|
||||
# Hostname of this host, as seen from the internet.
|
||||
pod_url: "http://example.org/"
|
||||
pod_url: "http://localhost:3000"
|
||||
|
||||
# Set this to true in order to close signups. Users will still be
|
||||
# able to invite other people to join.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ module HCard
|
|||
:given_name => doc.css(".given_name").text,
|
||||
:family_name => doc.css(".family_name").text,
|
||||
:url => doc.css("#pod_location").text,
|
||||
:photo => doc.css(".photo[src]").attribute('src').text,
|
||||
:photo => doc.css(".entity_photo .photo[src]").attribute('src').text,
|
||||
:photo_small => doc.css(".entity_photo_small .photo[src]").attribute('src').text,
|
||||
:photo_medium => doc.css(".entity_photo_medium .photo[src]").attribute('src').text,
|
||||
:searchable => doc.css(".searchable").text
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
describe 'making sure the config is parsed as should' do
|
||||
|
||||
<<<<<<< HEAD
|
||||
describe 'pod_url' do
|
||||
it 'should have a trailing slash' do
|
||||
APP_CONFIG[:pod_url].should == 'http://example.org/'
|
||||
|
|
|
|||
45
spec/fixtures/hcard_response
vendored
45
spec/fixtures/hcard_response
vendored
|
|
@ -1,47 +1,56 @@
|
|||
<div id="content">
|
||||
|
||||
<div id='content'>
|
||||
<h1>Alexander Hamiltom</h1>
|
||||
<div id="content_inner">
|
||||
<div id="i" class="entity_profile vcard author">
|
||||
<div id='content_inner'>
|
||||
<div class='entity_profile vcard author' id='i'>
|
||||
<h2>User profile</h2>
|
||||
<dl class="entity_nickname">
|
||||
<dl class='entity_nickname'>
|
||||
<dt>Nickname</dt>
|
||||
<dd>
|
||||
<a href="http://tom.joindiaspora.com/" rel="me" class="nickname url uid">Alexander Hamiltom</a>
|
||||
<a class='nickname url uid' href='http://localhost:3000/' rel='me'>Alexander Hamiltom</a>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="entity_given_name">
|
||||
<dl class='entity_given_name'>
|
||||
<dt>First name</dt>
|
||||
<dd>
|
||||
<span class="given_name" >Alexander</span>
|
||||
<span class='given_name'>Alexander</span>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="entity_family_name">
|
||||
<dl class='entity_family_name'>
|
||||
<dt>Family name</dt>
|
||||
<dd>
|
||||
<span class="family_name" >Hamiltom</span>
|
||||
<span class='family_name'>Hamiltom</span>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="entity_fn">
|
||||
<dl class='entity_fn'>
|
||||
<dt>Full name</dt>
|
||||
<dd>
|
||||
<span class="fn" >Alexander Hamiltom</span>
|
||||
<span class='fn'>Alexander Hamiltom</span>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="entity_url">
|
||||
<dl class='entity_url'>
|
||||
<dt>URL</dt>
|
||||
<dd>
|
||||
<a href="http://tom.joindiaspora.com/" rel="me" id="pod_location" class="url">http://tom.joindiaspora.com/</a>
|
||||
<a class='url' href='http://localhost:3000/' id='pod_location' rel='me'>http://localhost:3000/</a>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="entity_photo">
|
||||
<dl class='entity_photo'>
|
||||
<dt>Photo</dt>
|
||||
<dd>
|
||||
<img class="photo avatar" src="http://tom.joindiaspora.com/images/user/tom.jpg" width="100" height="100"/>
|
||||
<img class='photo avatar' height='300px' src='http://localhost:3000/uploads/images/thumb_large_8rxQAwC4Vx4cf5667d37db5b0fef000003.jpg' width='300px'>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="entity_note">
|
||||
<dt>Note</dt>
|
||||
<dd class="note">Diaspora is awesome! vi is better than emacs!</dd>
|
||||
<dl class='entity_photo_medium'>
|
||||
<dt>Photo</dt>
|
||||
<dd>
|
||||
<img class='photo avatar' height='100px' src='http://localhost:3000/uploads/images/thumb_medium_8rxQAwC4Vx4cf5667d37db5b0fef000003.jpg' width='100px'>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class='entity_photo_small'>
|
||||
<dt>Photo</dt>
|
||||
<dd>
|
||||
<img class='photo avatar' height='50px' src='http://localhost:3000/uploads/images/thumb_small_8rxQAwC4Vx4cf5667d37db5b0fef000003.jpg' width='50px'>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class='entity_searchable'>
|
||||
<dt>Searchable</dt>
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ describe HCard do
|
|||
hcard = HCard.build raw_hcard
|
||||
hcard[:family_name].include?("Hamiltom").should be true
|
||||
hcard[:given_name].include?("Alex").should be true
|
||||
hcard[:photo].include?("tom.jpg").should be true
|
||||
hcard[:url].should == "http://tom.joindiaspora.com/"
|
||||
hcard[:photo].include?("thumb_large").should be true
|
||||
hcard[:photo_medium].include?("thumb_medium").should be true
|
||||
hcard[:photo_small].include?("thumb_small").should be true
|
||||
hcard[:url].should == "http://localhost:3000/"
|
||||
hcard[:searchable].should == "false"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue