Class: Filter::URI
Constant Summary
Constants inherited from Filter
Instance Attribute Summary collapse
-
#new_window ⇒ Object
readonly
Weither or not to open in a new window.
Attributes inherited from Filter
Instance Method Summary collapse
-
#filter! ⇒ Object
Convert URIs to anchor tags.
-
#initialize(string, options = {}) ⇒ URI
constructor
Initialize with string and options.
Methods inherited from Filter
Profanity, Profanity!, #filter, inherited
Constructor Details
#initialize(string, options = {}) ⇒ URI
Initialize with string and options.
14 15 16 17 |
# File 'lib/filters/uri.rb', line 14 def initialize string, = {} super @new_window = .fetch :new_window, false end |
Instance Attribute Details
#new_window ⇒ Object (readonly)
Weither or not to open in a new window.
9 10 11 |
# File 'lib/filters/uri.rb', line 9 def new_window @new_window end |
Instance Method Details
#filter! ⇒ Object
Convert URIs to anchor tags.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/filters/uri.rb', line 22 def filter! string.gsub! ::URI.regexp do |uri| if new_window %(<a href="#{uri}" target="_blank">#{uri}</a>) else %(<a href="#{uri}">#{uri}</a>) end end string end |