Module: Pagy::SemanticExtra

Included in:
Frontend
Defined in:
lib/pagy/extras/semantic.rb

Instance Method Summary collapse

Instance Method Details

#pagy_semantic_combo_nav_js(pagy, pagy_id: nil, link_extra: '') ⇒ Object

Combo pagination for semantic: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pagy/extras/semantic.rb', line 41

def pagy_semantic_combo_nav_js(pagy, pagy_id: nil, link_extra: '')
  p_id    = %( id="#{pagy_id}") if pagy_id
  link    = pagy_link_proc(pagy, link_extra: %(class="item" #{link_extra}))
  p_page  = pagy.page
  p_pages = pagy.pages
  input   = %(<input type="number" min="1" max="#{p_pages}" value="#{
                p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length + 1}rem; margin: 0 0.3rem">)

  %(<div#{p_id} class="pagy-semantic-combo-nav-js ui compact menu" role="navigation" #{
      pagy_json_attr pagy, :combo_nav, p_page, pagy_marked_link(link)}>#{
      pagy_semantic_prev_html pagy, link
    }<div class="pagy-combo-input item">#{
      pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
    }</div> #{
      pagy_semantic_next_html pagy, link
    }</div>)
end

#pagy_semantic_nav(pagy, pagy_id: nil, link_extra: '') ⇒ Object

Pagination for semantic: it returns the html with the series of links to the pages



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pagy/extras/semantic.rb', line 9

def pagy_semantic_nav(pagy, pagy_id: nil, link_extra: '')
  p_id = %( id="#{pagy_id}") if pagy_id
  link = pagy_link_proc(pagy, link_extra: %(class="item" #{link_extra}))

  html = +%(<div#{p_id} class="pagy-semantic-nav ui pagination menu">)
  html << pagy_semantic_prev_html(pagy, link)
  pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
    html << case item
            when Integer then link.call item                                                 # page link
            when String  then %(<a class="item active">#{item}</a>)                          # current page
            when :gap    then %(<div class="disabled item">#{pagy_t 'pagy.nav.gap'}</div>)   # page gap
            end
  end
  html << pagy_semantic_next_html(pagy, link)
  html << %(</div>)
end

#pagy_semantic_nav_js(pagy, pagy_id: nil, link_extra: '', steps: nil) ⇒ Object

Javascript pagination for semantic: it returns a nav and a JSON tag used by the Pagy.nav javascript



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pagy/extras/semantic.rb', line 27

def pagy_semantic_nav_js(pagy, pagy_id: nil, link_extra: '', steps: nil)
  p_id = %( id="#{pagy_id}") if pagy_id
  link = pagy_link_proc(pagy, link_extra: %(class="item" #{link_extra}))
  tags = { 'before' => pagy_semantic_prev_html(pagy, link),
           'link'   => link.call(PAGE_PLACEHOLDER),
           'active' => %(<a class="item active">#{pagy.page}</a>),
           'gap'    => %(<div class="disabled item">#{pagy_t('pagy.nav.gap')}</div>),
           'after'  => pagy_semantic_next_html(pagy, link) }

  %(<div#{p_id} class="pagy-njs pagy-semantic-nav-js ui pagination menu" role="navigation" #{
    pagy_json_attr(pagy, :nav, tags, pagy.sequels(steps))}></div>)
end