profile now knows about three images sizes, even in federation case

This commit is contained in:
maxwell 2010-11-30 13:29:17 -08:00
parent ec5145777e
commit ec05c21472
10 changed files with 90 additions and 30 deletions

View file

@ -77,6 +77,8 @@ class PeopleController < ApplicationController
photo = current_user.post(:photo, params[:profile_image_hash]) photo = current_user.post(:photo, params[:profile_image_hash])
params[:person][:profile][:image_url] = photo.url(:thumb_large) 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 end
if current_user.update_profile params[:person][:profile] if current_user.update_profile params[:person][:profile]

View file

@ -105,8 +105,9 @@ module ApplicationHelper
</a>".html_safe </a>".html_safe
end end
def image_or_default(person) def image_or_default(person, size=:thumb_large)
image_location = person.profile.image_url if person.profile 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 ||= "/images/user/default.png"
image_location image_location
end end

View file

@ -130,6 +130,8 @@ class Person
new_person.profile = Profile.new( :first_name => hcard[:given_name], new_person.profile = Profile.new( :first_name => hcard[:given_name],
:last_name => hcard[:family_name], :last_name => hcard[:family_name],
:image_url => hcard[:photo], :image_url => hcard[:photo],
:image_url_medium => hcard[:photo_medium],
:image_url_small => hcard[:photo_small],
:searchable => hcard[:searchable]) :searchable => hcard[:searchable])
new_person.save! ? new_person : nil new_person.save! ? new_person : nil

View file

@ -12,6 +12,8 @@ class Profile
xml_reader :first_name xml_reader :first_name
xml_reader :last_name xml_reader :last_name
xml_reader :image_url xml_reader :image_url
xml_reader :image_url_small
xml_reader :image_url_medium
xml_reader :birthday xml_reader :birthday
xml_reader :gender xml_reader :gender
xml_reader :bio xml_reader :bio
@ -21,6 +23,8 @@ class Profile
key :first_name, String key :first_name, String
key :last_name, String key :last_name, String
key :image_url, String key :image_url, String
key :image_url_small, String
key :image_url_medium, String
key :birthday, Date key :birthday, Date
key :gender, String key :gender, String
key :bio, String key :bio, String
@ -32,7 +36,7 @@ class Profile
before_save :strip_names 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 def person
@ -44,6 +48,17 @@ class Profile
(self._parent_document) ? self.person.diaspora_handle : self[:diaspora_handle] (self._parent_document) ? self.person.diaspora_handle : self[:diaspora_handle]
end 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 def image_url= url
return image_url if url == '' return image_url if url == ''
if url.nil? || url.match(/^https?:\/\//) if url.nil? || url.match(/^https?:\/\//)
@ -53,6 +68,24 @@ class Profile
end end
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 protected
def strip_names def strip_names

View file

@ -32,8 +32,18 @@
%dl.entity_photo %dl.entity_photo
%dt Photo %dt Photo
%dd %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 %dl.entity_searchable
%dt Searchable %dt Searchable
%dd %dd

View file

@ -5,7 +5,7 @@
default: default:
# Hostname of this host, as seen from the internet. # 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 # Set this to true in order to close signups. Users will still be
# able to invite other people to join. # able to invite other people to join.

View file

@ -8,7 +8,9 @@ module HCard
:given_name => doc.css(".given_name").text, :given_name => doc.css(".given_name").text,
:family_name => doc.css(".family_name").text, :family_name => doc.css(".family_name").text,
:url => doc.css("#pod_location").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 :searchable => doc.css(".searchable").text
} }
end end

View file

@ -4,7 +4,6 @@
describe 'making sure the config is parsed as should' do describe 'making sure the config is parsed as should' do
<<<<<<< HEAD
describe 'pod_url' do describe 'pod_url' do
it 'should have a trailing slash' do it 'should have a trailing slash' do
APP_CONFIG[:pod_url].should == 'http://example.org/' APP_CONFIG[:pod_url].should == 'http://example.org/'

View file

@ -1,54 +1,63 @@
<div id="content">
<div id='content'>
<h1>Alexander Hamiltom</h1> <h1>Alexander Hamiltom</h1>
<div id="content_inner"> <div id='content_inner'>
<div id="i" class="entity_profile vcard author"> <div class='entity_profile vcard author' id='i'>
<h2>User profile</h2> <h2>User profile</h2>
<dl class="entity_nickname"> <dl class='entity_nickname'>
<dt>Nickname</dt> <dt>Nickname</dt>
<dd> <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> </dd>
</dl> </dl>
<dl class="entity_given_name"> <dl class='entity_given_name'>
<dt>First name</dt> <dt>First name</dt>
<dd> <dd>
<span class="given_name" >Alexander</span> <span class='given_name'>Alexander</span>
</dd> </dd>
</dl> </dl>
<dl class="entity_family_name"> <dl class='entity_family_name'>
<dt>Family name</dt> <dt>Family name</dt>
<dd> <dd>
<span class="family_name" >Hamiltom</span> <span class='family_name'>Hamiltom</span>
</dd> </dd>
</dl> </dl>
<dl class="entity_fn"> <dl class='entity_fn'>
<dt>Full name</dt> <dt>Full name</dt>
<dd> <dd>
<span class="fn" >Alexander Hamiltom</span> <span class='fn'>Alexander Hamiltom</span>
</dd> </dd>
</dl> </dl>
<dl class="entity_url"> <dl class='entity_url'>
<dt>URL</dt> <dt>URL</dt>
<dd> <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> </dd>
</dl> </dl>
<dl class="entity_photo"> <dl class='entity_photo'>
<dt>Photo</dt> <dt>Photo</dt>
<dd> <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> </dd>
</dl> </dl>
<dl class="entity_note"> <dl class='entity_photo_medium'>
<dt>Note</dt> <dt>Photo</dt>
<dd class="note">Diaspora is awesome! vi is better than emacs!</dd> <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>
<dl class='entity_searchable'> <dl class='entity_searchable'>
<dt>Searchable</dt> <dt>Searchable</dt>
<dd> <dd>
<span class='searchable'>false</span> <span class='searchable'>false</span>
</dd> </dd>
</dl> </dl>
</div> </div>
</div> </div>
</div> </div>

View file

@ -11,8 +11,10 @@ describe HCard do
hcard = HCard.build raw_hcard hcard = HCard.build raw_hcard
hcard[:family_name].include?("Hamiltom").should be true hcard[:family_name].include?("Hamiltom").should be true
hcard[:given_name].include?("Alex").should be true hcard[:given_name].include?("Alex").should be true
hcard[:photo].include?("tom.jpg").should be true hcard[:photo].include?("thumb_large").should be true
hcard[:url].should == "http://tom.joindiaspora.com/" 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" hcard[:searchable].should == "false"
end end
end end