2014-02-01 00:26:58 +00:00
|
|
|
class BrowsePagePresenter
|
2014-01-17 16:21:22 +00:00
|
|
|
|
2015-05-10 19:15:43 +00:00
|
|
|
DEFAULT_CATEGORY = :public
|
2015-07-20 12:05:38 +00:00
|
|
|
DEFAULT_ORDER = :date
|
2014-02-01 00:10:54 +00:00
|
|
|
PER_PAGE = 12
|
2014-01-17 16:21:22 +00:00
|
|
|
|
2015-05-15 19:13:37 +00:00
|
|
|
attr_reader :scope, :category, :order, :page, :per_page
|
2014-01-17 16:21:22 +00:00
|
|
|
|
2015-05-15 19:13:37 +00:00
|
|
|
def self.build(scope, category, order, page = nil, per_page = nil)
|
2014-02-01 00:10:54 +00:00
|
|
|
new(
|
2015-05-15 19:13:37 +00:00
|
|
|
scope,
|
2014-02-01 00:10:54 +00:00
|
|
|
(category || DEFAULT_CATEGORY).to_sym,
|
|
|
|
(order || DEFAULT_ORDER).to_sym,
|
|
|
|
page || 1,
|
|
|
|
per_page || PER_PAGE
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2015-05-15 19:13:37 +00:00
|
|
|
def initialize(scope, category, order, page, per_page)
|
|
|
|
@scope = scope
|
2014-02-01 00:10:54 +00:00
|
|
|
@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(
|
2015-05-15 19:13:37 +00:00
|
|
|
scope.for_category_ordered(category, order, page, per_page)
|
2014-01-17 16:21:22 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|