Sha256: 275477488fedb9bc13d897dab5a5eb6835dc9729a799052c2633305bcf537482
Contents?: true
Size: 679 Bytes
Versions: 4
Compression:
Stored size: 679 Bytes
Contents
require 'hpricot' module Haml::Helpers def html_to_text(str) str.gsub( /<[^>]+>/, '' ) end def summarize(text, numwords=20) text.split()[0, numwords].join(' ') end def fully_qualify_urls(base_url, text) doc = Hpricot( text ) doc.search( "//a" ).each do |a| a['href'] = fix_url( base_url, a['href'] ) end doc.search( "//link" ).each do |link| link['href'] = fix_url( base_url, link['href'] ) end doc.search( "//img" ).each do |img| img['src'] = fix_url( base_url, img['src'] ) end return doc.to_s end def fix_url(base_url, url) return url unless ( url =~ /^\// ) "#{base_url}#{url}" end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
awestruct-0.0.4 | lib/awestruct/haml_helpers.rb |
awestruct-0.0.3 | lib/awestruct/haml_helpers.rb |
awestruct-0.0.2 | lib/awestruct/haml_helpers.rb |
awestruct-0.0.1 | lib/awestruct/haml_helpers.rb |