sugpoko 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88e84036fab620a72d223e6b63b24e1aaca2f057
4
- data.tar.gz: 5112051bf8f3054a66aed7a1545f9d58a46abcb7
3
+ metadata.gz: 9f55c3d943cbf37ce969a91cada3db4116cb8a54
4
+ data.tar.gz: f12fb395816002eb6968d8cb85817fc04f2eb3e3
5
5
  SHA512:
6
- metadata.gz: 699cf988d09c49bd0e7e71bf997d2d7786b56721d3d6de22c2d19bffee0c321abb33fb24d199a07ad002b6eeba2c05714829b7f1b137154ed5d0f74b3c21786e
7
- data.tar.gz: f46bc4dd1388ec612f9b86fd3bb3894516c7438166fda47a692d0c1aabaa87138e9d4c4e5a785926a9902a2018cbe69f71316ce32bdcfbda759d29f24def890d
6
+ metadata.gz: 152acfb68107e463792109283656875978f7b3cbb65df2cbd1f0122872a029e89c3916a9a2708f5c9bc54e6f000d5e080e2bdaffe127509f4ff69a68df7a15ec
7
+ data.tar.gz: '048d959b6ef02c9a86fd71e0e3f0c53d5c9a05260644aca2f401adf752332541004334700f54fa021dd75fec9ccd4d92691b14b12a060c7a1602e68c5161c0d2'
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ sandbox
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sugpoko (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ pdf-core (0.7.0)
11
+ prawn (2.2.2)
12
+ pdf-core (~> 0.7.0)
13
+ ttfunk (~> 1.5)
14
+ prawn-table (0.2.2)
15
+ prawn (>= 1.3.0, < 3.0.0)
16
+ rake (10.5.0)
17
+ rspec (3.8.0)
18
+ rspec-core (~> 3.8.0)
19
+ rspec-expectations (~> 3.8.0)
20
+ rspec-mocks (~> 3.8.0)
21
+ rspec-core (3.8.2)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-expectations (3.8.4)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-mocks (3.8.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-support (3.8.2)
30
+ ttfunk (1.5.1)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 2.0)
37
+ prawn
38
+ prawn-table
39
+ rake (~> 10.0)
40
+ rspec (~> 3.0)
41
+ sugpoko!
42
+
43
+ BUNDLED WITH
44
+ 2.0.1
data/lib/sugpoko.rb CHANGED
@@ -2,6 +2,8 @@ require "sugpoko/version"
2
2
  require 'prawn'
3
3
  require 'sugpoko/base'
4
4
  require 'sugpoko/component'
5
+ require "sugpoko/point"
6
+ require "sugpoko/helpers/prawn"
5
7
  require "prawn/measurement_extensions"
6
8
 
7
9
  module Sugpoko
data/lib/sugpoko/base.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Sugpoko
2
2
  class Base
3
- attr_reader :pdf, :data
3
+ attr_reader :pdf, :data, :page_size
4
4
 
5
5
  include Prawn::View
6
6
 
@@ -9,12 +9,38 @@ module Sugpoko
9
9
  end
10
10
 
11
11
  def draw(klass, options = {})
12
- klass.new(options.merge(pdf: pdf)).generate
12
+ klass.new(base_attributes.merge(options)).generate
13
+ end
14
+
15
+ def base_attributes
16
+ {
17
+ pdf: pdf,
18
+ width: width - margin * 2,
19
+ height: height - margin * 2,
20
+ position: [0, pdf.cursor],
21
+ data: data
22
+ }
13
23
  end
14
24
 
15
25
  def initialize(options = {})
16
26
  @data = options[:data]
17
27
  @pdf = self
28
+ configure options
29
+ end
30
+
31
+ def configure(options = {})
32
+ end
33
+
34
+ def width
35
+ 8.5.in
36
+ end
37
+
38
+ def height
39
+ 11.in
40
+ end
41
+
42
+ def margin
43
+ 0.5.in
18
44
  end
19
45
 
20
46
  def document
@@ -23,7 +49,7 @@ module Sugpoko
23
49
 
24
50
  def default_options
25
51
  @default_options ||= {
26
- page_size: [8.5.in, 11.in],
52
+ page_size: [width, height],
27
53
  page_layout: :portrait
28
54
  }
29
55
  end
@@ -1,16 +1,44 @@
1
+ require "sugpoko/helpers/prawn"
2
+
1
3
  class Sugpoko::Component
2
- attr_reader :pdf, :cursor_origin
4
+ include Sugpoko::Helpers::Prawn
5
+ attr_reader :pdf, :cursor_origin, :position, :data, :width, :height
3
6
 
4
7
  def generate
5
8
  raise '#generate not defined'
6
9
  end
7
10
 
8
11
  def draw(klass, options = {})
9
- klass.new(options.merge(pdf: pdf)).generate
12
+ klass.new(base_attributes.merge(options)).generate
13
+ end
14
+
15
+ def base_attributes
16
+ {
17
+ pdf: pdf,
18
+ width: width,
19
+ height: height,
20
+ position: [0, pdf.cursor],
21
+ data: data
22
+ }
10
23
  end
11
24
 
12
25
  def initialize(options = {})
13
26
  @pdf = options.fetch(:pdf)
14
- @cursor_origin = pdf.cursor
27
+ @width = options.fetch(:width)
28
+ @height = options.fetch(:height)
29
+ initialize_position(options.fetch(:position))
30
+ configure(options)
31
+ end
32
+
33
+ def initialize_position(point)
34
+ if point
35
+ @position = Sugpoko::Point.new *point
36
+ else
37
+ @position = Sugpoko::Point.new 0, pdf.cursor
38
+ end
39
+ end
40
+
41
+ def configure(options = {})
42
+ # override this for other initialization process
15
43
  end
16
44
  end
@@ -0,0 +1,22 @@
1
+ module Sugpoko
2
+ module Helpers
3
+ module Prawn
4
+ def bounding_box(options = {})
5
+ pos, options = build_bounding_box_options(options)
6
+ pdf.bounding_box pos, options do
7
+ yield
8
+ end
9
+ end
10
+
11
+ def build_bounding_box_options(options)
12
+ pos = options.fetch(:position) { position }
13
+ bounding_box_options = {
14
+ width: width,
15
+ height: height
16
+ }
17
+ bounding_box_options.merge! options
18
+ return pos, bounding_box_options
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,47 @@
1
+ module Sugpoko
2
+ class Point
3
+ attr_accessor :x, :y
4
+
5
+ def initialize(*args)
6
+ if args[0].is_a?(Hash)
7
+ @x, @y = identify(args[0])
8
+ else
9
+ @x, @y = identify(args)
10
+ end
11
+ end
12
+
13
+ def +(obj)
14
+ id_x, id_y = identify obj
15
+ self.class.new x + id_x, y + id_y
16
+ end
17
+
18
+ def -(obj)
19
+ self.class.new x - obj.x, y - obj.y
20
+ end
21
+
22
+ def ==(obj)
23
+ x == obj.x && y == obj.y
24
+ end
25
+
26
+ def to_s
27
+ "[#{x}, #{y}]"
28
+ end
29
+
30
+ def to_ary
31
+ [x, y]
32
+ end
33
+
34
+ private
35
+
36
+ def identify(obj)
37
+ case obj.class.to_s
38
+ when 'Array'
39
+ obj
40
+ when 'Hash'
41
+ [ obj[:x], obj[:y] ]
42
+ else # assumes an object that responds to 'x' and 'y'
43
+ [ obj.x, obj.y ]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module Sugpoko
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/sugpoko.gemspec CHANGED
@@ -38,4 +38,6 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency "bundler", "~> 2.0"
39
39
  spec.add_development_dependency "rake", "~> 10.0"
40
40
  spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "prawn"
42
+ spec.add_development_dependency "prawn-table"
41
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugpoko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Nelson Valeros
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-21 00:00:00.000000000 Z
11
+ date: 2019-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: prawn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: prawn-table
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: 'Modularize your prawnpdf code '
56
84
  email:
57
85
  - valerosjoseph@gmail.com
@@ -63,6 +91,7 @@ files:
63
91
  - ".rspec"
64
92
  - ".travis.yml"
65
93
  - Gemfile
94
+ - Gemfile.lock
66
95
  - README.md
67
96
  - Rakefile
68
97
  - bin/console
@@ -70,6 +99,8 @@ files:
70
99
  - lib/sugpoko.rb
71
100
  - lib/sugpoko/base.rb
72
101
  - lib/sugpoko/component.rb
102
+ - lib/sugpoko/helpers/prawn.rb
103
+ - lib/sugpoko/point.rb
73
104
  - lib/sugpoko/version.rb
74
105
  - sugpoko.gemspec
75
106
  homepage: https://github.com/neume/sugpoko