Skip to content

Commit

Permalink
Fix running with RUBYOPT="--enable-frozen-string-literal" (#651)
Browse files Browse the repository at this point in the history
* Fix running with RUBYOPT="--enable-frozen-string-literal"

* remove use of inject

---------

Co-authored-by: Mislav Marohnić <git@mislav.net>
  • Loading branch information
jdelStrother and mislav authored Jun 10, 2024
1 parent f7e900f commit e1746e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/will_paginate/view_helpers/link_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ def link(text, target, attributes = {})
end

def tag(name, value, attributes = {})
string_attributes = attributes.inject('') do |attrs, pair|
string_attributes = attributes.map do |pair|
unless pair.last.nil?
attrs << %( #{pair.first}="#{CGI::escapeHTML(pair.last.to_s)}")
%( #{pair.first}="#{CGI::escapeHTML(pair.last.to_s)}")
end
attrs
end
"<#{name}#{string_attributes}>#{value}</#{name}>"
"<#{name}#{string_attributes.compact.join("")}>#{value}</#{name}>"
end

def rel_value(page)
Expand Down
3 changes: 1 addition & 2 deletions spec/view_helpers/action_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,13 @@ def renderer.gap() '<span class="my-gap">~~</span>' end

it "should match expected markup" do
paginate
expected = <<-HTML
expected = <<-HTML.strip.gsub(/\s{2,}/, ' ')
<div class="pagination" role="navigation" aria-label="Pagination"><span class="previous_page disabled" aria-label="Previous page">&#8592; Previous</span>
<em class="current" aria-label="Page 1" aria-current="page">1</em>
<a href="/foo/bar?page=2" aria-label="Page 2" rel="next">2</a>
<a href="/foo/bar?page=3" aria-label="Page 3">3</a>
<a href="/foo/bar?page=2" class="next_page" rel="next" aria-label="Next page">Next &#8594;</a></div>
HTML
expected.strip!.gsub!(/\s{2,}/, ' ')
expected_dom = parse_html_document(expected)

if expected_dom.respond_to?(:canonicalize)
Expand Down

0 comments on commit e1746e1

Please sign in to comment.