Sha256: 90f65c5b3095588d53957142560bbf1371b5c79b18919c69158ccc1e7f2d625a

Contents?: true

Size: 1.95 KB

Versions: 11

Compression:

Stored size: 1.95 KB

Contents

module Locomotive
  module Liquid
    module Filters
      module Misc

        # was called modulo at first
        def str_modulo(word, index, modulo)
          (index.to_i + 1) % modulo == 0 ? word : ''
        end

        # Get the nth element of the passed in array
        def index(array, position)
          array.at(position) if array.respond_to?(:at)
        end

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

        # Render the navigation for a paginated collection
        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

      end

      ::Liquid::Template.register_filter(Misc)

    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
locomotive_cms-2.1.4 lib/locomotive/liquid/filters/misc.rb
locomotive_cms-2.1.3 lib/locomotive/liquid/filters/misc.rb
locomotive_cms-2.1.2 lib/locomotive/liquid/filters/misc.rb
locomotive_cms-2.1.1 lib/locomotive/liquid/filters/misc.rb
locomotive_cms-2.1.0 lib/locomotive/liquid/filters/misc.rb
locomotive_cms-2.0.3 lib/locomotive/liquid/filters/misc.rb
locomotive_cms-2.0.2 lib/locomotive/liquid/filters/misc.rb
locomotive_cms-2.0.1 lib/locomotive/liquid/filters/misc.rb
locomotive_cms-2.0.0 lib/locomotive/liquid/filters/misc.rb
tribeca_cms-0.1.1 lib/locomotive/liquid/filters/misc.rb
tribeca_cms-2.0.0.rc12 lib/locomotive/liquid/filters/misc.rb