-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move core helper methods to ContextHelper from haml helpers.
- Loading branch information
Bob McWhirter
committed
Mar 1, 2010
1 parent
18ac214
commit 31236fa
Showing
3 changed files
with
36 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'hpricot' | ||
|
||
module Awestruct | ||
module ContextHelper | ||
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 | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.