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.4.0.rc1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.4.0.pre.rc.1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.3.0 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.3.0.rc2 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.1.2 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.2.1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.3.0.rc1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.2.0 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.2.0.rc3 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.2.0.rc2 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.2.0.rc1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.2.0.beta1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.1.1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.1.0 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.1.0.rc3 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.1.0.rc2 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.1.0.rc1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.1 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0 lib/locomotive/steam/liquid/filters/pagination.rb
locomotivecms_steam-1.0.0.rc10 lib/locomotive/steam/liquid/filters/pagination.rb