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(-) 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