class Textp::HtmlHelper
Public Class Methods
new(text)
click to toggle source
# File lib/textp/html_helper.rb, line 7 def initialize(text) @text = text @parser = Parser.new(text) end
Public Instance Methods
links()
click to toggle source
# File lib/textp/html_helper.rb, line 12 def links links = { :links => @parser.links } end
links_content()
click to toggle source
# File lib/textp/html_helper.rb, line 16 def links_content oembed_data = {} OEmbed::Providers.register(OEmbed::Providers::Youtube) @parser.links.each do |link| resource = OEmbed::Providers.get(link) oembed_data[link] ||= {} oembed_data[link][:html] ||= resource.html oembed_data[link][:provider] ||= { :endpoint => resource.provider.endpoint } end oembed_data end
parser()
click to toggle source
# File lib/textp/html_helper.rb, line 30 def parser @parser end
replacement_content()
click to toggle source
# File lib/textp/html_helper.rb, line 41 def replacement_content content = @text @parser.links.each do |link| html_content = links_content[link][:html] content.gsub!(link, html_content) end content end
response()
click to toggle source
# File lib/textp/html_helper.rb, line 34 def response json_string = { :links => @parser.links, :oembed_data => links_content }.to_json end