teaching_printables 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c13573faaf877bc3eafb60b606499249f6f08c2
4
+ data.tar.gz: cecc09049bf1f752e6bee99f9ce6fa24847f62c8
5
+ SHA512:
6
+ metadata.gz: cdfe6cf64b825021197c2b585e254adef1c16804e4bc6258725b068e0fb4760aa2151376e600112b6b239ccb1df53dfb500ae0ccf5bde9d2ce79700da7a73cb5
7
+ data.tar.gz: 7e81ab0c5098015a06b7f20e2c9e0e1811f52f246c8b1a8adf2ea6987f3465ce26d771c12eaa2e53022b42a8ac36e87c8eac3bb6ecfc74ff9969ee75643d29c4
data/lib/grid_sheet.rb ADDED
File without changes
@@ -0,0 +1,114 @@
1
+ require 'prawn'
2
+ require 'prawn/measurement_extensions'
3
+
4
+ def ind2sub(siz,ind)
5
+ if !siz || !ind || !siz.is_a?(Array) || siz.count!=2 || !ind.is_a?(Integer) || ind >= siz[0]*siz[1]
6
+ raise ArgumentError
7
+ end
8
+
9
+ return [ind%siz[0],ind/siz[0]]
10
+ end
11
+
12
+ GRAPHIC_EXTENSIONS = [".jpg",".JPG",".png",".jpeg"]
13
+ def is_image_file?(filename)
14
+ !filename.start_with?(".") && GRAPHIC_EXTENSIONS.include?(File.extname(filename))
15
+ end
16
+
17
+ COMPULABEL = {
18
+ :page_layout => :portrait,
19
+ :page_size => "LETTER",
20
+ :top_margin => 0.25.in,
21
+ :bottom_margin => 0.25.in,
22
+ :right_margin => 0.in,
23
+ :left_margin => 0.in,
24
+ :columns => 3,
25
+ :rows => 7,
26
+ :gutter => 10,
27
+ :column_width => 2.81.in,
28
+ :row_height => 1.5.in
29
+ }
30
+
31
+ AVERY5371 = {
32
+ :page_layout => :portrait,
33
+ :page_size => "LETTER",
34
+ :top_margin => 0.5.in,
35
+ :bottom_margin => 0.5.in,
36
+ :right_margin => 0.75.in,
37
+ :left_margin => 0.75.in,
38
+ :columns => 2,
39
+ :rows => 5,
40
+ :gutter => 0,
41
+ :column_width => 3.5.in,
42
+ :row_height => 2.in
43
+ }
44
+
45
+
46
+ class GridSheet
47
+ include Prawn::View
48
+
49
+ GRID_OPTIONS_DEFAULT = {
50
+ columns: 2,
51
+ rows: 2,
52
+ gutter: 0,
53
+ column_width: 100,
54
+ row_height: 100
55
+ }
56
+
57
+ def initialize(args={})
58
+ @document = Prawn::Document.new(args)
59
+ @font_size = 60
60
+ update_grid_options(args)
61
+ end
62
+
63
+ def update_grid_options(options)
64
+ GRID_OPTIONS_DEFAULT.each do |k,v|
65
+ instance_variable_set("@#{k}", options[k]) unless options[k].nil?
66
+ end
67
+ end
68
+
69
+ def make_grid(content_array)
70
+ puts grid_options
71
+ @document.define_grid(grid_options)
72
+ content_array.each_with_index {|obj,ind|
73
+
74
+ if ind > 0 && ind%10==0
75
+ @document.start_new_page
76
+ end
77
+
78
+ subs = ind2sub([@rows,@columns],ind%10)
79
+ @document.grid(subs[0],subs[1]).bounding_box do
80
+ #place_contents_in_gridbox(obj)
81
+ @document.text_box obj.to_s, align: :center, valign: :center, size: @font_size, overflow: :shrink_to_fit
82
+ end
83
+ }
84
+ end
85
+ def place_contents_in_gridbox(obj)
86
+ text obj.to_s, fit: [@column_width,@row_height]
87
+ end
88
+
89
+ private
90
+ def grid_options
91
+ keys = GRID_OPTIONS_DEFAULT.keys
92
+ Hash[keys.map { |key| [key.to_sym, instance_variable_get("@#{key}")] } ]
93
+ end
94
+
95
+ end
96
+
97
+ class PictureGridSheet < GridSheet
98
+ def place_contents_in_gridbox(picture_filename)
99
+ image picture_filename, fit: [@column_width,@row_height]
100
+ end
101
+ end
102
+
103
+
104
+ def test_grid_sheet
105
+ gs = GridSheet.new(AVERY5371)
106
+ 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 ]
107
+ gs.make_grid(content)
108
+ gs.save_as("mygrid.pdf")
109
+ gs
110
+ end
111
+
112
+
113
+
114
+
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: teaching_printables
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jen Dobson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prawn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: prawn-svg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A gem to create printable sheets for teaching
42
+ email: jendobson@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/grid_sheet.rb
48
+ - lib/teaching_printables.rb
49
+ homepage: ''
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.5.1
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Create Printable Sheets for Teaching
73
+ test_files: []