Skip to content

Commit

Permalink
Use prawn-dev
Browse files Browse the repository at this point in the history
prawn-dev helps keep development environment consistent between Prawn
gems.

With the updated development dependencies code style is updated as well.
  • Loading branch information
pointlessone committed Dec 27, 2020
1 parent 5f21d99 commit 7f17308
Show file tree
Hide file tree
Showing 35 changed files with 89 additions and 285 deletions.
174 changes: 2 additions & 172 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,16 @@
require:
- rubocop-performance
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.5
NewCops: enable

Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation
inherit_gem:
prawn-dev: rubocop.yml

Lint/ConstantDefinitionInBlock:
Exclude:
- manual/text/formatted_callbacks.rb
- manual/text/text_box_extensions.rb

Layout/FirstArrayElementLineBreak:
Enabled: true

Layout/FirstHashElementLineBreak:
Enabled: true

Layout/FirstMethodArgumentLineBreak:
Enabled: true

Layout/FirstMethodParameterLineBreak:
Enabled: true

Layout/FirstArgumentIndentation:
EnforcedStyle: consistent

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent

Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Layout/HeredocArgumentClosingParenthesis:
Enabled: true

Layout/MultilineAssignmentLayout:
Enabled: true

Layout/MultilineHashKeyLineBreaks:
Enabled: true

Layout/MultilineMethodArgumentLineBreaks:
Enabled: true

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Layout/MultilineOperationIndentation:
EnforcedStyle: indented
Exclude:
- prawn.gemspec

Layout/ParameterAlignment:
EnforcedStyle: with_fixed_indentation

Layout/SpaceAroundOperators:
AllowForAlignment: false


Lint/HeredocMethodCallPosition:
Enabled: true

# FIXME
Lint/NumberConversion:
Enabled: false

# This file shows examples on how to instantiate a document in multiple ways,
# it does not actually do the instantiation and isn't actually shadowing any
# variables.
Expand All @@ -82,9 +24,6 @@ Lint/SuppressedException:
Exclude:
- lib/prawn/text/formatted/box.rb


Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Exclude:
- lib/prawn/graphics.rb
Expand All @@ -93,17 +32,6 @@ Metrics/BlockLength:
- manual/**/*.rb
- prawn.gemspec
- spec/**/*.rb
Metrics/ClassLength:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/ModuleLength:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false


Naming/AccessorMethodName:
Exclude:
Expand All @@ -114,43 +42,6 @@ Naming/PredicateName:
- lib/prawn/font/ttf.rb
- lib/prawn/font/afm.rb

Naming/MethodParameterName:
MinNameLength: 3
AllowNamesEndingInNumbers: true
AllowedNames:
- id
- to
- at
- x
- x1
- x2
- y
- y1
- y2
- r1
- r2

ForbiddenNames: []


# This one doesn't work well with YARD
Style/AccessorGrouping:
Enabled: false

# We need to reference non-ascii characters when testing and explaining
# behavior related to win-1252, UTF-8 and UTF-16 encodings for example.
Style/AsciiComments:
Enabled: false

Style/AutoResourceCleanup:
Enabled: true

Style/CollectionMethods:
Enabled: true

Style/Documentation:
Enabled: false

Style/Encoding:
# To be safe we are leaving these files encoded ASCII-8BIT as
# discussed at https://github.com/prawnpdf/prawn/pull/705
Expand All @@ -159,64 +50,3 @@ Style/Encoding:
- lib/prawn/images/png.rb
- lib/prawn/images.rb
- spec/png_spec.rb

Style/GuardClause:
Enabled: false

# We don't always prefer modifier statements even if they do fit on a line.
Style/IfUnlessModifier:
Enabled: false
Style/WhileUntilModifier:
Enabled: false

Style/ImplicitRuntimeError:
Enabled: true

# This one would break our public API
Style/OptionalBooleanParameter:
Enabled: false

Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%': '()'
'%i': '[]'
'%I': '[]'
'%q': '()'
'%Q': '()'
'%r': '{}'
'%s': '()'
'%w': '[]'
'%W': '[]'
'%x': '()'

Style/ReturnNil:
Enabled: true

Style/Send:
Enabled: true


Performance/CaseWhenSplat:
Enabled: true

Performance/IoReadlines:
Enabled: true


RSpec/DescribedClassModuleWrapping:
Enabled: true

RSpec/ExampleLength:
Enabled: false

RSpec/MessageExpectation:
Enabled: true

RSpec/MultipleExpectations:
Enabled: false

RSpec/NestedGroups:
Max: 5

RSpec/NotToNot:
EnforcedStyle: to_not
33 changes: 2 additions & 31 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
# frozen_string_literal: true

require 'rake'
require 'rspec/core/rake_task'
require 'yard'
require 'rubygems/package_task'
require 'rubocop/rake_task'
GEMSPEC = File.expand_path('prawn.gemspec', __dir__)
require 'prawn/dev/tasks'

task default: %i[spec rubocop]

desc 'Run all rspec files'
RSpec::Core::RakeTask.new('spec') do |c|
c.rspec_opts = '-t ~unresolved'
end

YARD::Rake::YardocTask.new do |t|
t.options = ['--output-dir', 'doc/html']
end
task docs: :yard

desc "Generate the 'Prawn by Example' manual"
task :manual do
puts 'Building manual...'
Expand All @@ -26,12 +13,6 @@ task :manual do
puts 'The Prawn manual is available at manual.pdf. Happy Prawning!'
end

spec = Gem::Specification.load 'prawn.gemspec'
Gem::PackageTask.new(spec) do |pkg|
pkg.need_zip = true
pkg.need_tar = true
end

desc 'Run a console with Prawn loaded'
task :console do
require 'irb'
Expand All @@ -42,13 +23,3 @@ task :console do
ARGV.clear
IRB.start
end

RuboCop::RakeTask.new

task :checksum do
require 'digest/sha2'
built_gem_path = "prawn-#{Prawn::VERSION}.gem"
checksum = Digest::SHA512.new.hexdigest(File.read(built_gem_path))
checksum_path = "checksums/#{built_gem_path}.sha512"
File.write(checksum_path, checksum)
end
6 changes: 3 additions & 3 deletions lib/prawn/font.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ def self.font_format(src, options)
return options.fetch(:format, 'ttf') if src.respond_to? :read

case src.to_s
when /\.ttf$/i then 'ttf'
when /\.otf$/i then 'otf'
when /\.ttf$/i then 'ttf'
when /\.otf$/i then 'otf'
when /\.dfont$/i then 'dfont'
when /\.ttc$/i then 'ttc'
when /\.ttc$/i then 'ttc'
else 'afm'
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/fonts/afm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def find_font(file)
rescue NoMethodError
raise Prawn::Errors::UnknownFont,
"Couldn't find the font: #{file} in any of:\n" +
self.class.metrics_path.join("\n")
self.class.metrics_path.join("\n")
end

def parse_afm(file_name)
Expand Down
10 changes: 5 additions & 5 deletions lib/prawn/graphics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def ellipse(point, radius1, radius2 = radius1)
move_to(x + radius1, y)

# Upper right hand corner
curve_to [x, y + radius2],
curve_to [x, y + radius2],
bounds: [[x + radius1, y + l2], [x + l1, y + radius2]]

# Upper left hand corner
Expand Down Expand Up @@ -633,10 +633,10 @@ def close_path

ops.product(shapes).each do |operation, shape|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{operation}_#{shape}(*args)
#{shape}(*args)
#{operation}
end
def #{operation}_#{shape}(*args) # def fill_polygon(*args)
#{shape}(*args) # polygon(*args)
#{operation} # fill
end # end
METHOD
end

Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/graphics/join_style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def join_style(style = nil)
unless JOIN_STYLES.key?(current_join_style)
raise Prawn::Errors::InvalidJoinStyle,
"#{style} is not a recognized join style. Valid styles are " +
JOIN_STYLES.keys.join(', ')
JOIN_STYLES.keys.join(', ')
end

write_stroke_join_style
Expand Down
1 change: 1 addition & 0 deletions lib/prawn/graphics/patterns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def parse_gradient_arguments(
*arguments, from: nil, to: nil, r1: nil, r2: nil, stops: nil,
apply_transformations: nil
)

case arguments.length
when 0
apply_transformations = true if apply_transformations.nil?
Expand Down
4 changes: 2 additions & 2 deletions lib/prawn/graphics/transformation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def rotate(angle, options = {}, &block)
if options[:origin].nil?
transformation_matrix(cos, sin, -sin, cos, 0, 0, &block)
else
raise Prawn::Errors::BlockRequired unless block_given?
raise Prawn::Errors::BlockRequired unless block

x = options[:origin][0] + bounds.absolute_left
y = options[:origin][1] + bounds.absolute_bottom
Expand Down Expand Up @@ -118,7 +118,7 @@ def scale(factor, options = {}, &block)
if options[:origin].nil?
transformation_matrix(factor, 0, 0, factor, 0, 0, &block)
else
raise Prawn::Errors::BlockRequired unless block_given?
raise Prawn::Errors::BlockRequired unless block

x = options[:origin][0] + bounds.absolute_left
y = options[:origin][1] + bounds.absolute_bottom
Expand Down
4 changes: 2 additions & 2 deletions lib/prawn/security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def self.encrypt_string(str, key, id, gen)
def encryption_dictionary
{
Filter: :Standard, # default PDF security handler
V: 1, # "Algorithm 3.1", PDF reference 1.3
R: 2, # Revision 2 of the algorithm
V: 1, # "Algorithm 3.1", PDF reference 1.3
R: 2, # Revision 2 of the algorithm
O: PDF::Core::ByteString.new(owner_password_hash),
U: PDF::Core::ByteString.new(user_password_hash),
P: permissions_value
Expand Down
5 changes: 2 additions & 3 deletions lib/prawn/text/formatted/arranger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,8 @@ def repack_unretrieved
end

def font_style(styles)
if styles.nil?
:normal
elsif styles.include?(:bold) && styles.include?(:italic)
styles = Array(styles)
if styles.include?(:bold) && styles.include?(:italic)
:bold_italic
elsif styles.include?(:bold)
:bold
Expand Down
6 changes: 3 additions & 3 deletions manual/bounding_box/canvas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualBuilder::Example.generate(filename) do
canvas do
fill_circle [bounds.left, bounds.top], 30
fill_circle [bounds.right, bounds.top], 30
fill_circle [bounds.left, bounds.top], 30
fill_circle [bounds.right, bounds.top], 30
fill_circle [bounds.right, bounds.bottom], 30
fill_circle [0, 0], 30
fill_circle [0, 0], 30
end
end
6 changes: 3 additions & 3 deletions manual/document_and_page_options/document_and_page_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualBuilder::Example.generate(filename, page_size: 'FOLIO') do
package 'document_and_page_options' do |p|
p.example 'page_size', eval_source: false, full_source: true
p.example 'page_size', eval_source: false, full_source: true
p.example 'page_margins', eval_source: false, full_source: true
p.example 'background', eval_source: false, full_source: true
p.example 'metadata', eval_source: false, full_source: true
p.example 'background', eval_source: false, full_source: true
p.example 'metadata', eval_source: false, full_source: true
p.example 'print_scaling', eval_source: false, full_source: true

p.intro do
Expand Down
Loading

0 comments on commit 7f17308

Please sign in to comment.