From cae440740f803b7832ea81006c7cf5675a9829df Mon Sep 17 00:00:00 2001 From: Torsten Curdt Date: Thu, 12 May 2011 13:43:41 +0200 Subject: [PATCH] for now moved the collections extension back into my site, helper method to strip images, whitespace, fixed the atom template in regards to author support --- lib/awestruct/context_helper.rb | 10 ++-- lib/awestruct/engine.rb | 1 - lib/awestruct/extensions/collection.rb | 52 --------------------- lib/awestruct/extensions/template.atom.haml | 23 ++++++--- 4 files changed, 23 insertions(+), 63 deletions(-) delete mode 100644 lib/awestruct/extensions/collection.rb diff --git a/lib/awestruct/context_helper.rb b/lib/awestruct/context_helper.rb index ca17ec26..7d642854 100644 --- a/lib/awestruct/context_helper.rb +++ b/lib/awestruct/context_helper.rb @@ -11,13 +11,17 @@ def clean_html(str) str.gsub( / /, ' ' ) end + def without_images(str) + str.gsub(/]+>/,'').gsub(/]+>([^<]*)<\/a>/, '\1') + 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 @@ -29,7 +33,7 @@ def fully_qualify_urls(base_url, text) end return doc.to_s end - + def fix_url(base_url, url) return url unless ( url =~ /^\// ) "#{base_url}#{url}" diff --git a/lib/awestruct/engine.rb b/lib/awestruct/engine.rb index c8e6ed55..7457e69f 100644 --- a/lib/awestruct/engine.rb +++ b/lib/awestruct/engine.rb @@ -22,7 +22,6 @@ require 'awestruct/extensions/pipeline' require 'awestruct/extensions/posts' -require 'awestruct/extensions/collection' require 'awestruct/extensions/indexifier' require 'awestruct/extensions/data_dir' require 'awestruct/extensions/paginator' diff --git a/lib/awestruct/extensions/collection.rb b/lib/awestruct/extensions/collection.rb deleted file mode 100644 index 863b7ae2..00000000 --- a/lib/awestruct/extensions/collection.rb +++ /dev/null @@ -1,52 +0,0 @@ - -module Awestruct - module Extensions - class Collection - - def initialize(assign_to, path_prefix = nil, default_layout = nil) - @assign_to = assign_to - @path_prefix = path_prefix || '_' + assign_to.to_s - @default_layout = default_layout || assign_to.to_s.singularize - end - - def execute(site) - posts = [] - - Dir[ "#{@path_prefix}/*" ].each do |entry| - if entry =~ /^#{@path_prefix}\/(20[01][0-9])-([01][0-9])-([0123][0-9])-([^.]+)\..*$/ - if ( File.directory?( entry ) ) - # TODO deal with dirs - else - page = site.engine.load_page( entry ) - year = $1 - month = $2 - day = $3 - slug = $4 - page.date = Time.utc( year.to_i, month.to_i, day.to_i ) - page.slug = slug - page.output_path = "/#{year}/#{month}/#{day}/#{slug}/index.html" - page.layout ||= @default_layout - - posts << page - site.pages << page - end - end - end - - posts = posts.sort_by{|each| [each.date, each.sequence || 0, File.mtime( each.source_path ), each.slug ] }.reverse - - last = nil - singular = @assign_to.to_s.singularize - posts.each do |e| - if ( last != nil ) - e.send( "next_#{singular}=", last ) - last.send( "previous_#{singular}=", e ) - end - last = e - end - - site.send( "#{@assign_to}=", posts ) - end - end - end -end diff --git a/lib/awestruct/extensions/template.atom.haml b/lib/awestruct/extensions/template.atom.haml index fd45425d..f4dd86d9 100644 --- a/lib/awestruct/extensions/template.atom.haml +++ b/lib/awestruct/extensions/template.atom.haml @@ -5,6 +5,14 @@ %feed{ 'xml:base'=>site.base_url, 'xml:lang'=>'en-US', :xmlns=>'http://www.w3.org/2005/Atom' } %id #{site.base_url} %title #{page.title} + - if ( defined?( site.author ) ) + %author + - if ( defined?( site.author.name ) ) + %name= site.author.name + - if ( site.author.email ) + %email= site.author.email + - else + %name= site.author - unless page.entries.empty? %updated= page.entries.first.date.xmlschema %link{:rel=>"alternate", :type=>"text/html", :href=>site.base_url} @@ -15,13 +23,14 @@ %title= escape_once( entry.title ) %updated= entry.date.xmlschema %link{:rel=>"alternate", :type=>"text/html", :href=>"#{site.base_url}#{entry.url}" } - %author - - if ( defined?( entry.author.name ) ) - %name= entry.author.name - - if ( entry.author.email ) - %name= entry.author.email - - else - %name= entry.author + - if ( defined?( entry.author ) ) + %author + - if ( defined?( entry.author.name ) ) + %name= entry.author.name + - if ( entry.author.email ) + %email= entry.author.email + - else + %name= entry.author %summary #{summarize( html_to_text( entry.content ), 100 )}... %content{:type=>'html'}