Permalink
Browse files

update rdoc

  • Loading branch information...
1 parent c1e30b1 commit 5c15134720a7f635556a31d15b3ac89142c65001 @keitaf keitaf committed Jun 6, 2012
Showing with 24 additions and 2 deletions.
  1. +22 −0 lib/twitter-text/autolink.rb
  2. +2 −2 spec/autolinking_spec.rb
@@ -94,6 +94,11 @@ def auto_link_entities(text, entities, options = {}, &block)
# <tt>:username_include_symbol</tt>:: place the <tt>@</tt> symbol within username and list links
# <tt>:suppress_lists</tt>:: disable auto-linking to lists
# <tt>:suppress_no_follow</tt>:: do not add <tt>rel="nofollow"</tt> to auto-linked items
+ # <tt>:symbol_tag</tt>:: tag to apply around symbol (@, #, $) in username / hashtag / cashtag links
+ # <tt>:text_with_symbol_tag</tt>:: tag to apply around text part in username / hashtag / cashtag links
+ # <tt>:url_target</tt>:: the value for <tt>target</tt> attribute on URL links.
+ # <tt>:link_attribute_block</tt>:: function to modify the attributes of a link based on the entity. called with |entity, attributes| params, and should modify the attributes hash.
+ # <tt>:link_text_block</tt>:: function to modify the text of a link based on the entity. called with |entity, text| params, and should return a modified text.
def auto_link(text, options = {}, &block)
auto_link_entities(text, Extractor.extract_entities_with_indices(text, :extract_url_without_protocol => false), options, &block)
end
@@ -110,6 +115,10 @@ def auto_link(text, options = {}, &block)
# <tt>:username_include_symbol</tt>:: place the <tt>@</tt> symbol within username and list links
# <tt>:suppress_lists</tt>:: disable auto-linking to lists
# <tt>:suppress_no_follow</tt>:: do not add <tt>rel="nofollow"</tt> to auto-linked items
+ # <tt>:symbol_tag</tt>:: tag to apply around symbol (@, #, $) in username / hashtag / cashtag links
+ # <tt>:text_with_symbol_tag</tt>:: tag to apply around text part in username / hashtag / cashtag links
+ # <tt>:link_attribute_block</tt>:: function to modify the attributes of a link based on the entity. called with |entity, attributes| params, and should modify the attributes hash.
+ # <tt>:link_text_block</tt>:: function to modify the text of a link based on the entity. called with |entity, text| params, and should return a modified text.
def auto_link_usernames_or_lists(text, options = {}, &block) # :yields: list_or_username
auto_link_entities(text, Extractor.extract_mentions_or_lists_with_indices(text), options, &block)
end
@@ -122,6 +131,10 @@ def auto_link_usernames_or_lists(text, options = {}, &block) # :yields: list_or_
# <tt>:hashtag_class</tt>:: class to add to hashtag <tt><a></tt> tags
# <tt>:hashtag_url_base</tt>:: the value for <tt>href</tt> attribute. The hashtag text (minus the <tt>#</tt>) will be appended at the end of this.
# <tt>:suppress_no_follow</tt>:: do not add <tt>rel="nofollow"</tt> to auto-linked items
+ # <tt>:symbol_tag</tt>:: tag to apply around symbol (@, #, $) in username / hashtag / cashtag links
+ # <tt>:text_with_symbol_tag</tt>:: tag to apply around text part in username / hashtag / cashtag links
+ # <tt>:link_attribute_block</tt>:: function to modify the attributes of a link based on the entity. called with |entity, attributes| params, and should modify the attributes hash.
+ # <tt>:link_text_block</tt>:: function to modify the text of a link based on the entity. called with |entity, text| params, and should return a modified text.
def auto_link_hashtags(text, options = {}, &block) # :yields: hashtag_text
auto_link_entities(text, Extractor.extract_hashtags_with_indices(text), options, &block)
end
@@ -134,6 +147,10 @@ def auto_link_hashtags(text, options = {}, &block) # :yields: hashtag_text
# <tt>:cashtag_class</tt>:: class to add to cashtag <tt><a></tt> tags
# <tt>:cashtag_url_base</tt>:: the value for <tt>href</tt> attribute. The cashtag text (minus the <tt>$</tt>) will be appended at the end of this.
# <tt>:suppress_no_follow</tt>:: do not add <tt>rel="nofollow"</tt> to auto-linked items
+ # <tt>:symbol_tag</tt>:: tag to apply around symbol (@, #, $) in username / hashtag / cashtag links
+ # <tt>:text_with_symbol_tag</tt>:: tag to apply around text part in username / hashtag / cashtag links
+ # <tt>:link_attribute_block</tt>:: function to modify the attributes of a link based on the entity. called with |entity, attributes| params, and should modify the attributes hash.
+ # <tt>:link_text_block</tt>:: function to modify the text of a link based on the entity. called with |entity, text| params, and should return a modified text.
def auto_link_cashtags(text, options = {}, &block) # :yields: cashtag_text
auto_link_entities(text, Extractor.extract_cashtags_with_indices(text), options, &block)
end
@@ -146,6 +163,11 @@ def auto_link_cashtags(text, options = {}, &block) # :yields: cashtag_text
# <tt>:url_class</tt>:: class to add to url <tt><a></tt> tags
# <tt>:invisible_tag_attrs</tt>:: HTML attribute to add to invisible span tags
# <tt>:suppress_no_follow</tt>:: do not add <tt>rel="nofollow"</tt> to auto-linked items
+ # <tt>:symbol_tag</tt>:: tag to apply around symbol (@, #, $) in username / hashtag / cashtag links
+ # <tt>:text_with_symbol_tag</tt>:: tag to apply around text part in username / hashtag / cashtag links
+ # <tt>:url_target</tt>:: the value for <tt>target</tt> attribute on URL links.
+ # <tt>:link_attribute_block</tt>:: function to modify the attributes of a link based on the entity. called with |entity, attributes| params, and should modify the attributes hash.
+ # <tt>:link_text_block</tt>:: function to modify the text of a link based on the entity. called with |entity, text| params, and should return a modified text.
def auto_link_urls(text, options = {}, &block)
auto_link_entities(text, Extractor.extract_urls_with_indices(text, :extract_url_without_protocol => false), options, &block)
end
View
@@ -683,7 +683,7 @@ def original_text; "Single char file ext http://www.bestbuy.com/site/Currie+Tech
linked.should have_autolinked_url('dummy', 'http://example.com/')
end
- it "should customie HTML attributes by link_attribute_block" do
+ it "should modify link attributes by link_attribute_block" do
linked = @linker.auto_link("#hash @mention",
:link_attribute_block => lambda{|entity, attributes|
attributes[:"dummy-hash-attr"] = "test" if entity[:hashtag]
@@ -692,7 +692,7 @@ def original_text; "Single char file ext http://www.bestbuy.com/site/Currie+Tech
linked.should match(/<a[^>]+hashtag[^>]+dummy-hash-attr=\"test\"[^>]+>/)
linked.should_not match(/<a[^>]+username[^>]+dummy-hash-attr=\"test\"[^>]+>/)
linked.should_not match(/link_attribute_block/i)
-
+
linked = @linker.auto_link("@mention http://twitter.com/",
:link_attribute_block => lambda{|entity, attributes|
attributes["dummy-url-attr"] = entity[:url] if entity[:url]

0 comments on commit 5c15134

Please sign in to comment.