Module: OrthorHelper

Defined in:
lib/orthor_helper.rb

Instance Method Summary collapse

Instance Method Details

#orthor_pagination(category_id, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/orthor_helper.rb', line 17

def orthor_pagination(category_id, options = {})
  return unless defined?(request) && defined?(params)

  current_page = params[:page] ? params[:page].to_i : 1
  category = Orthor.category(category_id, :page => current_page)
  return if category == "" || category["total_pages"] == 1 # no pagination required

  options[:prev_label] ||= "←"
  options[:next_label] ||= "→"

  if params[:page] && params[:page].to_i > 0
    href = request.url
  else
    href = request.url + (request.url.include?("?") ? "&" : "?") + "page=#{current_page}"
  end

  previous_link = if current_page > 1 
    %!<a class="previous" href="#{href.gsub("page=#{current_page}", "page=#{current_page - 1}")}">#{options[:prev_label]}</a>!
  else
    %!<span class="previous disabled">#{options[:prev_label]}</span>!
  end
  next_link = if current_page < category["total_pages"] 
    %!<a class="next" href="#{href.gsub("page=#{current_page}", "page=#{current_page + 1}")}">#{options[:next_label]}</a>!
  else
    %!<span class="next disabled">#{options[:next_label]}</span>!
  end

  html = <<-HTML
    <div class="orthor-pagination">
      #{previous_link}
      #{next_link}
    </div>
  HTML

  make_safe(html)
end

#with_orthor_category(id, page = nil, &blk) ⇒ Object



7
8
9
10
# File 'lib/orthor_helper.rb', line 7

def with_orthor_category(id, page = nil, &blk)
  return unless block_given?
  render_orthor_result(:category, id, page, &blk)
end

#with_orthor_content(id, &blk) ⇒ Object



2
3
4
5
# File 'lib/orthor_helper.rb', line 2

def with_orthor_content(id, &blk)
  return unless block_given?
  render_orthor_result(:content, id, &blk)
end

#with_orthor_query(id, &blk) ⇒ Object



12
13
14
15
# File 'lib/orthor_helper.rb', line 12

def with_orthor_query(id, &blk)
  return unless block_given?
  render_orthor_result(:query, id, &blk)
end