Class: Workarea::Storefront::BlogViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Storefront::BlogViewModel
- Includes:
- DisplayContent, Pagination
- Defined in:
- app/view_models/workarea/storefront/blog_view_model.rb
Instance Method Summary collapse
- #breadcrumbs ⇒ Object
- #entries ⇒ Object
- #entries_on_index ⇒ Object
- #page ⇒ Object
- #tags ⇒ Object
- #total ⇒ Object
- #updated_at ⇒ Object
Instance Method Details
#breadcrumbs ⇒ Object
10 11 12 |
# File 'app/view_models/workarea/storefront/blog_view_model.rb', line 10 def @breadcrumbs ||= Navigation::Breadcrumbs.new(model) end |
#entries ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/view_models/workarea/storefront/blog_view_model.rb', line 14 def entries @entries ||= begin arr = scoped_entries .page(page) .per(self.class.per_page) .map { |e| BlogEntryViewModel.new(e) } PagedArray.from(arr, page, self.class.per_page, total) end end |
#entries_on_index ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/view_models/workarea/storefront/blog_view_model.rb', line 26 def entries_on_index @entries ||= begin scoped_entries[0...Workarea.config.blog_entries_on_index] .map { |entry| Storefront::BlogEntryViewModel.wrap(entry) } end end |
#page ⇒ Object
46 47 48 |
# File 'app/view_models/workarea/storefront/blog_view_model.rb', line 46 def page [:page].present? ? [:page].to_f : 1 end |
#tags ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/view_models/workarea/storefront/blog_view_model.rb', line 34 def @tags ||= if model.entries.any? model.entries.where(active: true). else [] end end |
#total ⇒ Object
42 43 44 |
# File 'app/view_models/workarea/storefront/blog_view_model.rb', line 42 def total @total ||= scoped_entries.total_count end |
#updated_at ⇒ Object
50 51 52 |
# File 'app/view_models/workarea/storefront/blog_view_model.rb', line 50 def updated_at @updated_at ||= model.entries.newest.select(&:active?).first.try(:updated_at) end |