Class: Textp::HtmlHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/textp/html_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ HtmlHelper

Returns a new instance of HtmlHelper.



7
8
9
10
# File 'lib/textp/html_helper.rb', line 7

def initialize(text)
  @text     = text
  @parser   = Parser.new(text)
end

Instance Method Details



12
13
14
# File 'lib/textp/html_helper.rb', line 12

def links
  links = { :links => @parser.links }
end


16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

#parserObject



30
31
32
# File 'lib/textp/html_helper.rb', line 30

def parser
  @parser
end

#replacement_contentObject



41
42
43
44
45
46
47
48
# 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

#responseObject



34
35
36
37
38
39
# File 'lib/textp/html_helper.rb', line 34

def response
  json_string = {
    :links => @parser.links,
    :oembed_data => links_content
  }.to_json
end