dot_grid 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/dotgrid +2 -1
- data/lib/dot_grid/document.rb +41 -0
- data/lib/dot_grid/generator.rb +3 -21
- data/lib/dot_grid/version.rb +1 -1
- data/lib/dot_grid.rb +1 -0
- data/spec/lib/dot_grid/document_spec.rb +82 -0
- data/spec/lib/dot_grid/generator_spec.rb +3 -19
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41426df4e0810af83423a9c902f3fbe5d46acd8f
|
4
|
+
data.tar.gz: 2898d3c296d18abbfc5a906115d73b27084c108f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 295552084e91b9c011444955b965a6a2b69da3cb2899f7172c8398d79c7a93e46a81207afe9283e3c9f6be97337443805f57a83cee6f4fbcb88561c974925f8b
|
7
|
+
data.tar.gz: 0fb0d12fb33927560f5e974c266f9bbb41c79b41a3a026839a960a1c4edbc08d1c46b5e528ab8314bd38d3a203eba4097ef5e843cb9053b947a0cd3dc8e34a38
|
data/Gemfile.lock
CHANGED
data/bin/dotgrid
CHANGED
@@ -10,9 +10,10 @@ 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 :orientation, "Orientation of pages (portrait/landscape)", type: :string, default: "portrait"
|
13
14
|
opt :page_types, "Types of pages desired: Types of pages desired: DotGrid, Planner, Grid, HorizontalRule, Checkerboard", type: :string, default: "Planner"
|
14
15
|
opt :dot_weight, "Dot Weight", :type => :float, :default => 1.5
|
15
|
-
opt :margin, "Border", :type => :float, :default => 0.
|
16
|
+
opt :margin, "Border", :type => :float, :default => 0.0
|
16
17
|
opt :page_size, "Page Size (LEGAL, LETTER)", :type => :string, :default => "LETTER"
|
17
18
|
opt :grid_color, "Grid Color (RGB)", :type => :string, :default => "B3B3B3"
|
18
19
|
opt :spacing, "Dot Spacing (mm)", :type => :integer, :default => 5
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module DotGrid
|
2
|
+
class Document
|
3
|
+
attr_accessor(
|
4
|
+
:document,
|
5
|
+
:pdf,
|
6
|
+
:file_name,
|
7
|
+
:orientation,
|
8
|
+
:page_size,
|
9
|
+
:margin,
|
10
|
+
:pages,
|
11
|
+
:page_types
|
12
|
+
)
|
13
|
+
|
14
|
+
def initialize(params = {})
|
15
|
+
@file_name = params[:file_name] || "dotgrid.pdf"
|
16
|
+
@page_size = params[:page_size] ? parse_page_size(params[:page_size]) : "LETTER"
|
17
|
+
@orientation = params[:orientation] ? params[:orientation].downcase.to_sym : :portrait
|
18
|
+
@margin = params[:margin] || 0.0
|
19
|
+
@page_types = params[:page_types] ? params[:page_types].split(",") : ["planner"]
|
20
|
+
|
21
|
+
@pdf = Prawn::Document.new(margin: margin, page_size: page_size, skip_page_creation: true, page_layout: orientation)
|
22
|
+
@pages = create_pages(params.merge({pdf: pdf}))
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_page_size(page_size)
|
26
|
+
return page_size unless p = /(?'w'\d+\.{0,1}\d*)x(?'h'\d+\.{0,1}\d*)(?'u'[a-z]{2})/.match(page_size)
|
27
|
+
return [p[:w].to_f.send(p[:u]), p[:h].to_f.send(p[:u])]
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_pages(params)
|
31
|
+
page_types.map do |p|
|
32
|
+
DotGrid::Page::Factory.build(p.strip, params.clone)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate
|
37
|
+
pages.each { |page| page.generate }
|
38
|
+
pdf.render_file file_name
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/dot_grid/generator.rb
CHANGED
@@ -4,33 +4,15 @@ require "prawn/measurement_extensions"
|
|
4
4
|
module DotGrid
|
5
5
|
class Generator
|
6
6
|
attr_accessor(
|
7
|
-
:
|
8
|
-
:file_name,
|
9
|
-
:page_size,
|
10
|
-
:margin,
|
11
|
-
:pages,
|
12
|
-
:page_types
|
7
|
+
:document
|
13
8
|
)
|
14
9
|
|
15
10
|
def initialize(params)
|
16
|
-
@
|
17
|
-
@page_size = params[:page_size] || "LETTER"
|
18
|
-
@margin = params[:margin] || 0.5
|
19
|
-
@page_types = params[:page_types] ? params[:page_types].split(",") : ["planner"]
|
20
|
-
@pdf = Prawn::Document.new(margin: margin, page_size: page_size, skip_page_creation: true)
|
21
|
-
params[:pdf] = pdf
|
22
|
-
@pages = create_pages(params)
|
23
|
-
end
|
24
|
-
|
25
|
-
def create_pages(params)
|
26
|
-
page_types.map do |p|
|
27
|
-
DotGrid::Page::Factory.build(p.strip, params.clone)
|
28
|
-
end
|
11
|
+
@document = DotGrid::Document.new(params)
|
29
12
|
end
|
30
13
|
|
31
14
|
def generate
|
32
|
-
|
33
|
-
pdf.render_file file_name
|
15
|
+
document.generate
|
34
16
|
end
|
35
17
|
end
|
36
18
|
end
|
data/lib/dot_grid/version.rb
CHANGED
data/lib/dot_grid.rb
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "DotGrid::Document" do
|
4
|
+
describe "#initialize" do
|
5
|
+
let(:subject) { DotGrid::Document.new({}) }
|
6
|
+
|
7
|
+
it "has a default file name" do
|
8
|
+
expect(subject.file_name).to eq("dotgrid.pdf")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a default file page size" do
|
12
|
+
expect(subject.page_size).to eq("LETTER")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has a default file page orientation" do
|
16
|
+
expect(subject.orientation).to eq(:portrait)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a default file margin" do
|
20
|
+
expect(subject.margin).to eq(0.0)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "creates a pdf file" do
|
24
|
+
expect(subject.pdf).to be_a(Prawn::Document)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "creates the pages" do
|
28
|
+
expect(subject.page_types).to have(1).page
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#parse_page_size" do
|
33
|
+
context "when the page size doesn't match the regex" do
|
34
|
+
let(:subject) { DotGrid::Document.new({page_size: "LEGAL"}) }
|
35
|
+
|
36
|
+
it "returns the page_size as is" do
|
37
|
+
expect(subject.page_size).to eq("LEGAL")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when the page size matches the regex" do
|
42
|
+
let(:subject) { DotGrid::Document.new({page_size: "4x5in"}) }
|
43
|
+
|
44
|
+
it "returns the width and heigth in an array" do
|
45
|
+
expect(subject.page_size).to have(2).elements
|
46
|
+
end
|
47
|
+
|
48
|
+
it "translates the width to points" do
|
49
|
+
expect(subject.page_size[0]).to eq(4.in)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "translates the height to points" do
|
53
|
+
expect(subject.page_size[1]).to eq(5.in)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#create_pages" do
|
59
|
+
it "calls the factory for each page" do
|
60
|
+
expect(DotGrid::Page::Factory).to receive(:build).twice
|
61
|
+
DotGrid::Document.new({page_types: "a, b"})
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#generate" do
|
66
|
+
let(:subject) { DotGrid::Document.new({}) }
|
67
|
+
|
68
|
+
before do
|
69
|
+
allow(subject.pdf).to receive(:render_file)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "generates each of the pages" do
|
73
|
+
expect(subject.pages[0]).to receive(:generate)
|
74
|
+
subject.generate
|
75
|
+
end
|
76
|
+
|
77
|
+
it "renders the pdf" do
|
78
|
+
expect(subject.pdf).to receive(:render_file)
|
79
|
+
subject.generate
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -4,31 +4,15 @@ describe "DotGrid::Generator" do
|
|
4
4
|
describe "#initialize" do
|
5
5
|
let(:subject) { DotGrid::Generator.new({}) }
|
6
6
|
|
7
|
-
it "
|
8
|
-
expect(subject.
|
9
|
-
end
|
10
|
-
|
11
|
-
it "has a default file page size" do
|
12
|
-
expect(subject.page_size).to eq("LETTER")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "has a default file margin" do
|
16
|
-
expect(subject.margin).to eq(0.5)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "creates a pdf file" do
|
20
|
-
expect(subject.pdf).to be_a(Prawn::Document)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "creates the pages" do
|
24
|
-
expect(subject.page_types).to have(1).page
|
7
|
+
it "creates a new document" do
|
8
|
+
expect(subject.document).to_not be_nil
|
25
9
|
end
|
26
10
|
end
|
27
11
|
|
28
12
|
describe "#generate" do
|
29
13
|
it "renders a file with the file name" do
|
30
14
|
subject = DotGrid::Generator.new({})
|
31
|
-
expect(subject.
|
15
|
+
expect(subject.document).to receive(:generate)
|
32
16
|
subject.generate
|
33
17
|
end
|
34
18
|
end
|
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.
|
4
|
+
version: 0.0.7
|
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-07-
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- dot_grid.gemspec
|
117
117
|
- lib/dot_grid.rb
|
118
118
|
- lib/dot_grid/bounding_box.rb
|
119
|
+
- lib/dot_grid/document.rb
|
119
120
|
- lib/dot_grid/generator.rb
|
120
121
|
- lib/dot_grid/page/checkerboard.rb
|
121
122
|
- lib/dot_grid/page/dot_grid.rb
|
@@ -131,6 +132,7 @@ files:
|
|
131
132
|
- lib/dot_grid/pattern/pattern.rb
|
132
133
|
- lib/dot_grid/pattern/square_grid.rb
|
133
134
|
- lib/dot_grid/version.rb
|
135
|
+
- spec/lib/dot_grid/document_spec.rb
|
134
136
|
- spec/lib/dot_grid/generator_spec.rb
|
135
137
|
- spec/lib/dot_grid/page/checkerboard_spec.rb
|
136
138
|
- spec/lib/dot_grid/page/dot_grid_spec.rb
|
@@ -170,6 +172,7 @@ signing_key:
|
|
170
172
|
specification_version: 4
|
171
173
|
summary: Dot Grid planner PDF generator.
|
172
174
|
test_files:
|
175
|
+
- spec/lib/dot_grid/document_spec.rb
|
173
176
|
- spec/lib/dot_grid/generator_spec.rb
|
174
177
|
- spec/lib/dot_grid/page/checkerboard_spec.rb
|
175
178
|
- spec/lib/dot_grid/page/dot_grid_spec.rb
|