Class: Emcee::Document
- Inherits:
-
Object
- Object
- Emcee::Document
- Defined in:
- lib/emcee/document.rb
Overview
Document is responsible for parsing HTML and handling interaction with the resulting document.
Constant Summary collapse
- ENCODING =
'UTF-8'
Instance Method Summary collapse
- #html_imports ⇒ Object
-
#initialize(data) ⇒ Document
constructor
A new instance of Document.
- #script_references ⇒ Object
- #style_references ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ Document
Returns a new instance of Document.
10 11 12 |
# File 'lib/emcee/document.rb', line 10 def initialize(data) @doc = Nokogiri::HTML5.parse("<html><body>#{data}</body></html>") end |
Instance Method Details
#html_imports ⇒ Object
22 23 24 |
# File 'lib/emcee/document.rb', line 22 def html_imports wrap_nodes(@doc.css("link[rel='import']")) end |
#script_references ⇒ Object
26 27 28 |
# File 'lib/emcee/document.rb', line 26 def script_references wrap_nodes(@doc.css("script[src]")) end |
#style_references ⇒ Object
30 31 32 |
# File 'lib/emcee/document.rb', line 30 def style_references wrap_nodes(@doc.css("link[rel='stylesheet']")) end |
#to_s ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/emcee/document.rb', line 14 def to_s # Make an html string. The parser does weird things with certain # attributes, so turn those nodes into xhtml. xhtml_nodes = nodes_with_selected_attribute + nodes_with_src_attribute html = htmlify_except(xhtml_nodes) unescape(html).encode(ENCODING) end |