Sha256: bb00103a23a7f20c3619d00b980b295f8d9e4f682197028a68c76bdec83d478d

Contents?: true

Size: 1.71 KB

Versions: 13

Compression:

Stored size: 1.71 KB

Contents

module Locomotive
  module Steam
    module Liquid
      module Filters
        module Pagination

          # Render the navigation for a paginated collection
          def default_pagination(paginate, *args)
            return '' if paginate['parts'].empty?

            options = args_to_options(args)

            previous_link = default_pagination_next_or_previous_link(:previous, paginate, options, 'prev')
            next_link     = default_pagination_next_or_previous_link(:next, paginate, options, 'next')
            links         = default_pagination_links(paginate)

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

          private

          def default_pagination_links(paginate)
            paginate['parts'].map do |part|
              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.join
          end

          def default_pagination_next_or_previous_link(type, paginate, options, css)
            label = options[:"#{type}_label"] || I18n.t("pagination.#{type}")

            if paginate[type.to_s].blank?
              "<span class=\"disabled #{css}_page\">#{label}</span>"
            else
              "<a href=\"#{absolute_url(paginate[type.to_s]['url'])}\" class=\"#{css}_page\">#{label}</a>"
            end
          end

        end

        ::Liquid::Template.register_filter(Pagination)

      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.rc8 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.rc6 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.rc4 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.rc3 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.rc2 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.rc1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.pre.beta.3 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.pre.beta.2 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.pre.beta.1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.pre.alpha.3 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.pre.alpha.2 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.pre.alpha.1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.pre.alpha lib/locomotive/steam/liquid/filters/pagination.rb