lib/awestruct/context_helper.rb in awestruct-0.5.6.beta3 vs lib/awestruct/context_helper.rb in awestruct-0.5.6.beta4

- old
+ new

@@ -1,9 +1,10 @@ -require 'nokogiri' +require 'rexml/document' module Awestruct module ContextHelper + include REXML def html_to_text(str) str.gsub( /<[^>]+>/, '' ).gsub( /&nbsp;/, ' ' ) end @@ -36,19 +37,22 @@ def summarize(text, numwords=20, ellipsis='...') close_tags(text.split(/ /)[0, numwords].join(' ') + ellipsis) end def fully_qualify_urls(base_url, text) - doc = Nokogiri::HTML.fragment( text ) + doc = Document.new text + doc.context[:attribute_quote] = :quote # Set double-quote as the attribute value delimiter - doc.css( "a" ).each do |a| - a['href'] = fix_url( base_url, a['href'] ) if a['href'] + XPath.each(doc, "//a") do |a| + a.attributes['href'] = fix_url( base_url, a.attributes['href'] ) if a.attributes['href'] end - doc.css( "link" ).each do |link| - link['href'] = fix_url( base_url, link['href'] ) + + XPath.each(doc, "//link") do |link| + link.attributes['href'] = fix_url( base_url, link.attributes['href'] ) end - doc.css( "img" ).each do |img| - img['src'] = fix_url( base_url, img['src'] ) + + XPath.each(doc, "//img") do |img| + img.attributes['src'] = fix_url( base_url, img.attributes['src'] ) end if RUBY_VERSION.start_with? '1.8' doc.to_s else