dot_grid 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/base +13 -2
  3. data/bin/dotgrid +4 -1
  4. data/lib/dot_grid/generator.rb +15 -3
  5. data/lib/dot_grid/page/checkerboard.rb +20 -0
  6. data/lib/dot_grid/page/dot_grid.rb +22 -0
  7. data/lib/dot_grid/page/grid.rb +21 -0
  8. data/lib/dot_grid/page/horizontal_rule.rb +20 -0
  9. data/lib/dot_grid/page/page.rb +40 -0
  10. data/lib/dot_grid/page/planner.rb +118 -0
  11. data/lib/dot_grid/pattern/checkerboard.rb +17 -0
  12. data/lib/dot_grid/pattern/dot_grid.rb +22 -0
  13. data/lib/dot_grid/pattern/grid.rb +15 -0
  14. data/lib/dot_grid/pattern/horizontal_rule.rb +13 -0
  15. data/lib/dot_grid/pattern/pattern.rb +37 -0
  16. data/lib/dot_grid/version.rb +1 -1
  17. data/lib/dot_grid.rb +13 -3
  18. data/spec/lib/dot_grid/generator_spec.rb +21 -5
  19. data/spec/lib/dot_grid/page/checkerboard_spec.rb +19 -0
  20. data/spec/lib/dot_grid/page/dot_grid_spec.rb +28 -0
  21. data/spec/lib/dot_grid/page/grid_spec.rb +28 -0
  22. data/spec/lib/dot_grid/page/horizontal_rule_spec.rb +28 -0
  23. data/spec/lib/dot_grid/{planner_spec.rb → page/planner_spec.rb} +18 -18
  24. data/spec/lib/dot_grid/pattern/checkerboard_spec.rb +39 -0
  25. data/spec/lib/dot_grid/pattern/dot_grid_spec.rb +26 -0
  26. data/spec/lib/dot_grid/pattern/grid_spec.rb +32 -0
  27. data/spec/lib/dot_grid/pattern/horizontal_rule_spec.rb +26 -0
  28. data/spec/lib/dot_grid/pattern/pattern_spec.rb +39 -0
  29. data/spec/spec_helper.rb +2 -1
  30. metadata +33 -11
  31. data/lib/dot_grid/grid.rb +0 -29
  32. data/lib/dot_grid/page.rb +0 -34
  33. data/lib/dot_grid/planner.rb +0 -116
  34. data/spec/lib/dot_grid/grid_spec.rb +0 -19
  35. data/spec/lib/dot_grid/page_spec.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37dc6770f99c575f28ae776313c5f63d578b5bb2
4
- data.tar.gz: 2ce9b5d286a2ee92eab7c0dbc14321827d6c3040
3
+ metadata.gz: 54a925c03705950b5f01d2c6cb92ee1bc9f3e023
4
+ data.tar.gz: 4511d7eea919e7397faa5a181a94bd8b20aea0c9
5
5
  SHA512:
6
- metadata.gz: 825a31391384cfd28e187a1944d29ffd13951d3506666bbc26cf1cd63e716de4a71961fd8759209f5ac9094ddc9ee785deb8bc08b6235d575a54377acc9a7a27
7
- data.tar.gz: cc2932c0ac9baf8ae5b42685e58be4b4c704a3810bd8a0eda07466eed76903a57412b9974a3258b4207b1af89a7c46e73acf84d19d2188b45844cdbaa737d258
6
+ metadata.gz: 8c4cb6d4f14c07903142d916f181fe23fefb120b988fbc1923223d1b73407bfecc479b034b7e42137ebf0fb88055c97db31698e5b431dbf03b336b64d6789a06
7
+ data.tar.gz: ab5e6792388c751dbf3b0e463d613689b8bcffd42b4a340ce0f818cd3b871165a4837375a2b6f9ea2a9a2122d79cc5ecc84615e44a181fef092bd2d84198ff28
data/base CHANGED
@@ -1,4 +1,15 @@
1
1
  # Base planner
2
- bin/dotgrid -f dotgrid_w5_c2dfff_no_grid.pdf --no-grid --grid-color CFBAEC --dot-weight 0.5 -m 0.0 --planner --planner-color-1 dddddd --planner-color-2 C2DFFF
2
+ bin/dotgrid -f planner_w5_c2dfff_no_grid.pdf --no-dot-grid --grid-color CFBAEC --dot-weight 0.5 -m 0.0 --planner --planner-color-1 dddddd --planner-color-2 C2DFFF
3
+ bin/dotgrid -f planner_w75_c2dfff_no_grid.pdf --no-dot-grid --grid-color CFBAEC --dot-weight 0.75 -m 0.0 --planner --planner-color-1 dddddd --planner-color-2 C2DFFF
3
4
 
4
- bin/dotgrid -f dotgrid_w75_c2dfff_no_grid.pdf --no-grid --grid-color CFBAEC --dot-weight 0.75 -m 0.0 --planner --planner-color-1 dddddd --planner-color-2 C2DFFF
5
+ # Dot grid
6
+ bin/dotgrid -f dot_grid_c2dfff.pdf --dot-grid --spacing 5 --grid-color CFBAEC -m 0.0
7
+
8
+ # Regular grid
9
+ bin/dotgrid -f grid_c2dfff.pdf --grid --no-dot-grid --spacing 5 --grid-color CFBAEC -m 0.0
10
+
11
+ # Horizontal rule
12
+ bin/dotgrid -f horizontal_rule_c2dfff.pdf --horizontal-rule --no-dot-grid --spacing 5 --grid-color CFBAEC -m 0.0
13
+
14
+ # Checkerboard
15
+ bin/dotgrid -f checkerboard_c2dfff.pdf --checkerboard --no-dot-grid --spacing 5 --grid-color CFBAEC -m 0.0
data/bin/dotgrid CHANGED
@@ -10,7 +10,7 @@ require_all 'lib'
10
10
 
11
11
  opts = Trollop::options do
12
12
  opt :file_name, "File Name", :type => :string, :default => "dotgrid.pdf"
13
- opt :grid, "Add a Grid Page", default: true
13
+ opt :dot_grid, "Add a Dot Grid Page", default: true
14
14
  opt :dot_weight, "Dot Weight", :type => :float, :default => 1.5
15
15
  opt :margin, "Border", :type => :float, :default => 0.5
16
16
  opt :page_size, "Page Size (LEGAL, LETTER)", :type => :string, :default => "LETTER"
@@ -18,6 +18,9 @@ opts = Trollop::options do
18
18
  opt :spacing, "Dot Spacing (mm)", :type => :integer, :default => 5
19
19
  opt :pages, "Number of pages", :type => :integer, :default => 1
20
20
  opt :planner, "Add a Planner Page"
21
+ opt :grid, "Add a Regular Grid page"
22
+ opt :horizontal_rule, "Add a Horizontal Rule page"
23
+ opt :checkerboard, "Add a Checkerboard page"
21
24
  opt :planner_color_1, "Planner Left and Footer color", type: :string, default: "CCCCCC"
22
25
  opt :planner_color_2, "Planner Right color", type: :string, default: "0099ff"
23
26
  end
@@ -8,11 +8,16 @@ module DotGrid
8
8
  :file_name,
9
9
  :page_size,
10
10
  :grid,
11
+ :dot_grid_page,
11
12
  :grid_page,
12
13
  :margin,
13
14
  :pages,
14
15
  :planner,
15
- :planner_page
16
+ :planner_page,
17
+ :horizontal_rule,
18
+ :horizontal_rule_page,
19
+ :checkerboard,
20
+ :checkerboard_page,
16
21
  )
17
22
 
18
23
  def initialize(params)
@@ -22,14 +27,21 @@ module DotGrid
22
27
  @pages = params[:pages] || 1
23
28
  @pdf = Prawn::Document.new(margin: margin, page_size: page_size, skip_page_creation: true)
24
29
  params[:pdf] = pdf
25
- @grid_page = DotGrid::Grid.new(params) if params[:grid]
26
- @planner_page = DotGrid::Planner.new(params) if params[:planner]
30
+
31
+ @dot_grid_page = DotGrid::Page::DotGrid.new(params) if params[:dot_grid]
32
+ @planner_page = DotGrid::Page::Planner.new(params) if params[:planner]
33
+ @grid_page = DotGrid::Page::Grid.new(params) if params[:grid]
34
+ @horizontal_rule_page = DotGrid::Page::HorizontalRule.new(params) if params[:horizontal_rule]
35
+ @checkerboard_page = DotGrid::Page::Checkerboard.new(params) if params[:checkerboard]
27
36
  end
28
37
 
29
38
  def generate
30
39
  (1..pages).each do |page|
31
40
  planner_page.generate if planner_page
32
41
  grid_page.generate if grid_page
42
+ dot_grid_page.generate if dot_grid_page
43
+ horizontal_rule_page.generate if horizontal_rule_page
44
+ checkerboard_page.generate if checkerboard_page
33
45
  end
34
46
  pdf.render_file file_name
35
47
  end
@@ -0,0 +1,20 @@
1
+ module DotGrid
2
+ module Page
3
+ class Checkerboard < Page
4
+ attr_accessor(
5
+ :pattern,
6
+ )
7
+
8
+ def initialize(params)
9
+ super
10
+ @pattern = ::DotGrid::Pattern::Checkerboard.new(params.merge!(:bounds => pdf.bounds))
11
+ end
12
+
13
+ def generate
14
+ super
15
+ pattern.draw
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,22 @@
1
+ module DotGrid
2
+ module Page
3
+ class DotGrid < Page
4
+ attr_accessor(
5
+ :dot_weight,
6
+ :grid_color,
7
+ :spacing,
8
+ :pattern
9
+ )
10
+
11
+ def initialize(params)
12
+ super
13
+ @pattern = ::DotGrid::Pattern::DotGrid.new(params.merge!(:bounds => pdf.bounds))
14
+ end
15
+
16
+ def generate
17
+ super
18
+ pattern.draw
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module DotGrid
2
+ module Page
3
+ class Grid < Page
4
+ attr_accessor(
5
+ :grid_color,
6
+ :spacing,
7
+ :pattern
8
+ )
9
+
10
+ def initialize(params)
11
+ super
12
+ @pattern = ::DotGrid::Pattern::Grid.new(params.merge!(:bounds => pdf.bounds))
13
+ end
14
+
15
+ def generate
16
+ super
17
+ pattern.draw
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ module DotGrid
2
+ module Page
3
+ class HorizontalRule < Page
4
+ attr_accessor(
5
+ :pattern
6
+ )
7
+
8
+ def initialize(params)
9
+ super
10
+ @pattern = ::DotGrid::Pattern::HorizontalRule.new(params.merge!(:bounds => pdf.bounds))
11
+ end
12
+
13
+ def generate
14
+ super
15
+ pattern.draw
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,40 @@
1
+ module DotGrid
2
+ module Page
3
+ class Page
4
+ attr_accessor(
5
+ :pdf,
6
+ :dot_weight,
7
+ :grid_color,
8
+ :spacing
9
+ )
10
+
11
+ def initialize(params)
12
+ @pdf = params[:pdf]
13
+ @dot_weight = params[:dot_weight] || 1.5
14
+ @grid_color = params[:grid_color] || "B3B3B3"
15
+ @spacing = params[:spacing] ? params[:spacing].mm : 5.mm
16
+ end
17
+
18
+ def generate
19
+ pdf.start_new_page
20
+ end
21
+
22
+ def page_width
23
+ pdf.bounds.width
24
+ end
25
+
26
+ def page_height
27
+ pdf.bounds.height
28
+ end
29
+
30
+ def draw_dot_grid(rows, columns, left_start, height_start)
31
+ pdf.fill_color grid_color
32
+ (1..rows).each do |row|
33
+ (1..columns).each do |col|
34
+ pdf.fill_circle [left_start + (col-1)*spacing, height_start - spacing - (row-1)*spacing], dot_weight
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,118 @@
1
+ module DotGrid
2
+ module Page
3
+ class Planner < Page
4
+ attr_accessor(
5
+ :planner_color_1,
6
+ :planner_color_2
7
+ )
8
+
9
+ HEADER_HEIGHT = 0.05 # 5.0 %
10
+ HEADER_LEFT_START = 0.05 # 5.0%
11
+ SQUARE_GRID_WIDTH = 0.30 # 30.0%
12
+ HEADER_GAP_WIDTH = 0.03 # 3.0%
13
+ DOT_GRID_COLUMN_WIDTH = 0.62 # 62%
14
+ SQUARE_GRID_ROWS_WIDTH = 0.80 # 80%
15
+ FOOT_HEIGHT_RATIO = 2 # Ratio of footer to header
16
+
17
+ def initialize(params)
18
+ super
19
+ @planner_color_1 = params[:planner_color_1] || "CCCCCC"
20
+ @planner_color_2 = params[:planner_color_2] || "0099ff"
21
+ end
22
+
23
+ def header_height
24
+ HEADER_HEIGHT * page_height
25
+ end
26
+
27
+ def square_grid_columns
28
+ ((SQUARE_GRID_WIDTH * page_width) / spacing).floor
29
+ end
30
+
31
+ def header_left_color
32
+ planner_color_1
33
+ end
34
+
35
+ def header_left_start
36
+ HEADER_LEFT_START * page_width
37
+ end
38
+
39
+ def header_left_width
40
+ square_grid_columns*spacing
41
+ end
42
+
43
+ def header_gap_start
44
+ header_left_start + header_left_width
45
+ end
46
+
47
+ def header_gap_width
48
+ page_width * HEADER_GAP_WIDTH
49
+ end
50
+
51
+ def dot_grid_columns
52
+ (page_width * DOT_GRID_COLUMN_WIDTH / spacing).floor + 2
53
+ end
54
+
55
+ def dot_grid_rows
56
+ square_grid_rows + 1
57
+ end
58
+
59
+ def header_right_color
60
+ planner_color_2
61
+ end
62
+
63
+ def header_right_start
64
+ header_gap_start + header_gap_width
65
+ end
66
+
67
+ def header_right_width
68
+ page_width - header_right_start
69
+ end
70
+
71
+ def square_grid_rows
72
+ (page_height * SQUARE_GRID_ROWS_WIDTH / spacing).floor
73
+ end
74
+
75
+ def footer_height
76
+ header_height * FOOT_HEIGHT_RATIO
77
+ end
78
+
79
+ def generate
80
+ super
81
+
82
+ # Header left
83
+ draw_header(header_left_start, header_left_width, header_height, header_left_color)
84
+
85
+ # Header right
86
+ draw_header(header_right_start, header_right_width, header_height, header_right_color)
87
+
88
+ # Square Grid Left
89
+ draw_square_grid_left(square_grid_rows, square_grid_columns, header_left_color, header_left_start, page_height - header_height - spacing, spacing)
90
+
91
+ # Dot Grid Right
92
+ draw_dot_grid(dot_grid_rows, dot_grid_columns, header_right_start, page_height-header_height)
93
+
94
+ # Footer
95
+ draw_footer(planner_color_1, header_left_start, footer_height, page_width-header_left_start)
96
+ end
97
+
98
+ def draw_header(header_start, header_width, header_height, header_color)
99
+ pdf.fill_color header_color
100
+ pdf.fill_rectangle [header_start, page_height], header_width, header_height
101
+ end
102
+
103
+ def draw_square_grid_left(square_grid_rows, square_grid_columns, grid_color, left_start, height_start, spacing)
104
+ pdf.fill_color grid_color
105
+ (1..square_grid_rows).each do |row|
106
+ (1..square_grid_columns).each do |col|
107
+ pdf.fill_rectangle [left_start + (col-1)*spacing, height_start - (row-1)*spacing], spacing-1 ,spacing-1
108
+ end
109
+ end
110
+ end
111
+
112
+ def draw_footer(footer_color, footer_start, footer_height, footer_width)
113
+ pdf.fill_color footer_color
114
+ pdf.fill_rectangle [footer_start, footer_height], footer_width, footer_height
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,17 @@
1
+ module DotGrid
2
+ module Pattern
3
+ class Checkerboard < Pattern
4
+
5
+ def draw
6
+ pdf.fill_color grid_color
7
+ (0..rows).each do |row|
8
+ (0..columns).each do |column|
9
+ if (row % 2 == 0 && column % 2 == 0) || (row % 2 == 1 && column % 2 == 1)
10
+ pdf.fill_rectangle [column*spacing, row*spacing], spacing, spacing
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ module DotGrid
2
+ module Pattern
3
+ class DotGrid < Pattern
4
+ attr_accessor(
5
+ :dot_weight,
6
+ )
7
+
8
+ def post_initialize(params)
9
+ @dot_weight = params[:dot_weight] || 1.5
10
+ end
11
+
12
+ def draw
13
+ pdf.fill_color grid_color
14
+ (0..rows).each do |row|
15
+ (0..columns).each do |col|
16
+ pdf.fill_circle [col*spacing, row*spacing], dot_weight
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module DotGrid
2
+ module Pattern
3
+ class Grid < Pattern
4
+ def draw
5
+ pdf.stroke_color grid_color
6
+ (0..rows).each do |row|
7
+ pdf.stroke_horizontal_line(0, bounds.width, :at => row*spacing)
8
+ end
9
+ (0..columns).each do |column|
10
+ pdf.stroke_vertical_line(0, bounds.height, :at => column*spacing)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module DotGrid
2
+ module Pattern
3
+ class HorizontalRule < Pattern
4
+
5
+ def draw
6
+ pdf.stroke_color grid_color
7
+ (0..rows).each do |row|
8
+ pdf.stroke_horizontal_line(0, bounds.width, :at => row*spacing)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ module DotGrid
2
+ module Pattern
3
+ class Pattern
4
+ attr_accessor(
5
+ :pdf,
6
+ :bounds,
7
+ :grid_color,
8
+ :spacing,
9
+ )
10
+
11
+ def initialize(params = {})
12
+ @pdf = params[:pdf]
13
+ @bounds = params[:bounds]
14
+ @grid_color = params[:grid_color] || "B3B3B3"
15
+ @spacing = params[:spacing] ? params[:spacing].mm : 5.mm
16
+ post_initialize(params)
17
+ end
18
+
19
+ def post_initialize(params)
20
+ nil
21
+ end
22
+
23
+ def rows
24
+ (bounds.height / spacing).floor
25
+ end
26
+
27
+ def columns
28
+ (bounds.width / spacing).floor
29
+ end
30
+
31
+ def draw
32
+ raise NotImplementedError
33
+ end
34
+ end
35
+ end
36
+ end
37
+
@@ -1,3 +1,3 @@
1
1
  module DotGrid
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/dot_grid.rb CHANGED
@@ -1,7 +1,17 @@
1
1
  require 'dot_grid/generator'
2
- require 'dot_grid/page'
3
- require 'dot_grid/grid'
4
- require 'dot_grid/planner'
2
+
3
+ require 'dot_grid/page/page'
4
+ require 'dot_grid/page/dot_grid'
5
+ require 'dot_grid/page/planner'
6
+ require 'dot_grid/page/grid'
7
+ require 'dot_grid/page/horizontal_rule'
8
+ require 'dot_grid/page/checkerboard'
9
+
10
+ require 'dot_grid/pattern/pattern'
11
+ require 'dot_grid/pattern/grid'
12
+ require 'dot_grid/pattern/dot_grid'
13
+ require 'dot_grid/pattern/checkerboard'
14
+ require 'dot_grid/pattern/horizontal_rule'
5
15
 
6
16
  module DotGrid
7
17
  end
@@ -27,14 +27,14 @@ describe "DotGrid::Generator" do
27
27
 
28
28
  context "when there is a grid parameter" do
29
29
  it "creates a new grid page" do
30
- expect(DotGrid::Grid).to receive(:new)
31
- DotGrid::Generator.new({:grid => true})
30
+ expect(DotGrid::Page::DotGrid).to receive(:new)
31
+ DotGrid::Generator.new({:dot_grid => true})
32
32
  end
33
33
  end
34
34
 
35
35
  context "when there is a planner parameter" do
36
36
  it "creates a new grid page" do
37
- expect(DotGrid::Planner).to receive(:new)
37
+ expect(DotGrid::Page::Planner).to receive(:new)
38
38
  DotGrid::Generator.new({:planner => true})
39
39
  end
40
40
  end
@@ -49,6 +49,14 @@ describe "DotGrid::Generator" do
49
49
  end
50
50
  end
51
51
 
52
+ context "when there is a dot grid page" do
53
+ let(:subject) { DotGrid::Generator.new(:dot_grid => true)}
54
+ it "generates a new grid page" do
55
+ expect(subject.dot_grid_page).to receive(:generate)
56
+ subject.generate
57
+ end
58
+ end
59
+
52
60
  context "when there is a grid page" do
53
61
  let(:subject) { DotGrid::Generator.new(:grid => true)}
54
62
  it "generates a new grid page" do
@@ -57,11 +65,19 @@ describe "DotGrid::Generator" do
57
65
  end
58
66
  end
59
67
 
68
+ context "when there is a horizontal rule page" do
69
+ let(:subject) { DotGrid::Generator.new(:horizontal_rule => true)}
70
+ it "generates a new horizontal rule page" do
71
+ expect(subject.horizontal_rule_page).to receive(:generate)
72
+ subject.generate
73
+ end
74
+ end
75
+
60
76
  context "when there are multiple pages" do
61
- let(:subject) { DotGrid::Generator.new(:grid => true, :planner => true, :pages => 2)}
77
+ let(:subject) { DotGrid::Generator.new(:dot_grid => true, :planner => true, :pages => 2)}
62
78
 
63
79
  it "generates grid for each page" do
64
- expect(subject.grid_page).to receive(:generate).twice
80
+ expect(subject.dot_grid_page).to receive(:generate).twice
65
81
  subject.generate
66
82
  end
67
83
 
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe "DotGrid::Page::Checkerboard" do
4
+ describe "#draw" do
5
+ let(:pdf) { double('pdf', bounds: double('bounds')) }
6
+ let(:subject) { DotGrid::Page::Checkerboard.new({pdf: pdf})}
7
+ let(:pattern) { double('pattern') }
8
+
9
+ before do
10
+ allow(pdf).to receive(:start_new_page)
11
+ allow(subject).to receive(:pattern).and_return(pattern)
12
+ end
13
+
14
+ it "draws the pattern" do
15
+ expect(pattern).to receive(:draw)
16
+ subject.generate
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe "DotGrid::Page::DotGrid" do
4
+ describe "#initialize" do
5
+ let(:pdf) { double('pdf', bounds: double('bounds')) }
6
+
7
+ it "creates a dot grid pattern" do
8
+ expect(::DotGrid::Pattern::DotGrid).to receive(:new)
9
+ DotGrid::Page::DotGrid.new({pdf: pdf})
10
+ end
11
+ end
12
+
13
+ describe "#generate" do
14
+ let(:pdf) { double('pdf', bounds: double('bounds')) }
15
+ let(:subject) { DotGrid::Page::DotGrid.new({pdf: pdf})}
16
+ let(:pattern) { double('pattern') }
17
+
18
+ before do
19
+ allow(pdf).to receive(:start_new_page)
20
+ allow(subject).to receive(:pattern).and_return(pattern)
21
+ end
22
+
23
+ it "draws the pattern" do
24
+ expect(pattern).to receive(:draw)
25
+ subject.generate
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe "DotGrid::Page::Grid" do
4
+ describe "#initialize" do
5
+ let(:pdf) { double('pdf', bounds: double('bounds')) }
6
+
7
+ it "creates a dot grid pattern" do
8
+ expect(::DotGrid::Pattern::Grid).to receive(:new)
9
+ DotGrid::Page::Grid.new({pdf: pdf})
10
+ end
11
+ end
12
+
13
+ describe "#generate" do
14
+ let(:pdf) { double('pdf', bounds: double('bounds')) }
15
+ let(:subject) { DotGrid::Page::Grid.new({pdf: pdf})}
16
+ let(:pattern) { double('pattern') }
17
+
18
+ before do
19
+ allow(pdf).to receive(:start_new_page)
20
+ allow(subject).to receive(:pattern).and_return(pattern)
21
+ end
22
+
23
+ it "draws the pattern" do
24
+ expect(pattern).to receive(:draw)
25
+ subject.generate
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe "DotGrid::Page::HorizontalRule" do
4
+ describe "#initialize" do
5
+ let(:pdf) { double('pdf', bounds: double('bounds')) }
6
+
7
+ it "creates a dot grid pattern" do
8
+ expect(::DotGrid::Pattern::HorizontalRule).to receive(:new)
9
+ DotGrid::Page::HorizontalRule.new({pdf: pdf})
10
+ end
11
+ end
12
+
13
+ describe "#generate" do
14
+ let(:pdf) { double('pdf', bounds: double('bounds')) }
15
+ let(:subject) { DotGrid::Page::HorizontalRule.new({pdf: pdf})}
16
+ let(:pattern) { double('pattern') }
17
+
18
+ before do
19
+ allow(pdf).to receive(:start_new_page)
20
+ allow(subject).to receive(:pattern).and_return(pattern)
21
+ end
22
+
23
+ it "draws the pattern" do
24
+ expect(pattern).to receive(:draw)
25
+ subject.generate
26
+ end
27
+ end
28
+ end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "DotGrid::Planner" do
3
+ describe "DotGrid::Page::Planner" do
4
4
  describe "#initialize" do
5
- let(:subject) { DotGrid::Planner.new({}) }
5
+ let(:subject) { DotGrid::Page::Planner.new({}) }
6
6
 
7
7
  it "has a default planner color 1" do
8
8
  expect(subject.planner_color_1).to eq("CCCCCC")
@@ -15,37 +15,37 @@ describe "DotGrid::Planner" do
15
15
 
16
16
  describe "#header_height" do
17
17
  let(:pdf) { double('pdf') }
18
- let(:subject) { DotGrid::Planner.new({:pdf => pdf }) }
18
+ let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
19
19
 
20
20
  it "returns the HEADER_HEIGHT of the header height" do
21
21
  allow(subject).to receive(:page_height).and_return(20)
22
- expect(subject.header_height).to eq(DotGrid::Planner::HEADER_HEIGHT * subject.page_height)
22
+ expect(subject.header_height).to eq(DotGrid::Page::Planner::HEADER_HEIGHT * subject.page_height)
23
23
  end
24
24
  end
25
25
 
26
26
  describe "#header_height" do
27
27
  let(:pdf) { double('pdf') }
28
- let(:subject) { DotGrid::Planner.new({:pdf => pdf }) }
28
+ let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
29
29
 
30
30
  it "returns the HEADER_HEIGHT of the header height" do
31
31
  allow(subject).to receive(:page_height).and_return(20)
32
- expect(subject.header_height).to eq(DotGrid::Planner::HEADER_HEIGHT * subject.page_height)
32
+ expect(subject.header_height).to eq(DotGrid::Page::Planner::HEADER_HEIGHT * subject.page_height)
33
33
  end
34
34
  end
35
35
 
36
36
  describe "#square_grid_columns" do
37
37
  let(:pdf) { double('pdf') }
38
- let(:subject) { DotGrid::Planner.new({:pdf => pdf, spacing: 5 }) }
38
+ let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf, spacing: 5 }) }
39
39
 
40
40
  it "returns the HEADER_HEIGHT of the header height" do
41
41
  allow(subject).to receive(:page_width).and_return(100)
42
- expect(subject.square_grid_columns).to eq((DotGrid::Planner::SQUARE_GRID_WIDTH * subject.page_width / subject.spacing).floor)
42
+ expect(subject.square_grid_columns).to eq((DotGrid::Page::Planner::SQUARE_GRID_WIDTH * subject.page_width / subject.spacing).floor)
43
43
  end
44
44
  end
45
45
 
46
46
  describe "#header_left_color" do
47
47
  let(:pdf) { double('pdf') }
48
- let(:subject) { DotGrid::Planner.new({:pdf => pdf, planner_color_1: "DDEEFF" }) }
48
+ let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf, planner_color_1: "DDEEFF" }) }
49
49
  it "returns the planner color 1" do
50
50
  expect(subject.header_left_color).to eq("DDEEFF")
51
51
  end
@@ -53,27 +53,27 @@ describe "DotGrid::Planner" do
53
53
 
54
54
  describe "#header_left_start" do
55
55
  let(:pdf) { double('pdf') }
56
- let(:subject) { DotGrid::Planner.new({:pdf => pdf }) }
56
+ let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
57
57
 
58
58
  it "returns the the header left_start" do
59
59
  allow(subject).to receive(:page_width).and_return(30)
60
- expect(subject.header_left_start).to eq(DotGrid::Planner::HEADER_LEFT_START * subject.page_width)
60
+ expect(subject.header_left_start).to eq(DotGrid::Page::Planner::HEADER_LEFT_START * subject.page_width)
61
61
  end
62
62
  end
63
63
 
64
64
  describe "#header_gap_width" do
65
65
  let(:pdf) { double('pdf') }
66
- let(:subject) { DotGrid::Planner.new({:pdf => pdf }) }
66
+ let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
67
67
 
68
68
  it "returns the the header gap width" do
69
69
  allow(subject).to receive(:page_width).and_return(30)
70
- expect(subject.header_gap_width).to eq(DotGrid::Planner::HEADER_GAP_WIDTH * subject.page_width)
70
+ expect(subject.header_gap_width).to eq(DotGrid::Page::Planner::HEADER_GAP_WIDTH * subject.page_width)
71
71
  end
72
72
  end
73
73
 
74
74
  describe "#header_right_color" do
75
75
  let(:pdf) { double('pdf') }
76
- let(:subject) { DotGrid::Planner.new({:pdf => pdf, planner_color_2: "FFEEDD" }) }
76
+ let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf, planner_color_2: "FFEEDD" }) }
77
77
  it "returns the planner color 1" do
78
78
  expect(subject.header_right_color).to eq("FFEEDD")
79
79
  end
@@ -81,7 +81,7 @@ describe "DotGrid::Planner" do
81
81
 
82
82
  describe "#dot_grid_rows" do
83
83
  let(:pdf) { double('pdf') }
84
- let(:subject) { DotGrid::Planner.new({:pdf => pdf }) }
84
+ let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
85
85
  let(:square_grid_rows) { 10 }
86
86
 
87
87
  it "returns the foot height" do
@@ -92,18 +92,18 @@ describe "DotGrid::Planner" do
92
92
 
93
93
  describe "#footer_height" do
94
94
  let(:pdf) { double('pdf') }
95
- let(:subject) { DotGrid::Planner.new({:pdf => pdf }) }
95
+ let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
96
96
  let(:header_height) { 100 }
97
97
 
98
98
  it "returns the foot height" do
99
99
  allow(subject).to receive(:header_height).and_return(header_height)
100
- expect(subject.footer_height).to eq(header_height*DotGrid::Planner::FOOT_HEIGHT_RATIO)
100
+ expect(subject.footer_height).to eq(header_height*DotGrid::Page::Planner::FOOT_HEIGHT_RATIO)
101
101
  end
102
102
  end
103
103
 
104
104
  describe "#generate" do
105
105
  let(:pdf) { double('pdf') }
106
- let(:subject) { DotGrid::Planner.new({:pdf => pdf }) }
106
+ let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
107
107
 
108
108
  before do
109
109
  allow(subject).to receive(:page_width).and_return(10)
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe "DotGrid::Pattern::Checkerboard" do
4
+ let(:pdf) { double('pdf') }
5
+ let(:params) { { pdf: pdf, bounds: double('bounds', { height: 20.mm, width: 10.mm } ), spacing: 5 } }
6
+ let(:subject) { DotGrid::Pattern::Checkerboard.new(params) }
7
+
8
+ describe "#rows" do
9
+ it "calculates the rows based on the bounds" do
10
+ expect(subject.rows).to eq(4)
11
+ end
12
+ end
13
+
14
+ describe "#columns" do
15
+ it "calculates the rows based on the bounds" do
16
+ expect(subject.columns).to eq(2)
17
+ end
18
+ end
19
+
20
+ describe "#draw" do
21
+ before do
22
+ allow(pdf).to receive(:fill_color)
23
+ allow(pdf).to receive(:fill_rectangle)
24
+ end
25
+
26
+ it "sets the fill color" do
27
+ expect(pdf).to receive(:fill_color)
28
+ subject.draw
29
+ end
30
+
31
+ it "calls fill rectangle the correct number of times" do
32
+ allow(subject).to receive(:rows).and_return(2)
33
+ allow(subject).to receive(:columns).and_return(3)
34
+ expect(pdf).to receive(:fill_rectangle).exactly(3*4 / 2).times
35
+ subject.draw
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe "DotGrid::Pattern::DotGrid" do
4
+ describe "#draw" do
5
+ let(:pdf) { double('pdf') }
6
+ let(:params) { { pdf: pdf, bounds: double('bounds', { height: 20.mm, width: 10.mm } ), spacing: 5 } }
7
+ let(:subject) { DotGrid::Pattern::DotGrid.new(params) }
8
+
9
+ before do
10
+ allow(pdf).to receive(:fill_color)
11
+ allow(pdf).to receive(:fill_circle)
12
+ end
13
+
14
+ it "sets the fill color" do
15
+ expect(pdf).to receive(:fill_color)
16
+ subject.draw
17
+ end
18
+
19
+ it "calls fill circle the correct number of times" do
20
+ allow(subject).to receive(:rows).and_return(2)
21
+ allow(subject).to receive(:columns).and_return(3)
22
+ expect(pdf).to receive(:fill_circle).exactly(3*4).times
23
+ subject.draw
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "DotGrid::Pattern::Grid" do
4
+ describe "#draw" do
5
+ let(:pdf) { double('pdf') }
6
+ let(:params) { { pdf: pdf, bounds: double('bounds', { height: 20.mm, width: 10.mm } ), spacing: 5 } }
7
+ let(:subject) { DotGrid::Pattern::Grid.new(params) }
8
+
9
+ before do
10
+ allow(pdf).to receive(:stroke_color)
11
+ allow(pdf).to receive(:stroke_horizontal_line)
12
+ allow(pdf).to receive(:stroke_vertical_line)
13
+ end
14
+
15
+ it "sets the fill color" do
16
+ expect(pdf).to receive(:stroke_color)
17
+ subject.draw
18
+ end
19
+
20
+ it "draws teh horizontal lines" do
21
+ allow(subject).to receive(:rows).and_return(2)
22
+ expect(pdf).to receive(:stroke_horizontal_line).exactly(3).times
23
+ subject.draw
24
+ end
25
+
26
+ it "calls fill rectangle the correct number of times" do
27
+ allow(subject).to receive(:columns).and_return(3)
28
+ expect(pdf).to receive(:stroke_vertical_line).exactly(4).times
29
+ subject.draw
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe "DotGrid::Pattern::HorizontalRule" do
4
+
5
+ describe "#draw" do
6
+ let(:pdf) { double('pdf') }
7
+ let(:params) { { pdf: pdf, bounds: double('bounds', { height: 20.mm, width: 10.mm } ), spacing: 5 } }
8
+ let(:subject) { DotGrid::Pattern::HorizontalRule.new(params) }
9
+
10
+ before do
11
+ allow(pdf).to receive(:stroke_color)
12
+ allow(pdf).to receive(:stroke_horizontal_line)
13
+ end
14
+
15
+ it "sets the fill color" do
16
+ expect(pdf).to receive(:stroke_color)
17
+ subject.draw
18
+ end
19
+
20
+ it "calls horizontal line the correct number of times" do
21
+ allow(subject).to receive(:rows).and_return(2)
22
+ expect(pdf).to receive(:stroke_horizontal_line).exactly(2 + 1).times
23
+ subject.draw
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe "DotGrid::Pattern::Pattern" do
4
+
5
+ let(:pdf) { double('pdf') }
6
+ let(:params) { { pdf: pdf, bounds: double('bounds', { height: 20.mm, width: 10.mm } ), spacing: 5 } }
7
+ let(:subject) { DotGrid::Pattern::Pattern.new(params) }
8
+
9
+ describe "#new" do
10
+ it "calls the post initialize method" do
11
+ expect_any_instance_of(DotGrid::Pattern::Pattern).to receive(:post_initialize)
12
+ DotGrid::Pattern::Pattern.new(params)
13
+ end
14
+ end
15
+
16
+ describe "#post_initialize" do
17
+ it "is nil" do
18
+ expect(subject.post_initialize({})).to be_nil
19
+ end
20
+ end
21
+
22
+ describe "#rows" do
23
+ it "calculates the rows based on the bounds" do
24
+ expect(subject.rows).to eq(4)
25
+ end
26
+ end
27
+
28
+ describe "#columns" do
29
+ it "calculates the rows based on the bounds" do
30
+ expect(subject.columns).to eq(2)
31
+ end
32
+ end
33
+
34
+ describe "#draw" do
35
+ it "raises an error" do
36
+ expect { subject.draw }.to raise_error
37
+ end
38
+ end
39
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'coveralls'
2
2
  Coveralls.wear!
3
3
 
4
- require File.expand_path('../../lib/dot_grid', __FILE__)
4
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '../lib')
5
+ require 'dot_grid'
5
6
 
6
7
  RSpec.configure do |c|
7
8
  # May need some code in here ...
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dot_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott LaBounty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-07 00:00:00.000000000 Z
11
+ date: 2014-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -116,14 +116,29 @@ files:
116
116
  - dot_grid.gemspec
117
117
  - lib/dot_grid.rb
118
118
  - lib/dot_grid/generator.rb
119
- - lib/dot_grid/grid.rb
120
- - lib/dot_grid/page.rb
121
- - lib/dot_grid/planner.rb
119
+ - lib/dot_grid/page/checkerboard.rb
120
+ - lib/dot_grid/page/dot_grid.rb
121
+ - lib/dot_grid/page/grid.rb
122
+ - lib/dot_grid/page/horizontal_rule.rb
123
+ - lib/dot_grid/page/page.rb
124
+ - lib/dot_grid/page/planner.rb
125
+ - lib/dot_grid/pattern/checkerboard.rb
126
+ - lib/dot_grid/pattern/dot_grid.rb
127
+ - lib/dot_grid/pattern/grid.rb
128
+ - lib/dot_grid/pattern/horizontal_rule.rb
129
+ - lib/dot_grid/pattern/pattern.rb
122
130
  - lib/dot_grid/version.rb
123
131
  - spec/lib/dot_grid/generator_spec.rb
124
- - spec/lib/dot_grid/grid_spec.rb
125
- - spec/lib/dot_grid/page_spec.rb
126
- - spec/lib/dot_grid/planner_spec.rb
132
+ - spec/lib/dot_grid/page/checkerboard_spec.rb
133
+ - spec/lib/dot_grid/page/dot_grid_spec.rb
134
+ - spec/lib/dot_grid/page/grid_spec.rb
135
+ - spec/lib/dot_grid/page/horizontal_rule_spec.rb
136
+ - spec/lib/dot_grid/page/planner_spec.rb
137
+ - spec/lib/dot_grid/pattern/checkerboard_spec.rb
138
+ - spec/lib/dot_grid/pattern/dot_grid_spec.rb
139
+ - spec/lib/dot_grid/pattern/grid_spec.rb
140
+ - spec/lib/dot_grid/pattern/horizontal_rule_spec.rb
141
+ - spec/lib/dot_grid/pattern/pattern_spec.rb
127
142
  - spec/spec_helper.rb
128
143
  homepage: http://github.com/slabounty/dot_grid
129
144
  licenses:
@@ -151,7 +166,14 @@ specification_version: 4
151
166
  summary: Dot Grid planner PDF generator.
152
167
  test_files:
153
168
  - spec/lib/dot_grid/generator_spec.rb
154
- - spec/lib/dot_grid/grid_spec.rb
155
- - spec/lib/dot_grid/page_spec.rb
156
- - spec/lib/dot_grid/planner_spec.rb
169
+ - spec/lib/dot_grid/page/checkerboard_spec.rb
170
+ - spec/lib/dot_grid/page/dot_grid_spec.rb
171
+ - spec/lib/dot_grid/page/grid_spec.rb
172
+ - spec/lib/dot_grid/page/horizontal_rule_spec.rb
173
+ - spec/lib/dot_grid/page/planner_spec.rb
174
+ - spec/lib/dot_grid/pattern/checkerboard_spec.rb
175
+ - spec/lib/dot_grid/pattern/dot_grid_spec.rb
176
+ - spec/lib/dot_grid/pattern/grid_spec.rb
177
+ - spec/lib/dot_grid/pattern/horizontal_rule_spec.rb
178
+ - spec/lib/dot_grid/pattern/pattern_spec.rb
157
179
  - spec/spec_helper.rb
data/lib/dot_grid/grid.rb DELETED
@@ -1,29 +0,0 @@
1
- module DotGrid
2
- class Grid < Page
3
- attr_accessor(
4
- :dot_weight,
5
- :grid_color,
6
- :spacing,
7
- )
8
-
9
- def initialize(params)
10
- super
11
- end
12
-
13
-
14
- def page_rows
15
- (page_height / spacing).floor
16
- end
17
-
18
- def page_columns
19
- (page_width / spacing).floor
20
- end
21
-
22
- def generate
23
- pdf.start_new_page
24
- num_columns = page_columns
25
- num_rows = page_rows
26
- draw_dot_grid(num_rows, num_columns, 0, pdf.bounds.height)
27
- end
28
- end
29
- end
data/lib/dot_grid/page.rb DELETED
@@ -1,34 +0,0 @@
1
- module DotGrid
2
- class Page
3
- attr_accessor(
4
- :pdf,
5
- :dot_weight,
6
- :grid_color,
7
- :spacing
8
- )
9
-
10
- def initialize(params)
11
- @pdf = params[:pdf]
12
- @dot_weight = params[:dot_weight] || 1.5
13
- @grid_color = params[:grid_color] || "B3B3B3"
14
- @spacing = params[:spacing] ? params[:spacing].mm : 5.mm
15
- end
16
-
17
- def page_width
18
- pdf.bounds.width
19
- end
20
-
21
- def page_height
22
- pdf.bounds.height
23
- end
24
-
25
- def draw_dot_grid(rows, columns, left_start, height_start)
26
- pdf.fill_color grid_color
27
- (1..rows).each do |row|
28
- (1..columns).each do |col|
29
- pdf.fill_circle [left_start + (col-1)*spacing, height_start - spacing - (row-1)*spacing], dot_weight
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,116 +0,0 @@
1
- module DotGrid
2
- class Planner < Page
3
- attr_accessor(
4
- :planner_color_1,
5
- :planner_color_2
6
- )
7
-
8
- HEADER_HEIGHT = 0.05 # 5.0 %
9
- HEADER_LEFT_START = 0.05 # 5.0%
10
- SQUARE_GRID_WIDTH = 0.30 # 30.0%
11
- HEADER_GAP_WIDTH = 0.03 # 3.0%
12
- DOT_GRID_COLUMN_WIDTH = 0.62 # 62%
13
- SQUARE_GRID_ROWS_WIDTH = 0.80 # 80%
14
- FOOT_HEIGHT_RATIO = 2 # Ratio of footer to header
15
-
16
- def initialize(params)
17
- super
18
- @planner_color_1 = params[:planner_color_1] || "CCCCCC"
19
- @planner_color_2 = params[:planner_color_2] || "0099ff"
20
- end
21
-
22
- def header_height
23
- HEADER_HEIGHT * page_height
24
- end
25
-
26
- def square_grid_columns
27
- ((SQUARE_GRID_WIDTH * page_width) / spacing).floor
28
- end
29
-
30
- def header_left_color
31
- planner_color_1
32
- end
33
-
34
- def header_left_start
35
- HEADER_LEFT_START * page_width
36
- end
37
-
38
- def header_left_width
39
- square_grid_columns*spacing
40
- end
41
-
42
- def header_gap_start
43
- header_left_start + header_left_width
44
- end
45
-
46
- def header_gap_width
47
- page_width * HEADER_GAP_WIDTH
48
- end
49
-
50
- def dot_grid_columns
51
- (page_width * DOT_GRID_COLUMN_WIDTH / spacing).floor + 2
52
- end
53
-
54
- def dot_grid_rows
55
- square_grid_rows + 1
56
- end
57
-
58
- def header_right_color
59
- planner_color_2
60
- end
61
-
62
- def header_right_start
63
- header_gap_start + header_gap_width
64
- end
65
-
66
- def header_right_width
67
- page_width - header_right_start
68
- end
69
-
70
- def square_grid_rows
71
- (page_height * SQUARE_GRID_ROWS_WIDTH / spacing).floor
72
- end
73
-
74
- def footer_height
75
- header_height * FOOT_HEIGHT_RATIO
76
- end
77
-
78
- def generate
79
- pdf.start_new_page
80
-
81
- # Header left
82
- draw_header(header_left_start, header_left_width, header_height, header_left_color)
83
-
84
- # Header right
85
- draw_header(header_right_start, header_right_width, header_height, header_right_color)
86
-
87
- # Square Grid Left
88
- draw_square_grid_left(square_grid_rows, square_grid_columns, header_left_color, header_left_start, page_height - header_height - spacing, spacing)
89
-
90
- # Dot Grid Right
91
- draw_dot_grid(dot_grid_rows, dot_grid_columns, header_right_start, page_height-header_height)
92
-
93
- # Footer
94
- draw_footer(planner_color_1, header_left_start, footer_height, page_width-header_left_start)
95
- end
96
-
97
- def draw_header(header_start, header_width, header_height, header_color)
98
- pdf.fill_color header_color
99
- pdf.fill_rectangle [header_start, page_height], header_width, header_height
100
- end
101
-
102
- def draw_square_grid_left(square_grid_rows, square_grid_columns, grid_color, left_start, height_start, spacing)
103
- pdf.fill_color grid_color
104
- (1..square_grid_rows).each do |row|
105
- (1..square_grid_columns).each do |col|
106
- pdf.fill_rectangle [left_start + (col-1)*spacing, height_start - (row-1)*spacing], spacing-1 ,spacing-1
107
- end
108
- end
109
- end
110
-
111
- def draw_footer(footer_color, footer_start, footer_height, footer_width)
112
- pdf.fill_color footer_color
113
- pdf.fill_rectangle [footer_start, footer_height], footer_width, footer_height
114
- end
115
- end
116
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "DotGrid::Grid" do
4
- describe "#initialize" do
5
- let(:subject) { DotGrid::Grid.new({}) }
6
-
7
- it "calculates the number of rows" do
8
- allow(subject).to receive(:page_height).and_return(22)
9
- allow(subject).to receive(:spacing).and_return(5)
10
- expect(subject.page_rows).to eq(4)
11
- end
12
-
13
- it "calculates the number of columns" do
14
- allow(subject).to receive(:page_width).and_return(44)
15
- allow(subject).to receive(:spacing).and_return(6)
16
- expect(subject.page_columns).to eq(7)
17
- end
18
- end
19
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "DotGrid::Page" do
4
- describe "#initialize" do
5
- let(:subject) { DotGrid::Page.new({}) }
6
-
7
- it "has a default dot weight" do
8
- expect(subject.dot_weight).to eq(1.5)
9
- end
10
-
11
- it "has a default grid color" do
12
- expect(subject.grid_color).to eq("B3B3B3")
13
- end
14
-
15
- it "has a default spacing" do
16
- expect(subject.spacing).to eq(5.mm)
17
- end
18
- end
19
-
20
- describe "#page_width" do
21
- let(:pdf) { double('pdf', bounds: double(:width => 42)) }
22
- let(:subject) { DotGrid::Page.new({:pdf => pdf}) }
23
-
24
- it "uses the pdf to calculate the page width" do
25
- expect(subject.page_width).to eq(42)
26
- end
27
- end
28
-
29
- describe "#page_height" do
30
- let(:pdf) { double('pdf', bounds: double(:height => 22)) }
31
- let(:subject) { DotGrid::Page.new({:pdf => pdf}) }
32
-
33
- it "uses the pdf to calculate the page height" do
34
- expect(subject.page_height).to eq(22)
35
- end
36
- end
37
-
38
- describe "#draw_dot_grid" do
39
- let(:pdf) { double('pdf', bounds: double(:height => 22)) }
40
- let(:subject) { DotGrid::Page.new({:pdf => pdf, :grid_color => "CCDDEE"}) }
41
-
42
- it "sets the pdf fill color" do
43
- allow(pdf).to receive(:fill_circle)
44
- expect(pdf).to receive(:fill_color).with("CCDDEE")
45
- subject.draw_dot_grid(1, 1, 100, 200)
46
- end
47
-
48
- it "fills the correct number of circles for the grid" do
49
- allow(pdf).to receive(:fill_color)
50
- expect(pdf).to receive(:fill_circle).exactly(4).times
51
- subject.draw_dot_grid(2, 2, 100, 200)
52
- end
53
- end
54
- end