Skip to content

Commit

Permalink
Merge pull request prawnpdf#884 from prawnpdf/space-inside-block-braces
Browse files Browse the repository at this point in the history
Enforce spaces inside block braces.
  • Loading branch information
packetmonkey committed May 31, 2015
2 parents ff4d844 + 453bc13 commit 4053a53
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 32 deletions.
2 changes: 0 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ SpaceInsideBrackets:
Enabled: false
FormatString:
Enabled: false
SpaceInsideBlockBraces:
Enabled: false
CollectionMethods:
Enabled: false
DotPosition:
Expand Down
2 changes: 1 addition & 1 deletion bench/table_bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.random(length)
end

def data_for_table(columns, rows, string_size)
rows.times.collect { columns.times.collect { String.random(string_size) }}
rows.times.collect { columns.times.collect { String.random(string_size) } }
end

def benchmark_table_generation(columns, rows, string_size, options = {})
Expand Down
8 changes: 4 additions & 4 deletions lib/prawn/grid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,19 @@ def bottom
private

def left_box
@left_box ||= @bs.min {|a, b| a.left <=> b.left}
@left_box ||= @bs.min { |a, b| a.left <=> b.left }
end

def right_box
@right_box ||= @bs.max {|a, b| a.right <=> b.right}
@right_box ||= @bs.max { |a, b| a.right <=> b.right }
end

def top_box
@top_box ||= @bs.max {|a, b| a.top <=> b.top}
@top_box ||= @bs.max { |a, b| a.top <=> b.top }
end

def bottom_box
@bottom_box ||= @bs.min {|a, b| a.bottom <=> b.bottom}
@bottom_box ||= @bs.min { |a, b| a.bottom <=> b.bottom }
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def permissions_value

PasswordPadding =
"28BF4E5E4E758A4164004E56FFFA01082E2E00B6D0683E802F0CA9FE6453697A".
scan(/../).map{|x| x.to_i(16)}.pack("c*")
scan(/../).map{ |x| x.to_i(16) }.pack("c*")

# Pads or truncates a password to 32 bytes as per Alg 3.2.
def pad_password(password)
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/security/arcfour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def initialize(key)
end

def encrypt(string)
string.unpack('c*').map{|byte| byte ^ key_byte}.pack('c*')
string.unpack('c*').map{ |byte| byte ^ key_byte }.pack('c*')
end

private
Expand Down
2 changes: 1 addition & 1 deletion manual/repeatable_content/page_numbering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
number_pages string, options

# Gray page numbers from 8 on up
options[:page_filter] = lambda{ |pg| pg > 7}
options[:page_filter] = lambda{ |pg| pg > 7 }
options[:start_count_at] = 8
options[:color] = "333333"
number_pages string, options
Expand Down
4 changes: 2 additions & 2 deletions spec/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def self.format(string)
context "some crazy proc and 2" do
it "increments the pages" do
6.times { @pdf.start_new_page }
options = { :page_filter => lambda {|p| p != 2 && p != 5}, :start_count_at => 4 }
options = { :page_filter => lambda { |p| p != 2 && p != 5 }, :start_count_at => 4 }
@pdf.expects(:text_box).with("4 6", :height => 50) # page 1
@pdf.expects(:text_box).with("5 6", :height => 50).never # page 2
@pdf.expects(:text_box).with("6 6", :height => 50) # page 3
Expand Down Expand Up @@ -708,7 +708,7 @@ def self.format(string)
describe "The page_match? method" do
before do
@pdf = Prawn::Document.new(:skip_page_creation => true)
10.times {@pdf.start_new_page}
10.times { @pdf.start_new_page }
end

it "returns nil given no filter" do
Expand Down
6 changes: 3 additions & 3 deletions spec/graphics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@
@pdf.rounded_rectangle([50, 550], 50, 100, 10)
curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
curve_points = []
curve.coords.each_slice(2) {|p| curve_points << p}
curve.coords.each_slice(2) { |p| curve_points << p }
@original_point = curve_points.shift
curves = []
curve_points.each_slice(3) {|c| curves << c}
curve_points.each_slice(3) { |c| curves << c }
line_points = PDF::Inspector::Graphics::Line.analyze(@pdf.render).points
line_points.shift
@all_coords = []
line_points.zip(curves).flatten.each_slice(2) {|p| @all_coords << p }
line_points.zip(curves).flatten.each_slice(2) { |p| @all_coords << p }
@all_coords.unshift @original_point
end

Expand Down
4 changes: 2 additions & 2 deletions spec/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
@pdf.image @filename, :fit => [600, 600]
output = StringIO.new(@pdf.render, 'r+')
hash = PDF::Reader::ObjectHash.new(output)
pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
pages = hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Pages }[:Kids]
expect(pages.size).to eq(2)
expect(hash[pages[0]][:Resources][:XObject].keys).to eq([:I1])
expect(hash[pages[1]][:Resources][:XObject].keys).to eq([:I2])
Expand All @@ -106,7 +106,7 @@
@pdf.image @filename, :fit => [400, 400]
output = StringIO.new(@pdf.render, 'r+')
hash = PDF::Reader::ObjectHash.new(output)
pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
pages = hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Pages }[:Kids]
expect(pages.size).to eq(1)
expect(Set.new(hash[pages[0]][:Resources][:XObject].keys)).to eq(
Set.new([:I1, :I2])
Expand Down
14 changes: 7 additions & 7 deletions spec/outline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

describe "#create_outline_item" do
it "should create outline items for each section and page" do
[@section_1, @page_1, @page_2].each {|item| expect(item).not_to be_nil}
[@section_1, @page_1, @page_2].each { |item| expect(item).not_to be_nil }
end
end

Expand All @@ -57,7 +57,7 @@
end

it "should link child items to parent item" do
[@page_1, @page_2].each {|page| expect(referenced_object(page[:Parent])).to eq(@section_1) }
[@page_1, @page_2].each { |page| expect(referenced_object(page[:Parent])).to eq(@section_1) }
end

it "should set the first and last child items for parent item" do
Expand Down Expand Up @@ -116,7 +116,7 @@
end

it "should add new outline items to document" do
[@section_2, @page_3].each { |item| expect(item).not_to be_nil}
[@section_2, @page_3].each { |item| expect(item).not_to be_nil }
end

it "should reset the last items for root outline dictionary" do
Expand Down Expand Up @@ -153,7 +153,7 @@
end

it "should add new outline items to document" do
[@subsection, @added_page_3].each { |item| expect(item).not_to be_nil}
[@subsection, @added_page_3].each { |item| expect(item).not_to be_nil }
end

it "should reset the last item for parent item dictionary" do
Expand Down Expand Up @@ -197,7 +197,7 @@
end

it "should add new outline items to document" do
[@subsection, @added_page_3].each { |item| expect(item).not_to be_nil}
[@subsection, @added_page_3].each { |item| expect(item).not_to be_nil }
end

it "should reset the first item for parent item dictionary" do
Expand Down Expand Up @@ -378,8 +378,8 @@
def render_and_find_objects
output = StringIO.new(@pdf.render, 'r+')
@hash = PDF::Reader::ObjectHash.new(output)
@outline_root = @hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Outlines}
@pages = @hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
@outline_root = @hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Outlines }
@pages = @hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Pages }[:Kids]
@section_1 = find_by_title('Chapter 1')
@page_1 = find_by_title('Page 1')
@page_2 = find_by_title('Page 2')
Expand Down
2 changes: 1 addition & 1 deletion spec/png_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
describe "When reading an indexed color PNG file with transparency (color type 3)" do
it "raises a not supported error" do
bin = File.binread("#{Prawn::DATADIR}/images/pal_bk.png")
expect { Prawn::Images::PNG.new(bin)}.to(
expect { Prawn::Images::PNG.new(bin) }.to(
raise_error(Prawn::Errors::UnsupportedImageType))
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/repeater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@
doc = sample_document

doc.expects(:stamp).never
(1..10).each { |p| repeater(doc, :all, true){:do_nothing}.run(p) }
(1..10).each { |p| repeater(doc, :all, true){ :do_nothing }.run(p) }
end

it "must try to run a block if the page number matches" do
doc = sample_document

doc.expects(:draw_text).twice
(1..10).each { |p| repeater(doc, [1, 2], true){doc.draw_text "foo"}.run(p) }
(1..10).each { |p| repeater(doc, [1, 2], true){ doc.draw_text "foo" }.run(p) }
end

it "must not try to run a block unless the page number matches" do
doc = sample_document

doc.expects(:draw_text).never
repeater(doc, :odd, true){doc.draw_text "foo"}.run(2)
repeater(doc, :odd, true){ doc.draw_text "foo" }.run(2)
end

it "must treat any block as a closure" do
Expand All @@ -96,7 +96,7 @@
end

text = PDF::Inspector::Text.analyze(doc.render)
expect(text.strings).to eq((1..10).to_a.map{|p| "Page #{p}"})
expect(text.strings).to eq((1..10).to_a.map{ |p| "Page #{p}" })
end

it "must treat any block as a closure (Document.new instance_eval form)" do
Expand All @@ -111,7 +111,7 @@
end

text = PDF::Inspector::Text.analyze(doc.render)
expect(text.strings).to eq((1..10).to_a.map{|p| "Page #{p}"})
expect(text.strings).to eq((1..10).to_a.map{ |p| "Page #{p}" })
end

def sample_document
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/extensions/ and its subdirectories.
Dir[File.dirname(__FILE__) + "/extensions/**/*.rb"].each {|f| require f }
Dir[File.dirname(__FILE__) + "/extensions/**/*.rb"].each { |f| require f }

RSpec.configure do |config|
config.mock_framework = :mocha
Expand Down
2 changes: 1 addition & 1 deletion spec/stamp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"stamp XObject, not the page" do
create_pdf
@pdf.create_stamp("MyStamp") do
@pdf.transparent(0.5) { @pdf.circle([100, 100], 10)}
@pdf.transparent(0.5) { @pdf.circle([100, 100], 10) }
end
@pdf.stamp("MyStamp")

Expand Down

0 comments on commit 4053a53

Please sign in to comment.