Class: Textp::HtmlHelper
- Inherits:
-
Object
- Object
- Textp::HtmlHelper
- Defined in:
- lib/textp/html_helper.rb
Instance Method Summary collapse
-
#initialize(text) ⇒ HtmlHelper
constructor
A new instance of HtmlHelper.
- #links ⇒ Object
- #links_content ⇒ Object
- #parser ⇒ Object
- #replacement_content ⇒ Object
- #response ⇒ Object
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
#links ⇒ Object
12 13 14 |
# File 'lib/textp/html_helper.rb', line 12 def links links = { :links => @parser.links } end |
#links_content ⇒ Object
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::Providers.register(OEmbed::Providers::Youtube) @parser.links.each do |link| resource = OEmbed::Providers.get(link) [link] ||= {} [link][:html] ||= resource.html [link][:provider] ||= { :endpoint => resource.provider.endpoint } end end |
#parser ⇒ Object
30 31 32 |
# File 'lib/textp/html_helper.rb', line 30 def parser @parser end |
#replacement_content ⇒ Object
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 |
#response ⇒ Object
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 |