diaspora/app/presenters/hovercard_presenter.rb
Florian Staudacher 0092acd492 re-add hovercards
* added a presenter for hovercard json
* added new backbone view for handling hovercard JS
* refactoring of PeopleController

* finished the backbone js version of hovercards
* don't try to make people_controller more restfull, out of scope
  just add a new route and use that for hovercard json
* added spec for people_controller#hovercard
* add new exception for "AccountClosed" to be able to raise from anywhere

* removed legacy code, since everything got ported to backbone
  (except the "cache" stuff, but that's not strictly necessary)
2012-12-28 22:37:13 +01:00

39 lines
1.1 KiB
Ruby

class HovercardPresenter
attr_accessor :person
# initialize the presenter with the given Person object
def initialize(person)
raise ArgumentError, "the given object is not a Person" unless person.class == Person
self.person = person
end
# returns the json representation of the Person object for use with the
# hovercard UI
def to_json(options={})
{ :id => person.id,
:avatar => avatar('small'),
:url => profile_url,
:name => person.name,
:handle => person.diaspora_handle,
:tags => person.tags.map { |t| "#"+t.name }
}.to_json(options)
end
# get the image url of the profile avatar for the given size
# possible sizes: 'small', 'medium', 'large'
def avatar(size="small")
if !["small", "medium", "large"].include?(size)
raise ArgumentError, "the given parameter is not a valid size"
end
person.image_url("thumb_#{size}".to_sym)
end
# return the (relative) url to the user profile page.
# uses the 'person_path' url helper from the rails routes
def profile_url
Rails.application.routes.url_helpers.person_path(person)
end
end