Sha256: ad51ec87408ebd9e738550185347dd8550cb5631b20a0c283b8954a921950f03
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
# major portion of code in here is copied/adjusted from # ActionView::Helpers::TagHelper and # ActionView::Helpers::TextHelper # AutoHtml.add_filter(:link).with({}) do |text, options| def tag_options(options) unless options.blank? attrs = [] attrs = options.map { |key, value| %(#{key}="#{value}") } " #{attrs.sort * ' '}" unless attrs.empty? end end def auto_link_re %r{ ( # leading text <\w+.*?>| # leading HTML tag, or [^=!:'"/]| # leading punctuation, or ^ # beginning of line ) ( (?:https?://)| # protocol spec, or (?:www\.) # www.* ) ( [-\w]+ # subdomain or domain (?:\.[-\w]+)* # remaining subdomains or domain (?::\d+)? # port (?:/(?:[~\w\+@%=\(\)-]|(?:[,.;:'][^\s$]))*)* # path (?:[\?|\#][\w\+@%&=.;:-]+)? # query string (?:\#[\w\-]*)? # trailing anchor ) ([[:punct:]]|<|$|) # trailing text }x end extra_options = tag_options(options.stringify_keys) || "" text.gsub(auto_link_re) do all, a, b, c, d = $&, $1, $2, $3, $4 if a =~ /<a\s/i # don't replace URL's that are already linked all else text = b + c %(#{a}<a href="#{b=="www."?"http://www.":b}#{c}"#{extra_options}>#{text}</a>#{d}) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dejan-auto_html-1.1.2 | lib/auto_html/filters/link.rb |