From ec05c214720fd1cb8678c606e36d355c6e3bc28f Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 30 Nov 2010 13:29:17 -0800 Subject: [PATCH] profile now knows about three images sizes, even in federation case --- app/controllers/people_controller.rb | 2 ++ app/helpers/application_helper.rb | 5 +-- app/models/person.rb | 2 ++ app/models/profile.rb | 35 ++++++++++++++++++- app/views/publics/hcard.haml | 12 ++++++- config/app_config.yml.example | 2 +- lib/hcard.rb | 4 ++- spec/config/config_spec.rb | 1 - spec/fixtures/hcard_response | 51 ++++++++++++++++------------ spec/lib/hcard_spec.rb | 6 ++-- 10 files changed, 90 insertions(+), 30 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 428bb58c7..f7e35c779 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -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] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b5192caee..9879e971f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -105,8 +105,9 @@ module ApplicationHelper ".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 diff --git a/app/models/person.rb b/app/models/person.rb index d6bd1800c..ed0aa2ac3 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/app/models/profile.rb b/app/models/profile.rb index 46f0c8235..7794c287e 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -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 diff --git a/app/views/publics/hcard.haml b/app/views/publics/hcard.haml index be6bf2bcb..f6e4c4408 100644 --- a/app/views/publics/hcard.haml +++ b/app/views/publics/hcard.haml @@ -32,8 +32,18 @@ %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 %dd diff --git a/config/app_config.yml.example b/config/app_config.yml.example index 3aef91197..9e3f0d298 100644 --- a/config/app_config.yml.example +++ b/config/app_config.yml.example @@ -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. diff --git a/lib/hcard.rb b/lib/hcard.rb index 09acb7c8f..01cf104f6 100644 --- a/lib/hcard.rb +++ b/lib/hcard.rb @@ -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 diff --git a/spec/config/config_spec.rb b/spec/config/config_spec.rb index 270b3726b..de5c1f755 100644 --- a/spec/config/config_spec.rb +++ b/spec/config/config_spec.rb @@ -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/' diff --git a/spec/fixtures/hcard_response b/spec/fixtures/hcard_response index d229660d2..302c02430 100644 --- a/spec/fixtures/hcard_response +++ b/spec/fixtures/hcard_response @@ -1,54 +1,63 @@ -
+ +

Alexander Hamiltom

-
-
+
+

User profile

-
+
Nickname
- Alexander Hamiltom + Alexander Hamiltom
-
+
First name
- Alexander + Alexander
-
-
+
+
Family name
- Hamiltom + Hamiltom
-
-
+
+
Full name
- Alexander Hamiltom + Alexander Hamiltom
-
+
URL
- http://tom.joindiaspora.com/ + http://localhost:3000/
-
+
Photo
- +
-
-
Note
-
Diaspora is awesome! vi is better than emacs!
+
+
Photo
+
+ +
+
+
+
Photo
+
+ +
Searchable
false
-
+
diff --git a/spec/lib/hcard_spec.rb b/spec/lib/hcard_spec.rb index fbd4bb42c..3e11017bb 100644 --- a/spec/lib/hcard_spec.rb +++ b/spec/lib/hcard_spec.rb @@ -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