Skip to content

Commit

Permalink
Update supported Rubies
Browse files Browse the repository at this point in the history
* Clarify our policy regarding supported Rubies and word it in a more
  timeless manner
* Ruby 2.4 is not supported any more
* Add Ruby 2.7 to the list of test targets
* Fix code style
  • Loading branch information
pointlessone committed Jul 25, 2020
1 parent d980247 commit 4b02b01
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 55 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ jobs:
fail-fast: false
matrix:
image:
- ruby:2.4.0
- ruby:2.4
- ruby:2.5.0
- ruby:2.5
- ruby:2.6.0
- ruby:2.6
- ruby:rc
- ruby:2.7.0
- ruby:2.7
- jruby:9.2
include:
- image: ruby:rc
Expand Down
56 changes: 55 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.5

RSpec/ExampleLength:
Enabled: false
Expand Down Expand Up @@ -153,3 +153,57 @@ Layout/SpaceAroundOperators:

Style/WhileUntilModifier:
Enabled: false

Layout/EmptyLinesAroundAttributeAccessor:
Enabled: false

Layout/SpaceAroundMethodCallOperator:
Enabled: false

Lint/DeprecatedOpenSSLConstant:
Enabled: false

Lint/RaiseException:
Enabled: false

Lint/StructNewOverride:
Enabled: false

Style/ExponentialNotation:
Enabled: false

Style/HashEachMethods:
Enabled: false

Style/HashTransformKeys:
Enabled: false

Style/HashTransformValues:
Enabled: false

Style/SlicingWithRange:
Enabled: false

Performance/AncestorsInclude:
Enabled: false

Performance/BigDecimalWithNumericArgument:
Enabled: false

Performance/RedundantSortBlock:
Enabled: false

Performance/RedundantStringChars:
Enabled: false

Performance/ReverseFirst:
Enabled: false

Performance/SortReverse:
Enabled: false

Performance/Squeeze:
Enabled: false

Performance/StringInclude:
Enabled: false
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ for rendering rich HTML documents.
## Supported Ruby Versions and Implementations

Because Prawn is pure Ruby and all of its runtime dependencies are maintained by
us, it should work pretty much anywhere. We officially support Ruby 2.3 and
newer. That translates to MRI 2.3 and newer and JRuby 9.1.13 and newer, however
us, it should work pretty much anywhere. We officially support all Ruby versions
suported by Ruby Core Team and JRuby versions of matching Ruby version. However
we will accept patches to fix problems on other Ruby platforms if they aren't
too invasive.

Expand Down
4 changes: 2 additions & 2 deletions lib/prawn/font/afm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def initialize(document, name, options = {}) #:nodoc:
super

file_name = @name.dup
file_name << '.afm' unless file_name =~ /\.afm$/
file_name << '.afm' unless /\.afm$/.match?(file_name)
file_name = file_name[0] == '/' ? file_name : find_font(file_name)

font_data = self.class.font_data[file_name] ||= parse_afm(file_name)
Expand Down Expand Up @@ -198,7 +198,7 @@ def parse_afm(file_name)

case section
when %w[FontMetrics CharMetrics]
next unless line =~ /^CH?\s/
next unless /^CH?\s/.match?(line)

name = line[/\bN\s+(\.?\w+)\s*;/, 1]
data[:glyph_widths][name] = line[/\bWX\s+(\d+)\s*;/, 1].to_i
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/graphics/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def process_color(*color)
def color_type(color)
case color
when String
if color =~ /\A\h{6}\z/
if /\A\h{6}\z/.match?(color)
:RGB
else
raise ArgumentError, "Unknown type of color: #{color.inspect}"
Expand Down
6 changes: 3 additions & 3 deletions lib/prawn/images/png.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def initialize(data)
@transparency = {}

loop do
chunk_size = data.read(4).unpack('N')[0]
chunk_size = data.read(4).unpack1('N')
section = data.read(4)
case section
when 'IHDR'
Expand Down Expand Up @@ -72,7 +72,7 @@ def initialize(data)
when 0
# Greyscale. Corresponding to entries in the PLTE chunk.
# Grey is two bytes, range 0 .. (2 ^ bit-depth) - 1
grayval = data.read(chunk_size).unpack('n').first
grayval = data.read(chunk_size).unpack1('n')
@transparency[:grayscale] = grayval
when 2
# True colour with proper alpha channel.
Expand Down Expand Up @@ -321,7 +321,7 @@ def generate_alpha_channel
alpha.putc filter

width.times do
color = data.read(1).unpack('C').first
color = data.read(1).unpack1('C')
alpha.putc alpha_palette[color]
end
end
Expand Down
10 changes: 4 additions & 6 deletions lib/prawn/text/formatted/arranger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ def line
end

@fragments.collect do |fragment|
begin
fragment.text.dup.encode(::Encoding::UTF_8)
rescue ::Encoding::InvalidByteSequenceError,
::Encoding::UndefinedConversionError
fragment.text.dup.force_encoding(::Encoding::UTF_8)
end
fragment.text.dup.encode(::Encoding::UTF_8)
rescue ::Encoding::InvalidByteSequenceError,
::Encoding::UndefinedConversionError
fragment.text.dup.force_encoding(::Encoding::UTF_8)
end.join
end

Expand Down
3 changes: 1 addition & 2 deletions lib/prawn/text/formatted/line_wrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ def line_finished?
end

def update_line_status_based_on_last_output
if @fragment_output =~
word_division_scan_pattern(@fragment_output.encoding)
if @fragment_output&.match?(word_division_scan_pattern(@fragment_output.encoding))
@line_contains_more_than_one_word = true
end
end
Expand Down
2 changes: 0 additions & 2 deletions manual/text/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

require '../example_helper'

# rubocop: disable Layout/LineLength
Prawn::ManualBuilder::Example.generate('text.pdf', page_size: 'FOLIO') do
package 'text' do |p|
p.section 'Basics' do |s|
Expand Down Expand Up @@ -74,4 +73,3 @@
end
end
end
# rubocop: enable Layout/LineLength
4 changes: 2 additions & 2 deletions prawn.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
'.yardopts'
]
spec.require_path = 'lib'
spec.required_ruby_version = '~> 2.3'
spec.required_ruby_version = '~> 2.5'
spec.required_rubygems_version = '>= 1.3.6'

spec.authors = [
Expand All @@ -44,7 +44,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency('prawn-manual_builder', '>= 0.3.0')
spec.add_development_dependency('rake', '~> 12.0')
spec.add_development_dependency('rspec', '~> 3.0')
spec.add_development_dependency('rubocop', '~> 0.78.0')
spec.add_development_dependency('rubocop', '~> 0.84.0')
spec.add_development_dependency('rubocop-performance', '~> 1.1')
spec.add_development_dependency('rubocop-rspec', '~> 1.32')
spec.add_development_dependency('simplecov')
Expand Down
10 changes: 4 additions & 6 deletions spec/prawn/document/bounding_box_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,10 @@

it 'restores the x coordinate and width on error' do
pdf.bounding_box([100, 100], width: 200) do
begin
pdf.indent(20) { raise }
rescue StandardError
expect(pdf.bounds.absolute_left).to eq(100)
expect(pdf.bounds.width).to eq(200)
end
pdf.indent(20) { raise }
rescue StandardError
expect(pdf.bounds.absolute_left).to eq(100)
expect(pdf.bounds.width).to eq(200)
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/prawn/document/security_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ class << pdf
end

it 'calculates the correct owner hash' do
expect(pdf.owner_password_hash.unpack('H*').first)
expect(pdf.owner_password_hash.unpack1('H*'))
.to match(/^61CA855012/i)
end

it 'calculates the correct user hash' do
expect(pdf.user_password_hash.unpack('H*').first)
expect(pdf.user_password_hash.unpack1('H*'))
.to match(/^6BC8C51031/i)
end

it 'calculates the correct user_encryption_key' do
expect(pdf.user_encryption_key.unpack('H*').first.upcase)
expect(pdf.user_encryption_key.unpack1('H*').upcase)
.to eq('B100AB6429')
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/prawn/stamp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
objects = output.split('endobj')

objects.each do |obj|
next unless obj =~ %r{/Type /Page$}
next unless %r{/Type /Page$}.match?(obj)

# The page object must contain the annotation reference
# to render a clickable link
Expand All @@ -116,9 +116,9 @@
output = pdf.render
objects = output.split('endobj')
objects.each do |object|
if object =~ %r{/Type /Page$}
if %r{/Type /Page$}.match?(object)
expect(object).to_not match(%r{/ExtGState})
elsif object =~ %r{/Type /XObject$}
elsif %r{/Type /XObject$}.match?(object)
expect(object).to match(%r{/ExtGState})
end
end
Expand Down
4 changes: 1 addition & 3 deletions spec/prawn/text/box_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,7 @@
it 'render returns an empty string because no text remains unprinted' do
expect(text_box.render).to eq('')
end
end

context 'when shrink_to_fit overflow' do
it 'does not drop below the minimum font size' do
options[:overflow] = :shrink_to_fit
options[:min_font_size] = 10.1
Expand Down Expand Up @@ -1019,7 +1017,7 @@
expect(text_box.text).to eq(expect)
end

it 'wraps lines comprised of a single word of the bounds when '\
it 'wraps lines comprised of a single non-alpha word of the bounds when '\
'wrapping text' do
text = '©' * 30

Expand Down
22 changes: 10 additions & 12 deletions spec/prawn/text/formatted/box_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ def wrap(_array)
end

describe 'Text::Formatted::Box#render' do
let(:fragment_callback_class) do
Class.new do
def initialize(_string, _number, _options); end

def render_behind(fragment); end

def render_in_front(fragment); end
end
end

it 'handles newlines' do
array = [{ text: "hello\nworld" }]
options = { document: pdf }
Expand Down Expand Up @@ -399,18 +409,6 @@ def wrap(_array)
expect(text.strings[2]).to eq(' olleh' * number_of_hellos)
expect(text.strings[3]).to eq('?uoy')
end
end

describe 'Text::Formatted::Box#render' do
let(:fragment_callback_class) do
Class.new do
def initialize(_string, _number, _options); end

def render_behind(fragment); end

def render_in_front(fragment); end
end
end

it 'is able to perform fragment callbacks' do
callback_object =
Expand Down
8 changes: 4 additions & 4 deletions spec/prawn_manual_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
MANUAL_HASH =
case RUBY_ENGINE
when 'ruby'
'ea401febcaf2d71a374bc7f25753568ec07dde3479597091498acf4c42c7fd6f'\
'9a94f4a42e5b366b947cc0c2623a3a6c6990cd7a9bbffa63babd1c61290c1ad6'
'85d2ded146d1e6659e9db389a071896d6e57d7cc4210c6b7fc75fc4afe2b5697'\
'8a86baca785acd717964619dc234327ef59f5ba6d750dfd626279af0166f6c5e'
when 'jruby'
'c7511076e6b38fb06e0af4e761327d640f692a63cba2322317d247d81f5d1974'\
'd2c02882bed80e5b06b521b879c91d1bfe7008b781e0b2f8e55b54f0fe615988'
'85d2ded146d1e6659e9db389a071896d6e57d7cc4210c6b7fc75fc4afe2b5697'\
'8a86baca785acd717964619dc234327ef59f5ba6d750dfd626279af0166f6c5e'
end

RSpec.describe Prawn do
Expand Down

0 comments on commit 4b02b01

Please sign in to comment.