Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add tags_tag helper method.

  • Loading branch information...
commit adf666024163e0ab7820d0cc15c35eeda9f36e49 1 parent 9569222
@mitukiii mitukiii authored
View
9 app/helpers/application_helper.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
View
12 spec/helpers/application_helper_spec.rb
@@ -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' }
Please sign in to comment.
Something went wrong with that request. Please try again.