Module: Readability::Harmonizable
- Included in:
- Readable
- Defined in:
- lib/readability/harmonizable.rb
Instance Method Summary collapse
- #execute_js(code) ⇒ Object (also: #x)
- #harmony_page ⇒ Object
- #load_js(*paths) ⇒ Object
- #parse(string_or_io, url = nil, encoding = nil, options = Nokogiri::XML::ParseOptions::DEFAULT_HTML, &block) ⇒ Object
- #window ⇒ Object
Instance Method Details
#execute_js(code) ⇒ Object Also known as: x
18 19 20 21 22 23 24 25 26 |
# File 'lib/readability/harmonizable.rb', line 18 def execute_js(code) result = nil harmony_page do |page| result = page.execute_js(code) end result end |
#harmony_page ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/readability/harmonizable.rb', line 37 def harmony_page html = self.to_html # unless encoding is already utf[-8], convert using iconv unless =~ /utf/i begin require 'iconv' html = Iconv.new("UTF8", "LATIN1//TRANSLIT//IGNORE").iconv(self.to_html) rescue end end # load document into a page page = Harmony::Page.new(html) # yield the page and reparse if a block is given if block_given? yield page # parse the page back into the document parse(page.to_html) end page end |
#load_js(*paths) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/readability/harmonizable.rb', line 29 def load_js(*paths) harmony_page do |page| page.load(*paths) end self end |
#parse(string_or_io, url = nil, encoding = nil, options = Nokogiri::XML::ParseOptions::DEFAULT_HTML, &block) ⇒ Object
14 15 16 |
# File 'lib/readability/harmonizable.rb', line 14 def parse string_or_io, url = nil, encoding = nil, = Nokogiri::XML::ParseOptions::DEFAULT_HTML, &block self.root = Nokogiri::HTML::Document.parse(string_or_io, url, encoding, , &block).root end |
#window ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/readability/harmonizable.rb', line 3 def window if block_given? harmony_page do |page| yield page.window page.window end else harmony_page.window end end |