a user can put tags in their profile and they show up on the person/show page.

This commit is contained in:
danielgrippi 2011-03-15 11:27:08 -07:00
parent 20f5105e5d
commit 1988e195fb
9 changed files with 44 additions and 20 deletions

View file

@ -101,6 +101,10 @@ class Profile < ActiveRecord::Base
end end
end end
def tag_string
@tag_string || self.tags.map{|t| '#' << t.to_s }.join(' ')
end
protected protected
def strip_names def strip_names

View file

@ -204,6 +204,11 @@ class User < ActiveRecord::Base
params[:image_url_medium] = photo.url(:thumb_medium) params[:image_url_medium] = photo.url(:thumb_medium)
params[:image_url_small] = photo.url(:thumb_small) params[:image_url_small] = photo.url(:thumb_small)
end end
if tag_string = params.delete(:tags)
self.person.profile.tag_string = tag_string
self.person.profile.build_tags
self.person.profile.save
end
if self.person.profile.update_attributes(params) if self.person.profile.update_attributes(params)
Postzord::Dispatch.new(self, profile).post Postzord::Dispatch.new(self, profile).post
true true

View file

@ -37,8 +37,15 @@
-if user_signed_in? && ((contact.persisted? && !contact.pending?) || person == current_user.person || @incoming_request) -if user_signed_in? && ((contact.persisted? && !contact.pending?) || person == current_user.person || @incoming_request)
%ul#profile_information %ul#profile_information
%li - unless person.profile.tags.blank?
- unless person.profile.bio.blank? %li
%h4
tags
= person.profile.format_tags(person.profile.tag_string)
- unless person.profile.bio.blank?
%li
%h4 %h4
=t('.bio') =t('.bio')
= markdownify(person.profile.bio, :newlines => true) = markdownify(person.profile.bio, :newlines => true)

View file

@ -31,7 +31,7 @@
%h4 %h4
= t('profiles.edit.your_tags') = t('profiles.edit.your_tags')
= text_field_tag 'profile[tags]', profile.tags, :placeholder => t('.your_tags_placeholder') = text_field_tag 'profile[tags]', profile.tag_string, :placeholder => t('.your_tags_placeholder')
%h4 %h4
= t('profiles.edit.your_bio') = t('profiles.edit.your_bio')

View file

@ -6,16 +6,14 @@ module Diaspora
module Taggable module Taggable
def self.included(model) def self.included(model)
model.class_eval do model.class_eval do
cattr_accessor :field_with_tags
cattr_reader :field_with_tags end
model.instance_eval do
def self.extract_tags_from sym def extract_tags_from sym
puts "extract_tags_from" self.field_with_tags = sym
pp self
@field_with_tags = sym
end end
def self.field_with_tags_setter def field_with_tags_setter
@field_with_tags_setter = "#{@field_with_tags}=".to_sym "#{self.field_with_tags}=".to_sym
end end
end end
end end
@ -26,8 +24,6 @@ module Diaspora
def tag_strings def tag_strings
regex = /(?:^|\s)#(\w+)/ regex = /(?:^|\s)#(\w+)/
puts "tag strings"
pp self
matches = self.send(self.class.field_with_tags).scan(regex).map do |match| matches = self.send(self.class.field_with_tags).scan(regex).map do |match|
match.last match.last
end end
@ -42,9 +38,9 @@ module Diaspora
return text if opts[:plain_text] return text if opts[:plain_text]
regex = /(^|\s)#(\w+)/ regex = /(^|\s)#(\w+)/
form_message = text.gsub(regex) do |matched_string| form_message = text.gsub(regex) do |matched_string|
"#{$~[1]}<a href=\"/p?tag=#{$~[2]}\" class=\"tag\">##{ERB::Util.h($~[2])}</a>" "#{$~[1]}<a href=\"/p?tag=#{$~[2]}\" class=\"tag\">##{$~[2]}</a>"
end end
form_message form_message.html_safe
end end
end end
end end

View file

@ -50,7 +50,7 @@ describe ProfilesController do
{ :tags => '#apples #oranges'}} { :tags => '#apples #oranges'}}
put :update, params put :update, params
@user.person(true).profile.tags.should =~ ['apples', 'oranges'] @user.person(true).profile.tag_list.to_set.should == ['apples', 'oranges'].to_set
end end
context 'with a profile photo set' do context 'with a profile photo set' do

View file

@ -148,7 +148,8 @@ describe Profile do
describe 'tags' do describe 'tags' do
before do before do
@object = Factory.build(:profile) person = Factory.create(:person)
@object = person.profile
end end
it_should_behave_like 'it is taggable' it_should_behave_like 'it is taggable'
end end

View file

@ -253,6 +253,13 @@ describe User do
:last_name => 'billytown', :last_name => 'billytown',
} }
end end
it 'dispatches the profile when tags are set' do
@params = {:tags => '#what #hey'}
mailman = Postzord::Dispatch.new(alice, Profile.new)
Postzord::Dispatch.should_receive(:new).and_return(mailman)
mailman.should_receive(:deliver_to_local)
alice.update_profile(@params).should be_true
end
it 'sends a profile to their contacts' do it 'sends a profile to their contacts' do
mailman = Postzord::Dispatch.new(alice, Profile.new) mailman = Postzord::Dispatch.new(alice, Profile.new)
Postzord::Dispatch.should_receive(:new).and_return(mailman) Postzord::Dispatch.should_receive(:new).and_return(mailman)

View file

@ -6,13 +6,17 @@ require 'spec_helper'
describe Diaspora::Taggable do describe Diaspora::Taggable do
shared_examples_for "it is taggable" do shared_examples_for "it is taggable" do
include ActionView::Helpers::UrlHelper
include Rails.application.routes.url_helpers
def controller
end
describe '#format_tags' do describe '#format_tags' do
before do before do
@str = '#what #hey' @str = '#what #hey'
@object.send(@object.class.field_with_tags_setter, @str) @object.send(@object.class.field_with_tags_setter, @str)
@object.build_tags @object.build_tags
@object.save @object.save!
@object.reload
end end
it 'links the tag to /p' do it 'links the tag to /p' do
link = link_to('#what', posts_path(:tag => 'what'), :class => 'tag') link = link_to('#what', posts_path(:tag => 'what'), :class => 'tag')