Skip to content

Instantly share code, notes, and snippets.

@ramontayag
Created October 21, 2010 09:50
Show Gist options
  • Save ramontayag/638224 to your computer and use it in GitHub Desktop.
Save ramontayag/638224 to your computer and use it in GitHub Desktop.
class PageDrop < Liquid::Drop
def initialize(page)
@page = page
end
def name
@page.name
end
def children
PagesDrop.new(page.children)
end
end
class PagesDrop < Liquid::Drop
def initialize(pages)
@pages = pages
end
def group_by
GroupByDrop.new(@pages)
end
def all
@pages.all
end
def size
@pages.size
end
end
@ramontayag
Copy link
Author

In case you don't know, a drop is what the Liquid templating language uses to expose methods/data of a particular object (because you don't want the user to have full access to the system in the templating language).

I want to be able to do this:

@page_drop = PageDrop.new(@page)
@page_drop.children # to get an array of children

instead of

@page_drop.children.all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment