Class: Middleman::Webcomic::Pager
- Inherits:
-
Object
- Object
- Middleman::Webcomic::Pager
- Defined in:
- lib/middleman-webcomic/pager.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#page_sets ⇒ Object
readonly
Returns the value of attribute page_sets.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each ⇒ Object
- #first ⇒ Object
-
#initialize(articles, base_path = "/page", page_size = 5) ⇒ Pager
constructor
A new instance of Pager.
- #last ⇒ Object
- #length ⇒ Object
Constructor Details
#initialize(articles, base_path = "/page", page_size = 5) ⇒ Pager
Returns a new instance of Pager.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/middleman-webcomic/pager.rb', line 6 def initialize(articles, base_path="/page", page_size=5) @all= articles @page_size= page_size @base_path= base_path @page_sets= @all.in_groups_of(page_size, false) @pages= [] @current_page=1 @page_sets.each do |art_ary| @pages << Thor::CoreExt::HashWithIndifferentAccess.new({ 'articles' => art_ary, 'page' => @current_page, 'uri' => "#{base_path}/#{current_page}", 'pager' => self }) @current_page += 1 end @current_page= nil end |
Instance Attribute Details
#all ⇒ Object (readonly)
Returns the value of attribute all.
4 5 6 |
# File 'lib/middleman-webcomic/pager.rb', line 4 def all @all end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
4 5 6 |
# File 'lib/middleman-webcomic/pager.rb', line 4 def base_url @base_url end |
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
4 5 6 |
# File 'lib/middleman-webcomic/pager.rb', line 4 def current_page @current_page end |
#page_sets ⇒ Object (readonly)
Returns the value of attribute page_sets.
4 5 6 |
# File 'lib/middleman-webcomic/pager.rb', line 4 def page_sets @page_sets end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
4 5 6 |
# File 'lib/middleman-webcomic/pager.rb', line 4 def pages @pages end |
Instance Method Details
#[](key) ⇒ Object
46 47 48 |
# File 'lib/middleman-webcomic/pager.rb', line 46 def [](key) @pages[key] end |
#each ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/middleman-webcomic/pager.rb', line 37 def each @current_page=1 @pages.each do |page_set| yield page_set @current_page += 1 end @current_page= nil end |
#first ⇒ Object
29 30 31 |
# File 'lib/middleman-webcomic/pager.rb', line 29 def first @pages.first end |
#last ⇒ Object
33 34 35 |
# File 'lib/middleman-webcomic/pager.rb', line 33 def last @pages.last end |
#length ⇒ Object
25 26 27 |
# File 'lib/middleman-webcomic/pager.rb', line 25 def length @pages.length end |