From c1854b8b518bde82b80429636f73496a537c3ad5 Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 1 Feb 2009 21:32:44 +0100 Subject: added first careful steps for aggregation --- app/helpers/content_helper.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'app/helpers') diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 0e1df66..046a2db 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -1,8 +1,29 @@ module ContentHelper - # def date_for_page page page.published_at.to_s(:db) rescue page.created_at.to_s(:db) end + def aggregate? content + options = {} + + if content =~ /]*)>/ + tag = $~.to_s + matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d]*\"/) + + matched_data.each do |data| + splitted_data = data.split("=") + options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "") + end + end + + content.sub(tag, render_collection(options)) + end + + def render_collection options + render( + :partial => 'content/article', + :collection => Page.aggregate(options) + ) + end end -- cgit v1.3 From 5a8c9154d504c5376e807716c0cfcb76ef766d88 Mon Sep 17 00:00:00 2001 From: hukl Date: Mon, 2 Feb 2009 00:37:42 +0100 Subject: made the whole aggregate helper exception safe by always falling back to the original content if something went wrong. only executing substitution if tag is found --- app/helpers/content_helper.rb | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 046a2db..3cf3488 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -7,17 +7,22 @@ module ContentHelper def aggregate? content options = {} - if content =~ /]*)>/ - tag = $~.to_s - matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d]*\"/) - - matched_data.each do |data| - splitted_data = data.split("=") - options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "") + begin + if content =~ /]*)>/ + tag = $~.to_s + matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d]*\"/) + + matched_data.each do |data| + splitted_data = data.split("=") + options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "") + end + + content.sub(tag, render_collection(options)) end + + rescue + content end - - content.sub(tag, render_collection(options)) end def render_collection options -- cgit v1.3