# frozen_string_literal: true # DESCRIPTION # Showcase all the helpers and styles # # DOC # https://ddnexus.github.io/pagy/playground/#demo-app # # BIN HELP # pagy -h # # DEMO USAGE # pagy demo # # DEV USAGE # pagy clone demo # pagy ./demo.ru # # URL # http://127.0.0.1:8000 VERSION = '43.4.4' if VERSION != Pagy::VERSION Warning.warn("\n>>> WARNING! '#{File.basename(__FILE__)}-#{VERSION}' running with 'pagy-#{Pagy::VERSION}'! <<< \n\n") end # Bundle require 'bundler/inline' gemfile(!Pagy::ROOT.join('pagy.gemspec').exist?) do source 'https://rubygems.org' gem 'oj' gem 'puma' gem 'rouge' gem 'sinatra' end # pagy initializer SECTIONS = { pagy: { css_anchor: 'pagy-css' }, tailwind: { css_anchor: 'pagy-tailwind-css' }, bootstrap: { style: :bootstrap, classes: 'pagination pagination-sm' }, bulma: { style: :bulma, classes: 'pagination is-small' }, template: { css_anchor: 'pagy-css', template: :template } }.freeze # Sinatra setup require 'sinatra/base' # Pagy init Pagy::OPTIONS[:client_max_limit] = 100 # Sinatra application class PagyDemo < Sinatra::Base include Pagy::Method get '/' do redirect '/pagy' end get('/javascripts/:file') do format = params[:file].split('.').last if format == 'js' content_type 'application/javascript' elsif format == 'map' content_type 'application/json' end send_file Pagy::ROOT.join('javascripts', params[:file]) end get('/stylesheets/:file') do content_type 'text/css' send_file Pagy::ROOT.join('stylesheets', params[:file]) end if ENV['E2E_TEST'] get('/assets/:file') do content_type 'text/css' send_file Pagy::ROOT.join('../test/e2e/assets', params[:file]) end end # One route/action per style SECTIONS.each do |section, value| get("/#{section}") do collection = MockCollection.new @pagy, @records = pagy(:offset, collection) erb value[:template] || :page, locals: { section:, pagy: @pagy, style: value[:style], classes: value[:classes], css_anchor: value[:css_anchor] } end end PAGY_LIKE_HEAD = %(#{Pagy.dev_tools unless ENV['E2E_TEST']} ).freeze helpers do def style_menu html = +%(
) html end def head_for(section) case section when :pagy, :template %(#{PAGY_LIKE_HEAD} ) when :tailwind %(#{PAGY_LIKE_HEAD} #{if ENV['E2E_TEST'] '' else '' end} ) when :bootstrap if ENV['E2E_TEST'] '' else '' end when :bulma if ENV['E2E_TEST'] '' else '' end end end def highlight(html, format: :html) if format == :html html = html.gsub(/>\s*, '><').strip # template single line no spaces around/between tags html = Formatter.new.format(html) end lexer = Rouge::Lexers::ERB.new formatter = Rouge::Formatters::HTMLInline.new('monokai.sublime') summary = { html: 'Served HTML (pretty formatted)', erb: 'ERB Template' } %(\n#{
formatter.format(lexer.lex(html))
}Check the <%= css_anchor.gsub('-', '.') %> for details.
<% end %><%= @records.join(',') %>
{slots: 7}
{steps: {0 => 5, 500 => 7, 600 => 9, 700 => 11}}See the Custom Templates documentation.
@records: <%= @records.join(',') %>