From 71ec0edea3f87fb69222dbb6fe025c2211402ca2 Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 12 Feb 2013 21:33:39 -0800 Subject: added capacity for pulling static pages from multiple directory source trees. --- lib/static_page_array.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/static_page_array.rb (limited to 'lib/static_page_array.rb') diff --git a/lib/static_page_array.rb b/lib/static_page_array.rb new file mode 100644 index 0000000..33b11e0 --- /dev/null +++ b/lib/static_page_array.rb @@ -0,0 +1,32 @@ +# +# Array of StaticPages +# +class StaticPageArray < Array + def limit(num) + StaticPageArray.new(self[0..(num-1)]) + end + def order_by(attr, options={}) + locale = options[:locale] || I18n.locale + direction = options[:direction] || :asc + array = sort do |a,b| + if direction == :desc + a, b = b, a + end + a_prop = a.props.locale(locale).send(attr) + b_prop = b.props.locale(locale).send(attr) + if a_prop.nil? && b_prop.nil? + 0 + elsif a_prop.nil? + 1 + elsif b_prop.nil? + -1 + else + a_prop <=> b_prop + end + end + array.delete_if do |page| + page.props.locale(locale).send(attr).nil? + end + return StaticPageArray.new.replace array + end +end \ No newline at end of file -- cgit v1.2.3