summaryrefslogtreecommitdiff
path: root/lib/static_page_array.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-02-12 21:33:39 -0800
committerelijah <elijah@riseup.net>2013-02-12 21:33:39 -0800
commit71ec0edea3f87fb69222dbb6fe025c2211402ca2 (patch)
tree5490323e8686df14165ccf5f37fa2d691fc99b88 /lib/static_page_array.rb
parent00c785b728c5d97335b87e3eb7d10b9ad0c46d35 (diff)
added capacity for pulling static pages from multiple directory source trees.
Diffstat (limited to 'lib/static_page_array.rb')
-rw-r--r--lib/static_page_array.rb32
1 files changed, 32 insertions, 0 deletions
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