Skip to content

Commit

Permalink
Move core helper methods to ContextHelper from haml helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob McWhirter committed Mar 1, 2010
1 parent 18ac214 commit 31236fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
34 changes: 34 additions & 0 deletions lib/awestruct/context_helper.rb
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
3 changes: 2 additions & 1 deletion lib/awestruct/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
require 'awestruct/sass_file'
require 'awestruct/verbatim_file'

require 'awestruct/haml_helpers'
require 'awestruct/context_helper'

require 'awestruct/extensions/pipeline'
require 'awestruct/extensions/posts'
Expand Down Expand Up @@ -93,6 +93,7 @@ def load_page(path, relative_path=nil)

def create_context(page, content='')
context = OpenStruct.new( :site=>site, :content=>content )
context.extend( Awestruct::ContextHelper )
@helpers.each do |h|
context.extend( h )
end
Expand Down
32 changes: 0 additions & 32 deletions lib/awestruct/haml_helpers.rb

This file was deleted.

0 comments on commit 31236fa

Please sign in to comment.