Permalink
Browse files

Add tags_tag helper method.

  • Loading branch information...
1 parent 9569222 commit adf666024163e0ab7820d0cc15c35eeda9f36e49 @mitukiii mitukiii committed Dec 11, 2011
Showing with 21 additions and 0 deletions.
  1. +9 −0 app/helpers/application_helper.rb
  2. +12 −0 spec/helpers/application_helper_spec.rb
@@ -31,6 +31,15 @@ def photo_tag(photo, size)
}
end
+ def tags_tag(text)
+ return nil if text.blank?
+ text.gsub(/\#([a-zA-Z0-9_]*)/) do
+ tag = $1
+ return nil if tag.blank?
+ content_tag :a, "##{tag}", href: tags_url(name: tag)
+ end
+ end
+
def caption_text(photo)
photo.caption.text unless photo.caption.blank?
end
@@ -116,6 +116,18 @@
end
end
+ describe :tags_tag do
+ context 'have tag' do
+ subject { tags_tag 'text #tag1 #tag2' }
+ it { should == 'text <a href="http://test.host/tags/tag1">#tag1</a> <a href="http://test.host/tags/tag2">#tag2</a>' }
+ end
+
+ context 'not have tag' do
+ subject { tags_tag 'text text text' }
+ it { should == 'text text text' }
+ end
+ end
+
describe :caption_text do
subject { caption_text @photo }
it { should == 'caption text' }

0 comments on commit adf6660

Please sign in to comment.