Skip to content

Commit

Permalink
Remove dependency on base64 (#618)
Browse files Browse the repository at this point in the history
Ruby 3.3 prints a warning if base64 is used without specifying it in the gemfile.
Ruby 3.4 will error
  • Loading branch information
Earlopain authored Jan 15, 2024
1 parent 60e25cf commit 2e60cac
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/pagy/extras/frontend_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'base64'

class Pagy # :nodoc:
DEFAULT[:steps] = false # default false will use {0 => @vars[:size]}

Expand Down Expand Up @@ -48,15 +46,17 @@ module Frontend
# Base64 encoded JSON is smaller than HTML escaped JSON
def pagy_data(pagy, *args)
args << pagy.vars[:page_param] if pagy.vars[:trim_extra]
%(data-pagy="#{Base64.strict_encode64(Oj.dump(args, mode: :strict))}")
strict_base64_encoded = [Oj.dump(args, mode: :strict)].pack('m0')
%(data-pagy="#{strict_base64_encoded}")
end
else
require 'json'
# Return a data tag with the base64 encoded JSON-serialized args generated with the slower to_json
# Base64 encoded JSON is smaller than HTML escaped JSON
def pagy_data(pagy, *args)
args << pagy.vars[:page_param] if pagy.vars[:trim_extra]
%(data-pagy="#{Base64.strict_encode64(args.to_json)}")
strict_base64_encoded = [args.to_json].pack('m0')
%(data-pagy="#{strict_base64_encoded}")
end
end

Expand Down

0 comments on commit 2e60cac

Please sign in to comment.