Created
March 11, 2011 07:31
-
-
Save ramontayag/865578 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PagesDrop < Liquid::Drop | |
def initialize(pages) | |
# the arg passed in should always be an AR Relation (AREL) | |
@pages = pages | |
end | |
def group_by | |
GroupByDrop.new(@pages) | |
end | |
def all | |
# When you're happy with the final code, you need to call .all to get an array back and work with that in liquid | |
@pages.is_a?(Array) ? @pages : @pages.all | |
end | |
def size | |
@pages.size | |
end | |
def published | |
PagesDrop.new @pages.published | |
end | |
def before_method(method_name) | |
if method_name =~ /named_([\S]+)/ | |
method_name.gsub!(/^(named_)/){""} | |
PagesDrop.new(@pages.named(method_name)) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment