Module: Locomotive::Liquid::Filters::Misc

Defined in:
lib/locomotive/liquid/filters/misc.rb

Instance Method Summary collapse

Instance Method Details

#default(input, value) ⇒ Object



16
17
18
# File 'lib/locomotive/liquid/filters/misc.rb', line 16

def default(input, value)
  input.blank? ? value : input
end

#default_pagination(paginate, *args) ⇒ Object

Render the navigation for a paginated collection



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
53
54
55
56
57
# File 'lib/locomotive/liquid/filters/misc.rb', line 21

def default_pagination(paginate, *args)
  return '' if paginate['parts'].empty?

  options = args_to_options(args)

  previous_label  = options[:previous_label] || I18n.t('pagination.previous')
  next_label      = options[:next_label] || I18n.t('pagination.next')

  previous_link = (if paginate['previous'].blank?
    "<span class=\"disabled prev_page\">#{previous_label}</span>"
  else
    "<a href=\"#{absolute_url(paginate['previous']['url'])}\" class=\"prev_page\">#{previous_label}</a>"
  end)

  links = ""
  paginate['parts'].each do |part|
    links << (if part['is_link']
      "<a href=\"#{absolute_url(part['url'])}\">#{part['title']}</a>"
    elsif part['hellip_break']
      "<span class=\"gap\">#{part['title']}</span>"
    else
      "<span class=\"current\">#{part['title']}</span>"
    end)
  end

  next_link = (if paginate['next'].blank?
    "<span class=\"disabled next_page\">#{next_label}</span>"
  else
    "<a href=\"#{absolute_url(paginate['next']['url'])}\" class=\"next_page\">#{next_label}</a>"
  end)

  %{<div class="pagination #{options[:css]}">
      #{previous_link}
      #{links}
      #{next_link}
    </div>}
end

#index(array, position) ⇒ Object

Get the nth element of the passed in array



12
13
14
# File 'lib/locomotive/liquid/filters/misc.rb', line 12

def index(array, position)
  array.at(position) if array.respond_to?(:at)
end

#str_modulo(word, index, modulo) ⇒ Object

was called modulo at first



7
8
9
# File 'lib/locomotive/liquid/filters/misc.rb', line 7

def str_modulo(word, index, modulo)
  (index.to_i + 1) % modulo == 0 ? word : ''
end