prawn-grouping 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: edbb74b3d883deb5f4c93d595265253f98635aa5
4
- data.tar.gz: 3e142422f61347f6b98aeb3bab1590748926c816
2
+ SHA256:
3
+ metadata.gz: aead835d0b903112a2a55fc086b9062aac77d1d399750791339c94e2fbde1fdf
4
+ data.tar.gz: 5e10604251eadec6c215d2709ef5b14c5fe6092ae2ef5adb7d947a7371391769
5
5
  SHA512:
6
- metadata.gz: 8733b32e99044a0a70faa3ebbdd4a99fdcdd70b8711fd38ac535f550c44c344bc66c18bd8c2461009f277bd422569e1dfef16b2d0c5868d2f0a4836ba46ad9af
7
- data.tar.gz: 2a76aef33d15346be91de76fd408e74fbee24e0fd0229fe99cba441fae62f715dda77691c44369e71085c10f48933f31ca3505e07a58e3f4b63b99f7586292c8
6
+ metadata.gz: d90cbb94ac56d9035274f26554247246f68d7592ed3856f202392d5cf477742d2a49da1c4e6e6f13e2751555321aebec99e7550203848d1e96181ad8110547aa
7
+ data.tar.gz: f718a7b7f64615d53ca9c465d5a367417adb25622e29ea711d91b800f1e3337980ec5da90d1aeb914451931e7916923e478e6c638b035318237185cb0f899f5e
data/.gitignore CHANGED
@@ -19,3 +19,6 @@ tmp
19
19
  /bin/
20
20
 
21
21
  /.DS_Store
22
+ /gemfiles/prawn_2.gemfile.lock
23
+ /gemfiles/prawn_1.gemfile.lock
24
+ /test.pdf
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- - rbx-2
7
- - jruby-19mode
8
- matrix:
9
- allow_failures:
10
- - rvm: rbx-2
3
+ - 2.3.7
4
+ - 2.4.4
5
+ - 2.5.1
6
+ - jruby-9.2.0.0
7
+
8
+ gemfile:
9
+ - gemfiles/prawn_2_1.gemfile
10
+ - gemfiles/prawn_2_2.gemfile
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## v0.2.0
4
+
5
+ * group parameter is no longer optional
6
+ * official support for ruby 1.9, 2.0, 2.1, 2.2 and rubinius removed
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem "guard"
6
+ gem "guard-rspec"
data/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- guard :rspec do
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/prawn/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
data/README.md CHANGED
@@ -27,8 +27,8 @@ Or install it yourself as:
27
27
  ```ruby
28
28
  Prawn::Document.new do
29
29
  20.times { text "Regular text" }
30
- group do
31
- 20.times { text "Paragraphs not separated unless neccessary" }
30
+ group do |g|
31
+ 20.times { g.text "Paragraphs not separated unless necessary" }
32
32
  end
33
33
  end
34
34
  ```
@@ -38,10 +38,10 @@ end
38
38
  ```ruby
39
39
  Prawn::Document.new do
40
40
  5.times { text "Regular text" }
41
- group do
42
- 15.times { text "Paragraphs not separated unless neccessary" }
43
- group do
44
- 30.times { text "Subparagraphs not separated unless neccessary" }
41
+ group do |g|
42
+ 15.times { g.text "Paragraphs not separated unless necessary" }
43
+ group do |g|
44
+ 30.times { g.text "Subparagraphs not separated unless necessary" }
45
45
  end
46
46
  end
47
47
  end
@@ -61,8 +61,8 @@ Currently three callbacks are supported:
61
61
  Prawn::Document.new do
62
62
  5.times { text "Regular text" }
63
63
 
64
- group :too_tall => lambda { start_new_page } do
65
- 15.times { text "Paragraphs not separated unless neccessary" }
64
+ group :too_tall => lambda { start_new_page } do |g|
65
+ 15.times { g.text "Paragraphs not separated unless necessary" }
66
66
  end
67
67
  end
68
68
  ```
@@ -72,18 +72,22 @@ The example above starts a new page if the content is too tall for a single page
72
72
 
73
73
  ## Troubleshooting
74
74
 
75
- When using JRuby a block parameter has to be supplied. For the other tested Interpreters this is optional.
75
+ #### When using JRuby on a version smaller than 0.2.0 a block parameter has to be supplied. For the other tested Interpreters this was optional.
76
76
 
77
77
  ```ruby
78
78
  Prawn::Document.new do
79
79
  5.times { text "Regular text" }
80
80
 
81
81
  group do |g|
82
- 15.times { g.text "Paragraphs not separated unless neccessary" }
82
+ 15.times { g.text "Paragraphs not separated unless necessary" }
83
83
  end
84
84
  end
85
85
  ```
86
86
 
87
+ #### Manipulating objects within the group block
88
+
89
+ The grouping internally works by executing the block one or _multiple_ times and checking the results, because deep copy did not work well for the original implementation in many cases. As a result you should not manipulate your data objects within the block. See issue #7 for details.
90
+
87
91
  ## Contributing
88
92
 
89
93
  1. Fork it ( http://github.com/<my-github-username>/prawn-grouping/fork )
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem "prawn", "~> 2.1.0"
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem "prawn", "~> 2.2.0"
@@ -3,9 +3,9 @@ require "prawn/grouping/version"
3
3
 
4
4
  module Prawn
5
5
  module Grouping
6
-
6
+
7
7
  # Groups a given block vertiacally within the current context, if possible.
8
- #
8
+ #
9
9
  # Parameters are:
10
10
  #
11
11
  # <tt>options</tt>:: A hash for grouping options.
@@ -16,7 +16,7 @@ module Prawn
16
16
  # <tt>:fits_current_context</tt>:: A proc called before the content is
17
17
  # rendered and does fit context.
18
18
  #
19
- def group(options = {}, &b)
19
+ def group(options = {})
20
20
  too_tall = options[:too_tall]
21
21
  fits_new_context = options[:fits_new_context]
22
22
  fits_current_context = options[:fits_current_context]
@@ -24,27 +24,27 @@ module Prawn
24
24
  # create a temporary document with current context and offset
25
25
  pdf = create_box_clone
26
26
  pdf.y = y
27
- pdf.instance_exec pdf, &b
27
+ yield pdf
28
28
 
29
29
  if pdf.page_count > 1
30
30
  # create a temporary document without offset
31
31
  pdf = create_box_clone
32
- pdf.instance_exec pdf, &b
32
+ yield pdf
33
33
 
34
34
  if pdf.page_count > 1
35
35
  # does not fit new context
36
36
  too_tall.call if too_tall
37
- b.call(self)
37
+ yield self
38
38
  else
39
39
  fits_new_context.call if fits_new_context
40
40
  bounds.move_past_bottom
41
- b.call(self)
41
+ yield self
42
42
  end
43
43
  return false
44
44
  else
45
45
  # just render it
46
46
  fits_current_context.call if fits_current_context
47
- b.call(self)
47
+ yield self
48
48
  return true
49
49
  end
50
50
  end
@@ -56,11 +56,12 @@ module Prawn
56
56
  pdf.margin_box = @bounding_box.dup
57
57
  pdf.text_formatter = @text_formatter.dup
58
58
  pdf.font_families.update font_families
59
- pdf.font font.name
59
+ pdf.font font.family
60
60
  pdf.font_size font_size
61
+ pdf.default_leading = default_leading
61
62
  end
62
63
  end
63
64
  end
64
65
  end
65
66
 
66
- Prawn::Document.extensions << Prawn::Grouping
67
+ Prawn::Document.extensions << Prawn::Grouping
@@ -1,5 +1,5 @@
1
1
  module Prawn
2
2
  module Grouping
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -16,17 +16,15 @@ Gem::Specification.new do |spec|
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.test_files = Dir[ "spec/*_spec.rb" ]
18
18
  spec.require_path = "lib"
19
- spec.required_ruby_version = '>= 1.9.3'
20
- spec.required_rubygems_version = ">= 1.3.6"
19
+ spec.required_ruby_version = '>= 2.3.0'
20
+ spec.required_rubygems_version = ">= 2.0.0"
21
21
 
22
- spec.add_dependency "prawn", "~> 1.0.0"
22
+ spec.add_dependency "prawn", ">= 2.0.0"
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "rspec"
27
- spec.add_development_dependency "pdf-inspector", "~> 1.1.0"
28
- spec.add_development_dependency "pdf-reader", "~>1.2"
29
- spec.add_development_dependency "guard"
30
- spec.add_development_dependency "guard-rspec"
27
+ spec.add_development_dependency "pdf-inspector", "~> 1.3.0"
28
+ spec.add_development_dependency "pdf-reader", "~>2.1.0"
31
29
  spec.add_development_dependency "growl"
32
30
  end
@@ -3,32 +3,32 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
3
  describe "Prawn::Grouping" do
4
4
  it "returns true if the content fits in the current context" do
5
5
  pdf = Prawn::Document.new
6
- val = pdf.group do |pdf|
6
+ val = pdf.group do |pdf|
7
7
  pdf.text "FooBar"
8
8
  end
9
- (!!val).should == true
9
+ expect(!!val).to eq(true)
10
10
 
11
11
  pages = PDF::Inspector::Page.analyze(pdf.render).pages
12
- pages.size.should == 1
12
+ expect(pages.size).to eq(1)
13
13
  end
14
14
 
15
15
  it "calls callbacks according to content length" do
16
16
  called = 0
17
- pdf = Prawn::Document.new do
18
- group :fits_current_context => lambda { called = 1 } do |pdf|
17
+ pdf = Prawn::Document.new do |pdf|
18
+ pdf.group :fits_current_context => lambda { called = 1 } do |pdf|
19
19
  20.times { pdf.text "FooBar 1" }
20
20
  end
21
- called.should == 1
21
+ expect(called).to eq(1)
22
22
 
23
- group :fits_new_context => lambda { called = 2 } do |pdf|
23
+ pdf.group :fits_new_context => lambda { called = 2 } do |pdf|
24
24
  40.times { pdf.text "FooBar 2" }
25
25
  end
26
- called.should == 2
26
+ expect(called).to eq(2)
27
27
 
28
- group :too_tall => lambda { called = 3 } do |pdf|
28
+ pdf.group :too_tall => lambda { called = 3 } do |pdf|
29
29
  100.times { pdf.text "FooBar 3" }
30
30
  end
31
- called.should == 3
31
+ expect(called).to eq(3)
32
32
  end
33
33
  end
34
34
 
@@ -46,29 +46,29 @@ describe "Prawn::Grouping" do
46
46
  end
47
47
  end
48
48
  pages = PDF::Inspector::Page.analyze(pdf.render).pages
49
- pages.size.should == 2
49
+ expect(pages.size).to eq(2)
50
50
  end
51
51
 
52
52
  # the following example were copied to fit the original spec from
53
53
  # https://github.com/prawnpdf/prawn/blob/master/spec/document_spec.rb
54
54
  it "should group a simple block on a single page" do
55
- pdf = Prawn::Document.new do
56
- self.y = 50
57
- val = group do |pdf|
55
+ pdf = Prawn::Document.new do |pdf|
56
+ pdf.y = 50
57
+ val = pdf.group do |pdf|
58
58
  pdf.text "Hello"
59
59
  pdf.text "World"
60
60
  end
61
61
 
62
62
  # group should return a false value since a new page was started
63
- (!!val).should == false
63
+ expect(!!val).to eq(false)
64
64
  end
65
65
  pages = PDF::Inspector::Page.analyze(pdf.render).pages
66
- pages.size.should == 2
67
- pages[0][:strings].should == []
68
- pages[1][:strings].should == ["Hello", "World"]
66
+ expect(pages.size).to eq(2)
67
+ expect(pages[0][:strings]).to eq([])
68
+ expect(pages[1][:strings]).to eq(["Hello", "World"])
69
69
  end
70
70
 
71
-
71
+
72
72
 
73
73
  it "should group within individual column boxes" do
74
74
  pdf = Prawn::Document.new do
@@ -84,7 +84,25 @@ describe "Prawn::Grouping" do
84
84
 
85
85
  # Second page should start with a 0 because it's a new group.
86
86
  pages = PDF::Inspector::Page.analyze(pdf.render).pages
87
- pages.size.should == 2
88
- pages[1][:strings].first.should == '0'
87
+ expect(pages.size).to eq(2)
88
+ expect(pages[1][:strings].first).to eq('0')
89
+ end
90
+
91
+ it "should allow the use of inline formatting" do
92
+ pdf = Prawn::Document.new do
93
+ # Set up columns with grouped blocks of 0..49. 0 to 49 is slightly short
94
+ # of the height of one page / column, so each column should get its own
95
+ # group (every column should start with zero).
96
+ group do |pdf|
97
+ 10.times { |i| pdf.text("<b>#{i}</b>", inline_format: true) }
98
+ end
99
+ end
100
+
101
+ # Second page should start with a 0 because it's a new group.
102
+ pages = PDF::Inspector::Page.analyze(pdf.render).pages
103
+ expect(pages.size).to eq(1)
104
+ expect(pages[0][:strings].first).to eq('0')
105
+
106
+ pdf.render_file 'test.pdf'
89
107
  end
90
- end
108
+ end
@@ -7,7 +7,6 @@ require "pdf/reader"
7
7
  require "pdf/inspector"
8
8
 
9
9
  RSpec.configure do |config|
10
- config.treat_symbols_as_metadata_keys_with_true_values = true
11
10
  config.run_all_when_everything_filtered = true
12
11
  config.filter_run :focus
13
12
  config.order = 'random'
metadata CHANGED
@@ -1,139 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-grouping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Dengler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-23 00:00:00.000000000 Z
11
+ date: 2018-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: 2.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: 2.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.5'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.5'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pdf-inspector
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.1.0
75
+ version: 1.3.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.1.0
82
+ version: 1.3.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pdf-reader
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
88
- - !ruby/object:Gem::Version
89
- version: '1.2'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ~>
95
- - !ruby/object:Gem::Version
96
- version: '1.2'
97
- - !ruby/object:Gem::Dependency
98
- name: guard
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - '>='
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: guard-rspec
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - '>='
87
+ - - "~>"
116
88
  - !ruby/object:Gem::Version
117
- version: '0'
89
+ version: 2.1.0
118
90
  type: :development
119
91
  prerelease: false
120
92
  version_requirements: !ruby/object:Gem::Requirement
121
93
  requirements:
122
- - - '>='
94
+ - - "~>"
123
95
  - !ruby/object:Gem::Version
124
- version: '0'
96
+ version: 2.1.0
125
97
  - !ruby/object:Gem::Dependency
126
98
  name: growl
127
99
  requirement: !ruby/object:Gem::Requirement
128
100
  requirements:
129
- - - '>='
101
+ - - ">="
130
102
  - !ruby/object:Gem::Version
131
103
  version: '0'
132
104
  type: :development
133
105
  prerelease: false
134
106
  version_requirements: !ruby/object:Gem::Requirement
135
107
  requirements:
136
- - - '>='
108
+ - - ">="
137
109
  - !ruby/object:Gem::Version
138
110
  version: '0'
139
111
  description:
@@ -143,14 +115,17 @@ executables: []
143
115
  extensions: []
144
116
  extra_rdoc_files: []
145
117
  files:
146
- - .gitignore
147
- - .rspec
148
- - .travis.yml
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - CHANGELOG.md
149
122
  - Gemfile
150
123
  - Guardfile
151
124
  - LICENSE.txt
152
125
  - README.md
153
126
  - Rakefile
127
+ - gemfiles/prawn_2_1.gemfile
128
+ - gemfiles/prawn_2_2.gemfile
154
129
  - lib/prawn/grouping.rb
155
130
  - lib/prawn/grouping/version.rb
156
131
  - prawn-grouping.gemspec
@@ -166,17 +141,17 @@ require_paths:
166
141
  - lib
167
142
  required_ruby_version: !ruby/object:Gem::Requirement
168
143
  requirements:
169
- - - '>='
144
+ - - ">="
170
145
  - !ruby/object:Gem::Version
171
- version: 1.9.3
146
+ version: 2.3.0
172
147
  required_rubygems_version: !ruby/object:Gem::Requirement
173
148
  requirements:
174
- - - '>='
149
+ - - ">="
175
150
  - !ruby/object:Gem::Version
176
- version: 1.3.6
151
+ version: 2.0.0
177
152
  requirements: []
178
153
  rubyforge_project:
179
- rubygems_version: 2.0.14
154
+ rubygems_version: 2.7.6
180
155
  signing_key:
181
156
  specification_version: 4
182
157
  summary: Grouping extension for prawn pdf generator