teaching_printables 0.0.1 → 0.0.2

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
2
  SHA1:
3
- metadata.gz: 2a91589527790eb2f14edb1f075363c4fea6d5ac
4
- data.tar.gz: e3816888c4b37ec71f00b542a39c5135222988d3
3
+ metadata.gz: 18b9c13fb7a7531d522c6e060d9174c543ed4a9c
4
+ data.tar.gz: 0f0cfbf2f224a1ef4e2a0af1a94bc0a145c92f81
5
5
  SHA512:
6
- metadata.gz: 1cca5307f42898442aa5bb2dd4feaacea8e0992acafc8a3e4d2ec6b035ace8fd4b641f27aff9c4b7ff0e05ca13d1a03a702500415d960f25b97e9539684f9bc8
7
- data.tar.gz: f5a49d0235f0c20fc05b57943abc707030ead36d0db56c6010a9a984eaa267e71c089857e16047611bd574bc75097f9b18699bd8bc8d049955feae1212ad0a0a
6
+ metadata.gz: a73ad00dc0b2b2d6da2fd8815c41d242063895779d1c572d182e4c8133a86f8867a41be8ee6a09747c1a37adb4a0efa7156a739bf71523d708f4d316b43e5675
7
+ data.tar.gz: 257f86b4e4e27995a0827c34d7b6b3789ae28f6e0c7c38a6e43b2375517b7ded564a7f136945b13e23980f2e0b5122e723340fea19a9a419559391f0f5c0f9cd
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -1,9 +1,15 @@
1
+ require "forwardable"
2
+
1
3
  require_relative "../utilities"
2
4
 
3
5
  module TeachingPrintables
4
6
  class GridSheet
7
+ extend Forwardable
5
8
  include Prawn::View
6
9
 
10
+ attr_reader :rows, :columns, :gutter, :column_width, :row_height
11
+
12
+
7
13
  GRID_OPTIONS_DEFAULT = {
8
14
  columns: 2,
9
15
  rows: 2,
@@ -11,29 +17,36 @@ module TeachingPrintables
11
17
  column_width: 100,
12
18
  row_height: 100
13
19
  }
14
-
15
- def initialize(args={})
16
- @document = Prawn::Document.new(args)
20
+
21
+ def initialize(args={},doc=nil)
22
+ if !doc
23
+ @document = Prawn::Document.new(args.merge({skip_page_creation: true }))
24
+ elsif doc.kind_of?(Prawn::Document)
25
+ @document = doc
26
+ else
27
+ raise ArgumentError, "Expecting Prawn::Document", caller
28
+ end
17
29
  @font_size = 60
18
- update_grid_options(args)
30
+ update_grid_options(GRID_OPTIONS_DEFAULT.merge(args))
19
31
  end
20
32
 
33
+ def_delegators :@document, :font_size, :page_number, :y, :grid
34
+
21
35
  def update_grid_options(options)
22
- GRID_OPTIONS_DEFAULT.each do |k,v|
36
+ options.each do |k,v|
23
37
  instance_variable_set("@#{k}", options[k]) unless options[k].nil?
24
38
  end
25
39
  end
26
40
 
27
- def make_grid(content_array)
28
- puts grid_options
41
+ def add_content(content_array)
29
42
  @document.define_grid(grid_options)
30
43
  content_array.each_with_index {|obj,ind|
31
44
 
32
- if ind > 0 && ind%10==0
45
+ if ind%(@rows*@columns)==0
33
46
  @document.start_new_page
34
47
  end
35
-
36
- subs = ind2sub([@rows,@columns],ind%10)
48
+
49
+ subs = ind2sub([@rows,@columns],ind%(@rows*@columns))
37
50
  @document.grid(subs[0],subs[1]).bounding_box do
38
51
  #place_contents_in_gridbox(obj)
39
52
  @document.text_box obj.to_s, align: :center, valign: :center, size: @font_size, overflow: :shrink_to_fit
@@ -0,0 +1,33 @@
1
+ module TeachingPrintables
2
+ module PrintTemplates
3
+
4
+ COMPULABEL = {
5
+ :page_layout => :portrait,
6
+ :page_size => "LETTER",
7
+ :top_margin => 0.25.in,
8
+ :bottom_margin => 0.25.in,
9
+ :right_margin => 0.in,
10
+ :left_margin => 0.in,
11
+ :columns => 3,
12
+ :rows => 7,
13
+ :gutter => 10,
14
+ :column_width => 2.81.in,
15
+ :row_height => 1.5.in
16
+ }
17
+
18
+ AVERY5371 = {
19
+ :page_layout => :portrait,
20
+ :page_size => "LETTER",
21
+ :top_margin => 0.5.in,
22
+ :bottom_margin => 0.5.in,
23
+ :right_margin => 0.75.in,
24
+ :left_margin => 0.75.in,
25
+ :columns => 2,
26
+ :rows => 5,
27
+ :gutter => 0,
28
+ :column_width => 3.5.in,
29
+ :row_height => 2.in
30
+ }
31
+ end
32
+ end
33
+
@@ -3,7 +3,7 @@ require 'prawn/measurement_extensions'
3
3
 
4
4
 
5
5
  require_relative "teaching_printables/grid_sheet/grid_sheet"
6
- require_relative "teaching_printables/printing/templates"
6
+ require_relative "teaching_printables/print_templates"
7
7
 
8
8
  module TeachingPrintables
9
9
  extend self
@@ -29,13 +29,7 @@ module TeachingPrintables
29
29
  end
30
30
 
31
31
 
32
- def test_grid_sheet
33
- gs = GridSheet.new(TeachingPrintables::Printing::Templates::AVERY5371)
34
- content = %W[crow mow low slow tow boat moat goat oat float feet seat treat beep speed need steep wait train rain paint way play day say bay hay stay lay may ]
35
- gs.make_grid(content)
36
- gs.save_as("mygrid.pdf")
37
- gs
38
- end
32
+
39
33
 
40
34
  def grid_sheet_with_content(content_array)
41
35
  gs = GridSheet.new(TeachingPrintables::Printing::Templates::AVERY5371)
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'teaching_printables'
3
+ s.version = '0.0.2'
4
+ s.executables << 'flashcards_AVERY5371'
5
+ s.add_runtime_dependency 'prawn', '~> 2'
6
+ s.add_runtime_dependency 'prawn-svg', '~> 0'
7
+ s.date = '2016-11-18'
8
+ s.summary = "Create Printable Sheets for Teaching"
9
+ s.description = "A gem to create printable sheets for teaching"
10
+ s.authors = ["Jen Dobson"]
11
+ s.email = 'jendobson@gmail.com'
12
+ s.files = Dir.glob("{bin,lib,test}/**/**/*") +
13
+ ["Rakefile", "teaching_printables.gemspec"]
14
+ s.homepage =
15
+ 'https://rubygems.org/gems/teaching_printables'
16
+ s.license = 'MIT'
17
+ end
@@ -0,0 +1,36 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+
4
+ require 'tmpdir'
5
+ require 'teaching_printables'
6
+
7
+
8
+ describe TeachingPrintables::GridSheet do
9
+ before do
10
+ @gs = TeachingPrintables::GridSheet.new
11
+ @content = (1..20).to_a.map{|i| i.to_s}
12
+
13
+ end
14
+
15
+ describe "after creating a new grid sheet" do
16
+ it "has the default grid options" do
17
+ assert_equal 2, @gs.rows
18
+ assert_equal 2, @gs.columns
19
+ end
20
+
21
+ it "can update the print template" do
22
+ @gs.update_grid_options(TeachingPrintables::PrintTemplates::AVERY5371)
23
+ assert_equal 5, @gs.rows
24
+ assert_equal 2, @gs.columns
25
+ end
26
+ it "can add content" do
27
+ @gs.add_content(@content)
28
+ assert_equal 5, @gs.page_number
29
+ end
30
+
31
+ it "saves as a pdf" do
32
+ @gs.save_as("mygrid.pdf")
33
+ assert File.exist?("mygrid.pdf")
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teaching_printables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jen Dobson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-15 00:00:00.000000000 Z
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -45,12 +45,15 @@ executables:
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - Rakefile
48
49
  - bin/flashcards_AVERY5371
49
50
  - lib/teaching_printables.rb
50
51
  - lib/teaching_printables/grid_sheet/grid_sheet.rb
51
- - lib/teaching_printables/printing/templates.rb
52
+ - lib/teaching_printables/print_templates.rb
52
53
  - lib/teaching_printables/utilities.rb
53
- homepage: ''
54
+ - teaching_printables.gemspec
55
+ - test/test_grid_sheet.rb
56
+ homepage: https://rubygems.org/gems/teaching_printables
54
57
  licenses:
55
58
  - MIT
56
59
  metadata: {}
@@ -1,34 +0,0 @@
1
- module TeachingPrintables
2
- module Printing
3
- module Templates
4
-
5
- COMPULABEL = {
6
- :page_layout => :portrait,
7
- :page_size => "LETTER",
8
- :top_margin => 0.25.in,
9
- :bottom_margin => 0.25.in,
10
- :right_margin => 0.in,
11
- :left_margin => 0.in,
12
- :columns => 3,
13
- :rows => 7,
14
- :gutter => 10,
15
- :column_width => 2.81.in,
16
- :row_height => 1.5.in
17
- }
18
-
19
- AVERY5371 = {
20
- :page_layout => :portrait,
21
- :page_size => "LETTER",
22
- :top_margin => 0.5.in,
23
- :bottom_margin => 0.5.in,
24
- :right_margin => 0.75.in,
25
- :left_margin => 0.75.in,
26
- :columns => 2,
27
- :rows => 5,
28
- :gutter => 0,
29
- :column_width => 3.5.in,
30
- :row_height => 2.in
31
- }
32
- end
33
- end
34
- end