add acts_as_api to the models directly for now. the 'root node' problem (posts : {}) breaks backbone. wip

This commit is contained in:
danielgrippi 2011-11-29 11:02:57 -08:00 committed by Dennis Collinson
parent 2a13381773
commit 91ba6447d0
7 changed files with 42 additions and 15 deletions

View file

@ -73,6 +73,7 @@ gem 'jammit', '0.6.5'
gem 'json', '1.5.2' gem 'json', '1.5.2'
gem 'vanna', :git => 'git://github.com/MikeSofaer/vanna.git' gem 'vanna', :git => 'git://github.com/MikeSofaer/vanna.git'
gem 'acts_as_api'
# localization # localization

View file

@ -85,6 +85,10 @@ GEM
activemodel (= 3.0.11) activemodel (= 3.0.11)
activesupport (= 3.0.11) activesupport (= 3.0.11)
activesupport (3.0.11) activesupport (3.0.11)
acts_as_api (0.3.11)
activemodel (>= 3.0.0)
activesupport (>= 3.0.0)
rack (>= 1.1.0)
addressable (2.2.4) addressable (2.2.4)
archive-tar-minitar (0.5.2) archive-tar-minitar (0.5.2)
arel (2.0.10) arel (2.0.10)
@ -450,6 +454,7 @@ DEPENDENCIES
SystemTimer (= 1.2.3) SystemTimer (= 1.2.3)
activerecord-import activerecord-import
acts-as-taggable-on! acts-as-taggable-on!
acts_as_api
addressable (= 2.2.4) addressable (= 2.2.4)
bundler (>= 1.0.0) bundler (>= 1.0.0)
capistrano (~> 2.9.0) capistrano (~> 2.9.0)

View file

@ -13,7 +13,8 @@ class MultisController < ApplicationController
respond_with do |format| respond_with do |format|
format.html{ default_stream_action(Stream::Multi) } format.html{ default_stream_action(Stream::Multi) }
format.json{ render :json => stream(Stream::Multi).stream_posts.to_json(:include => {:author => {:include => :profile}}) } #format.json{ render :json => stream(Stream::Multi).stream_posts.to_json(:include => {:author => {:include => :profile}}) }
format.json{ render_for_api :backbone, :json => stream(Stream::Multi).stream_posts }
end end
end end
end end

View file

@ -10,13 +10,25 @@ class Person < ActiveRecord::Base
include Encryptor::Public include Encryptor::Public
include Diaspora::Guid include Diaspora::Guid
# NOTE API V1 to be extracted
acts_as_api
api_accessible :post do |t|
t.add :id
t.add :name
t.add lambda { |person|
{:small => person.profile.image_url(:small),
:medium => person.profile.image_url(:medium),
:large => person.profile.image_url(:large) }
}, :as => :avatar
end
xml_attr :diaspora_handle xml_attr :diaspora_handle
xml_attr :url xml_attr :url
xml_attr :profile, :as => Profile xml_attr :profile, :as => Profile
xml_attr :exported_key xml_attr :exported_key
has_one :profile, :dependent => :destroy has_one :profile, :dependent => :destroy
delegate :last_name, :to => :profile delegate :last_name, :image_url, :to => :profile
accepts_nested_attributes_for :profile accepts_nested_attributes_for :profile
before_validation :downcase_diaspora_handle before_validation :downcase_diaspora_handle

View file

@ -9,6 +9,16 @@ class Post < ActiveRecord::Base
include Diaspora::Commentable include Diaspora::Commentable
include Diaspora::Shareable include Diaspora::Shareable
# NOTE API V1 to be extracted
acts_as_api
api_accessible :backbone do |t|
t.add :id
t.add :guid
t.add :text
t.add :created_at
t.add :author, :template => :post
end
xml_attr :provider_display_name xml_attr :provider_display_name
has_many :mentions, :dependent => :destroy has_many :mentions, :dependent => :destroy

View file

@ -29,10 +29,10 @@ class Profile < ActiveRecord::Base
before_save :strip_names before_save :strip_names
after_validation :strip_names after_validation :strip_names
validates :first_name, :length => { :maximum => 32 } validates :first_name, :length => { :maximum => 32 }
validates :last_name, :length => { :maximum => 32 } validates :last_name, :length => { :maximum => 32 }
validates_format_of :first_name, :with => /\A[^;]+\z/, :allow_blank => true validates_format_of :first_name, :with => /\A[^;]+\z/, :allow_blank => true
validates_format_of :last_name, :with => /\A[^;]+\z/, :allow_blank => true validates_format_of :last_name, :with => /\A[^;]+\z/, :allow_blank => true
validate :max_tags validate :max_tags

View file

@ -1,6 +1,4 @@
<% var post = typeof(status_message) === "undefined" ? (typeof(reshare) === "undefined" ? photo : reshare) : status_message; %> <div id="<%= guid %>" class="stream_element">
<div id="<%= post.guid %>" class="stream_element">
<div class="right controls"> <div class="right controls">
<a href="#" class="block_user control_icon"> <a href="#" class="block_user control_icon">
<img src="/images/icons/ignoreuser.png"> <img src="/images/icons/ignoreuser.png">
@ -15,32 +13,32 @@
<div class="sm_body"> <div class="sm_body">
<a href="/people/<%= post.author.id %>"> <a href="/people/<%= author.id %>">
<img src="<%= post.author.profile.image_url_small %>" class="avatar" data-person-id="<%= post.author.id %>"/> <img src="<%= author.profile.image_url_small %>" class="avatar" data-person-id="<%= post.author.id %>"/>
</a> </a>
<div class="content"> <div class="content">
<div class="post_initial_info"> <div class="post_initial_info">
<span class="from"> <span class="from">
<a href="/people/<%= post.author.id %>"> <a href="/people/<%= author.id %>">
<%= post.author.profile.full_name %> <%= author.profile.full_name %>
</a> </a>
</span> </span>
<span class="details"> <span class="details">
- -
<a href="/posts/<%= post.id %>"> <a href="/posts/<%= id %>">
<time class="timeago" datetime="<%= post.created_at %>"/> <time class="timeago" datetime="<%= created_at %>"/>
</a> </a>
</span> </span>
<p> <p>
<%= post.text %> <%= text %>
</p> </p>
<div class="info"> <div class="info">
<span class="via"> <span class="via">
via <%= post.provider_display_name %> via <%= provider_display_name %>
</span> </span>
</div> </div>