Skip to content

Instantly share code, notes, and snippets.

@ramontayag
Created March 11, 2011 07:31
Show Gist options
  • Save ramontayag/865578 to your computer and use it in GitHub Desktop.
Save ramontayag/865578 to your computer and use it in GitHub Desktop.
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