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
Constructor Details
#initialize(string, options = {}) ⇒ URI
Initialize with string and options.
13 14 15 16 |
# File 'lib/filters/uri.rb', line 13 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.
8 9 10 |
# File 'lib/filters/uri.rb', line 8 def new_window @new_window end |
Instance Method Details
#filter! ⇒ Object
Convert URIs to anchor tags.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/filters/uri.rb', line 21 def filter! string.gsub! /\w+:\/\/(.*?)(\s+|$)/ do |uri| if new_window %(<a href="#{uri.strip}" target="_blank">#{uri}</a>) else %(<a href="#{uri.strip}">#{uri}</a>) end end string end |