Sha256: 3b41f0b622371179e00833b899bab4d7c24b87da3696f17ac4ca77619a5e7071
Contents?: true
Size: 916 Bytes
Versions: 1
Compression:
Stored size: 916 Bytes
Contents
module RailsConnector class TextLinkConversion def initialize(text_links) @text_links = text_links end def convert(html) return html unless @text_links if html html.gsub(%r{<?\binternallink:(\d+)\b>?(['"]?)}) do link = @text_links[$1] postfix = $2 if link attach_snippet("#{convert_link(link)}#{postfix}", link) else "#__text_link_missing#{postfix}" end end end end private def convert_link(link) link.internal? ? convert_internal_link(link) : convert_external_link(link) end def attach_snippet(text, link) snippet = link.html_attribute_snippet if snippet.present? "#{text} #{snippet}" else text end end def convert_internal_link(link) "objid:#{link.obj_id}#{link.query_and_fragment}" end def convert_external_link(link) link.external_url end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
infopark_cloud_connector-7.1.0 | lib/rails_connector/text_link_conversion.rb |