Skip to content
Extraits de code Groupes Projets
Valider 1988e195 rédigé par danielgrippi's avatar danielgrippi
Parcourir les fichiers

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

parent 20f5105e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -101,6 +101,10 @@ class Profile < ActiveRecord::Base
end
end
def tag_string
@tag_string || self.tags.map{|t| '#' << t.to_s }.join(' ')
end
protected
def strip_names
......
......@@ -204,6 +204,11 @@ class User < ActiveRecord::Base
params[:image_url_medium] = photo.url(:thumb_medium)
params[:image_url_small] = photo.url(:thumb_small)
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)
Postzord::Dispatch.new(self, profile).post
true
......
......@@ -37,8 +37,15 @@
-if user_signed_in? && ((contact.persisted? && !contact.pending?) || person == current_user.person || @incoming_request)
%ul#profile_information
%li
- unless person.profile.bio.blank?
- unless person.profile.tags.blank?
%li
%h4
tags
= person.profile.format_tags(person.profile.tag_string)
- unless person.profile.bio.blank?
%li
%h4
=t('.bio')
= markdownify(person.profile.bio, :newlines => true)
......
......@@ -31,7 +31,7 @@
%h4
= 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
= t('profiles.edit.your_bio')
......
......@@ -6,16 +6,14 @@ module Diaspora
module Taggable
def self.included(model)
model.class_eval do
cattr_reader :field_with_tags
def self.extract_tags_from sym
puts "extract_tags_from"
pp self
@field_with_tags = sym
cattr_accessor :field_with_tags
end
model.instance_eval do
def extract_tags_from sym
self.field_with_tags = sym
end
def self.field_with_tags_setter
@field_with_tags_setter = "#{@field_with_tags}=".to_sym
def field_with_tags_setter
"#{self.field_with_tags}=".to_sym
end
end
end
......@@ -26,8 +24,6 @@ module Diaspora
def tag_strings
regex = /(?:^|\s)#(\w+)/
puts "tag strings"
pp self
matches = self.send(self.class.field_with_tags).scan(regex).map do |match|
match.last
end
......@@ -42,9 +38,9 @@ module Diaspora
return text if opts[:plain_text]
regex = /(^|\s)#(\w+)/
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
form_message
form_message.html_safe
end
end
end
......@@ -50,7 +50,7 @@ describe ProfilesController do
{ :tags => '#apples #oranges'}}
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
context 'with a profile photo set' do
......
......@@ -148,7 +148,8 @@ describe Profile do
describe 'tags' do
before do
@object = Factory.build(:profile)
person = Factory.create(:person)
@object = person.profile
end
it_should_behave_like 'it is taggable'
end
......
......@@ -253,6 +253,13 @@ describe User do
:last_name => 'billytown',
}
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
mailman = Postzord::Dispatch.new(alice, Profile.new)
Postzord::Dispatch.should_receive(:new).and_return(mailman)
......
......@@ -6,13 +6,17 @@ require 'spec_helper'
describe Diaspora::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
before do
@str = '#what #hey'
@object.send(@object.class.field_with_tags_setter, @str)
@object.build_tags
@object.save
@object.reload
@object.save!
end
it 'links the tag to /p' do
link = link_to('#what', posts_path(:tag => 'what'), :class => 'tag')
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter