asciinema.org/app/presenters/browse_page_presenter.rb

44 lines
845 B
Ruby
Raw Normal View History

class BrowsePagePresenter
2014-01-17 16:21:22 +00:00
DEFAULT_CATEGORY = :public
DEFAULT_ORDER = :recency
PER_PAGE = 12
2014-01-17 16:21:22 +00:00
attr_reader :scope, :category, :order, :page, :per_page
2014-01-17 16:21:22 +00:00
def self.build(scope, category, order, page = nil, per_page = nil)
new(
scope,
(category || DEFAULT_CATEGORY).to_sym,
(order || DEFAULT_ORDER).to_sym,
page || 1,
per_page || PER_PAGE
)
end
def initialize(scope, category, order, page, per_page)
@scope = scope
@category = category
@order = order
@page = page
@per_page = per_page
2014-01-17 16:21:22 +00:00
end
def category_name
"#{category.to_s.capitalize} asciicasts"
end
def items
2014-02-01 00:12:19 +00:00
@items ||= get_items
end
private
def get_items
2014-01-17 16:21:22 +00:00
PaginatingDecorator.new(
scope.for_category_ordered(category, order, page, per_page)
2014-01-17 16:21:22 +00:00
)
end
end