Sha256: 25047a44acc6bb14ac0ae67048f72dabce06e183f2daa6c64b79fac6c8be5355

Contents?: true

Size: 1.84 KB

Versions: 41

Compression:

Stored size: 1.84 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=\"#{default_pagination_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=\"#{default_pagination_url(paginate[type.to_s]['url'])}\" class=\"#{css}_page\">#{label}</a>"
            end
          end

          def default_pagination_url(url)
            url.starts_with?('/') ? url : "/#{url}"
          end

        end

        ::Liquid::Template.register_filter(Pagination)

      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.4.1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/liquid/filters/pagination.rb