Skip to content

Commit

Permalink
Update code style
Browse files Browse the repository at this point in the history
  • Loading branch information
pointlessone committed Mar 3, 2024
1 parent 21811fa commit 3a1bd0f
Show file tree
Hide file tree
Showing 129 changed files with 1,728 additions and 1,985 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ Style/Encoding:
RSpec/FilePath:
Exclude:
- spec/prawn/fonts/to_unicode_cmap_spec.rb

RSpec/SpecFilePathFormat:
Exclude:
- spec/prawn/fonts/to_unicode_cmap_spec.rb
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ task :manual do
puts 'Building manual...'
require_relative 'manual/manual'
manual_path = File.expand_path('manual/manual.rb', __dir__)
manual = eval(File.read(manual_path), TOPLEVEL_BINDING, manual_path) # rubocop:disable Security/Eval
manual = eval(File.read(manual_path), TOPLEVEL_BINDING, manual_path) # rubocop: disable Security/Eval
manual.generate('manual.pdf')
puts 'The Prawn manual is available at manual.pdf. Happy Prawning!'
end
Expand Down
2 changes: 1 addition & 1 deletion bench/afm_text_bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Prawn::Document.new do
N.times do
(1..5).each do |i|
draw_text 'Hello Prawn', at: [200, i * 100]
draw_text('Hello Prawn', at: [200, i * 100])
end
start_new_page
end
Expand Down
2 changes: 1 addition & 1 deletion bench/png_type_6.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
x.report('PNG Type 6') do
N.times do
Prawn::Document.new do
image "#{Prawn::DATADIR}/images/dice.png"
image("#{Prawn::DATADIR}/images/dice.png")
end.render_file('dice.pdf')
end
end
Expand Down
2 changes: 1 addition & 1 deletion bench/png_type_6_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
before = GC.stat

Prawn::Document.new do
image "#{Prawn::DATADIR}/images/dice.png"
image("#{Prawn::DATADIR}/images/dice.png")
end.render

after = GC.stat
Expand Down
10 changes: 5 additions & 5 deletions bench/table_bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def benchmark_table_generation(columns, rows, string_size, options = {})
data = data_for_table(columns, rows, string_size)
Benchmark.bm do |x|
x.report(
"#{columns}x#{rows} table (#{columns * rows} cells, with #{string_size} "\
'char string contents' \
"#{", options = #{options.inspect}" unless options.empty?})"
"#{columns}x#{rows} table (#{columns * rows} cells, with #{string_size} " \
'char string contents' \
"#{", options = #{options.inspect}" unless options.empty?})",
) do
Prawn::Document.new { table(data, options) }.render
end
Expand All @@ -38,7 +38,7 @@ def benchmark_table_generation(columns, rows, string_size, options = {})
10,
row_colors: %w[FFFFFF F0F0FF],
header: true,
cell_style: { inline_format: true }
cell_style: { inline_format: true },
)

# Try building and rendering tables of different sizes
Expand All @@ -54,5 +54,5 @@ def benchmark_table_generation(columns, rows, string_size, options = {})
5,
row_colors: %w[FFFFFF F0F0FF],
header: true,
cell_style: { inline_format: true }
cell_style: { inline_format: true },
)
4 changes: 2 additions & 2 deletions bench/ttf_text_bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
Benchmark.bmbm do |x|
x.report('TTF text') do
Prawn::Document.new do
font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
N.times do
(1..5).each do |i|
draw_text 'Hello Prawn', at: [200, i * 100]
draw_text('Hello Prawn', at: [200, i * 100])
end
start_new_page
end
Expand Down
3 changes: 1 addition & 2 deletions lib/prawn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def verify_options(accepted, actual)

unless (act = Set[*actual.keys]).subset?(acc = Set[*accepted])
raise Prawn::Errors::UnknownOption,
"\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" \
"Accepted options are: #{accepted.inspect}"
"\nDetected unknown option(s): #{(act - acc).to_a.inspect}\nAccepted options are: #{accepted.inspect}"
end
yield if block_given?
end
Expand Down
42 changes: 22 additions & 20 deletions lib/prawn/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ def self.generate(filename, options = {}, &block)
def initialize(options = {}, &block)
options = options.dup

Prawn.verify_options VALID_OPTIONS, options
Prawn.verify_options(VALID_OPTIONS, options)

# need to fix, as the refactoring breaks this
# raise NotImplementedError if options[:skip_page_creation]

self.class.extensions.reverse_each { |e| extend e }
self.class.extensions.reverse_each { |e| extend(e) }
self.state = PDF::Core::DocumentState.new(options)
state.populate_pages_from_store(self)
renderer.min_version(state.store.min_version) if state.store.min_version
Expand Down Expand Up @@ -307,7 +307,7 @@ def start_new_page(options = {})
page_options = {
size: options[:size] || last_page_size,
layout: options[:layout] || last_page_layout,
margins: last_page_margins
margins: last_page_margins,
}
if last_page
if last_page.graphic_state
Expand Down Expand Up @@ -455,7 +455,7 @@ def float
# @return [String]
def render(*arguments)
(1..page_count).each do |i|
go_to_page i
go_to_page(i)
repeaters.each { |r| r.run(i) }
end

Expand Down Expand Up @@ -651,7 +651,7 @@ def indent(left, right = 0, &block)
# @option options :color [String, Array<Number>] Text fill color.
def number_pages(string, options = {})
opts = options.dup
start_count_at = opts.delete(:start_count_at).to_i
start_count_at = opts.delete(:start_count_at)

page_filter =
if opts.key?(:page_filter)
Expand All @@ -671,21 +671,23 @@ def number_pages(string, options = {})
unless start_count
pseudopage =
case start_count_at
when 0
1
when String
Integer(start_count_at, 10)
when (1..)
Integer(start_count_at)
else
start_count_at.to_i
1
end
end
if page_match?(page_filter, p)
go_to_page(p)
# have to use fill_color here otherwise text reverts back to default
# fill color
fill_color txtcolor unless txtcolor.nil?
total_pages = total_pages.nil? ? page_count : total_pages
fill_color(txtcolor) unless txtcolor.nil?
total_pages = page_count if total_pages.nil?
str = string.gsub('<page>', pseudopage.to_s)
.gsub('<total>', total_pages.to_s)
text_box str, opts
text_box(str, opts)
start_count = true # increment page count as soon as first match found
end
pseudopage += 1 if start_count
Expand All @@ -698,18 +700,18 @@ def number_pages(string, options = {})
def group(*_arguments)
raise NotImplementedError,
'Document#group has been disabled because its implementation ' \
'lead to corrupted documents whenever a page boundary was ' \
'crossed. We will try to work on reimplementing it in a ' \
'future release'
'lead to corrupted documents whenever a page boundary was ' \
'crossed. We will try to work on reimplementing it in a ' \
'future release'
end

# @private
def transaction
raise NotImplementedError,
'Document#transaction has been disabled because its implementation ' \
'lead to corrupted documents whenever a page boundary was ' \
'crossed. We will try to work on reimplementing it in a ' \
'future release'
'lead to corrupted documents whenever a page boundary was ' \
'crossed. We will try to work on reimplementing it in a ' \
'future release'
end

# Provides a way to execute a block of code repeatedly based on a
Expand Down Expand Up @@ -751,7 +753,7 @@ def mask(*fields)
stored = {}
fields.each { |f| stored[f] = public_send(f) }
yield
fields.each { |f| public_send("#{f}=", stored[f]) }
fields.each { |f| public_send(:"#{f}=", stored[f]) }
end

# @group Extension API
Expand Down Expand Up @@ -804,7 +806,7 @@ def generate_margin_box
width: page.dimensions[-2] -
(page.margins[:left] + page.margins[:right]),
height: page.dimensions[-1] -
(page.margins[:top] + page.margins[:bottom])
(page.margins[:top] + page.margins[:bottom]),
)

# This check maintains indentation settings across page breaks
Expand All @@ -828,7 +830,7 @@ def apply_margin_options(options)
3 => [0, 1, 2, 1],
2 => [0, 1, 0, 1],
1 => [0, 0, 0, 0],
0 => []
0 => [],
}[margin.length]

sides.zip(positions).each do |side, pos|
Expand Down
12 changes: 6 additions & 6 deletions lib/prawn/document/bounding_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def canvas(&block)
nil,
[0, page.dimensions[3]],
width: page.dimensions[2],
height: page.dimensions[3]
height: page.dimensions[3],
)
end
end
Expand Down Expand Up @@ -531,7 +531,7 @@ def height

@stretched_height = [
(absolute_top - @document.y),
@stretched_height.to_f
Float(@stretched_height || 0.0),
].max
end

Expand Down Expand Up @@ -599,12 +599,12 @@ def deep_copy
copy = dup
# Deep-copy the parent bounds
copy.instance_variable_set(
'@parent',
:@parent,
if @parent.is_a?(BoundingBox)
@parent.deep_copy
end
end,
)
copy.instance_variable_set('@document', nil)
copy.instance_variable_set(:@document, nil)
copy
end

Expand All @@ -617,7 +617,7 @@ def deep_copy
# @param document [Prawn::Document]
# @return [BoundingBox]
def self.restore_deep_copy(bounds, document)
bounds.instance_variable_set('@document', document)
bounds.instance_variable_set(:@document, document)
bounds
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/document/column_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def initialize(document, parent, point, options = {})
#
# @return [Number]
def bare_column_width
(@width - @spacer * (@columns - 1)) / @columns
(@width - (@spacer * (@columns - 1))) / @columns
end

# The column width after padding. Used to calculate how long a line of
Expand Down
8 changes: 4 additions & 4 deletions lib/prawn/document/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Document # rubocop: disable Style/Documentation
# @return [void]
# @raise [ArgumentError] For unsupported `:position` value.
def span(width, options = {})
Prawn.verify_options [:position], options
Prawn.verify_options([:position], options)
original_position = y

# FIXME: Any way to move this upstream?
Expand All @@ -38,7 +38,7 @@ def span(width, options = {})
when :left
margin_box.absolute_left
when :center
margin_box.absolute_left + margin_box.width / 2.0 - width / 2.0
margin_box.absolute_left + (margin_box.width / 2.0) - (width / 2.0)
when :right
margin_box.absolute_right - width
when Numeric
Expand All @@ -52,9 +52,9 @@ def span(width, options = {})
bounding_box(
[
left_boundary,
margin_box.absolute_top
margin_box.absolute_top,
],
width: width
width: width,
) do
self.y = original_position
yield
Expand Down
19 changes: 9 additions & 10 deletions lib/prawn/font.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def font_size=(size)
# @option options :style [Symbol]
# @return [Number]
def width_of(string, options = {})
if options.key? :inline_format
if options.key?(:inline_format)
p = options[:inline_format]
p = [] unless p.is_a?(Array)

Expand Down Expand Up @@ -215,22 +215,22 @@ def font_families
bold: 'Courier-Bold',
italic: 'Courier-Oblique',
bold_italic: 'Courier-BoldOblique',
normal: 'Courier'
normal: 'Courier',
},

'Times-Roman' => {
bold: 'Times-Bold',
italic: 'Times-Italic',
bold_italic: 'Times-BoldItalic',
normal: 'Times-Roman'
normal: 'Times-Roman',
},

'Helvetica' => {
bold: 'Helvetica-Bold',
italic: 'Helvetica-Oblique',
bold_italic: 'Helvetica-BoldOblique',
normal: 'Helvetica'
}
normal: 'Helvetica',
},
)
end

Expand Down Expand Up @@ -299,7 +299,7 @@ def find_font(name, options = {}) # :nodoc:
end
key = "#{family}:#{name}:#{options[:font] || 0}"

if name.is_a? Prawn::Font
if name.is_a?(Prawn::Font)
font_registry[key] = name
else
font_registry[key] ||=
Expand Down Expand Up @@ -392,7 +392,7 @@ def self.load(document, src, options = {})
# @option options :format [String]
# @return [String]
def self.font_format(src, options)
return options.fetch(:format, 'ttf') if src.respond_to? :read
return options.fetch(:format, 'ttf') if src.respond_to?(:read)

case src.to_s
when /\.ttf$/i then 'ttf'
Expand Down Expand Up @@ -467,8 +467,7 @@ def normalize_encoding(_string)
# @param str [String]
# @return [String]
def normalize_encoding!(str)
warn 'Font#normalize_encoding! is deprecated. ' \
'Please use non-mutating version Font#normalize_encoding instead.'
warn('Font#normalize_encoding! is deprecated. Please use non-mutating version Font#normalize_encoding instead.')
str.dup.replace(normalize_encoding(str))
end

Expand Down Expand Up @@ -507,7 +506,7 @@ def identifier_for(subset)
if full_font_embedding
@identifier.to_sym
else
"#{@identifier}.#{subset}".to_sym
:"#{@identifier}.#{subset}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/fonts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Fonts
end
end

require_relative 'fonts/font'
require_relative 'font'
require_relative 'fonts/afm'
require_relative 'fonts/ttf'
require_relative 'fonts/dfont'
Expand Down
Loading

0 comments on commit 3a1bd0f

Please sign in to comment.