teaching_printables 0.0.3 → 0.0.4

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: 8e8cc77020eb961d443b4a55b7ee55957a595ccd
4
- data.tar.gz: 45e54de39a3445a49b6f3cd8b7143e088fa27ee6
3
+ metadata.gz: 917c84946f09309acdaf431d40d42794be9b5c29
4
+ data.tar.gz: 66cf3313c463a6cce11c5e19724e9664e398b154
5
5
  SHA512:
6
- metadata.gz: 97d554c065d4b76fbe75cc71127e79204111a4e986aa7032cf34395af2d8bc39cafda5874b665fe300076b7a62ba937f9a0e9f80f66b9198f6f078f5228930c2
7
- data.tar.gz: c6931e02bafd8a5bec5ca7feef2946a63cf35ace1608aba85257e3be15425e756c059f4b95fd3fe4e9b63fe2ff5a7bc66b7c93cb4c1cd91060591ef854cadb6b
6
+ metadata.gz: ed06053e013045c4b764d037c4b4a316130bf4ff2d69c29b7427617c6644629ce90d588e5681c40cd2c285aa2589975c80644ed6903a1ffcf26df5412f79b474
7
+ data.tar.gz: 54b68331bbd9945395de256ed6d7e2559a0195061abc6f7ae386f70e4cc5a8fae7101e4d524571648bcb715a8ba493d14f4bb50edcbf7a052417b20553389c46
data/Rakefile CHANGED
@@ -1,8 +1,10 @@
1
- require 'rake/testtask'
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
2
3
 
3
- Rake::TestTask.new do |t|
4
- t.libs << 'test'
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
5
8
  end
6
9
 
7
- desc "Run tests"
8
10
  task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "teaching_printables"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -3,4 +3,4 @@
3
3
  #Usage: ./bin/flashcards_AVERY5371 rug mug slug but cut tub sub hub mud up
4
4
  require 'teaching_printables'
5
5
 
6
- TeachingPrintables::grid_sheet_with_content(ARGV)
6
+ TeachingPrintables::Factory.avery5371_with_array_content(ARGV, "output.pdf")
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #Usage: ./bin/quad_ruled_paper <number_of_pages> <rule_size> <rule_unit>
4
+ #eg: ./bin/quad_ruled_paper 2 1 cm
5
+ # ./bin/quad_ruled_paper 2 18
6
+ # => rule_unit defaults to points
7
+
8
+ require 'teaching_printables'
9
+ require 'optparse'
10
+ require 'ostruct'
11
+
12
+ class Parser
13
+
14
+ def self.parse(args)
15
+
16
+ options = OpenStruct.new
17
+ options.rule_unit = ''
18
+
19
+ optparser = OptionParser.new do |opts|
20
+ opts.banner = "Usage: quad_ruled_paper <number_of_pages> <rule> <output_file> [options]"
21
+
22
+ opts.on("-uRULEUNIT", "--unit=RULEUNIT", "Rule Unit") do |r|
23
+ options.rule_unit = r
24
+ end
25
+
26
+ end
27
+ optparser.parse!(args)
28
+ options
29
+ end
30
+
31
+ end # class Parser
32
+
33
+
34
+ options = Parser.parse(ARGV)
35
+
36
+ TeachingPrintables::Factory.quad_ruled_paper(ARGV[0],ARGV[1],options.rule_unit,ARGV[3])
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,71 @@
1
+ #require_relative "./templatable"
2
+
3
+ module TeachingPrintables
4
+ # Rubber stamps common worksheets
5
+ module Factory
6
+ def Factory.avery5371_with_array_content(content_array,output_file_name="output.pdf")
7
+ doc = TeachingPrintables::TPDocument.new
8
+ class << doc
9
+ include TeachingPrintables::Templatable
10
+ end
11
+ doc.create_page_with_template(:avery5371)
12
+ doc.add_grid_content(content_array)
13
+ doc.save_as(output_file_name)
14
+ puts "Sheet saved as #{output_file_name}."
15
+ end
16
+
17
+ def Factory.centimeter_paper
18
+ doc = TeachingPrintables::TPDocument.new
19
+ class << doc
20
+ include QuadRulable
21
+ end
22
+ 2.times do |i|
23
+ doc.create_quad_rule(start_new_page: true)
24
+ end
25
+ doc.save_as(output_file_name)
26
+ end
27
+
28
+ def Factory.quad_ruled_paper(npages,rule_value,rule_unit='',filename='output.pdf')
29
+ npages = npages.to_i
30
+ rule = rule_unit.empty? ? rule_value.to_f : rule_value.to_f.send(rule_unit)
31
+
32
+ if !filename || filename.empty?
33
+ filename = 'output.pdf'
34
+ end
35
+
36
+ doc = TeachingPrintables::TPDocument.new
37
+ class << doc
38
+ include QuadRulable
39
+ end
40
+ npages.times do |i|
41
+ doc.create_quad_rule(rule_unit: rule, start_new_page: true)
42
+ end
43
+ doc.save_as(filename)
44
+ end
45
+
46
+
47
+ def Factory.hundreds_grid(output_file_name="output.pdf")
48
+ qr=TeachingPrintables::TPDocument.new
49
+ class << qr
50
+ include QuadRulable
51
+ end
52
+ 2.times do |i|
53
+ qr.create_quad_rule(start_new_page: true)
54
+ qr.line_width = 4
55
+ qr.stroke_rectangle [1.cm,11.cm], 10.cm, 10.cm
56
+ qr.stroke_line [6.cm,11.cm], [6.cm,21.cm]
57
+ qr.stroke_rectangle [1.cm,22.cm], 10.cm, 10.cm
58
+ qr.stroke_line [6.cm,21.cm], [6.cm,31.cm]
59
+ end
60
+ qr.save_as(output_file_name)
61
+ end
62
+
63
+
64
+ #
65
+ # def place_contents_in_gridbox(picture_filename)
66
+ # image picture_filename, fit: [@column_width,@row_height]
67
+ # end
68
+
69
+
70
+ end
71
+ end
@@ -0,0 +1,73 @@
1
+
2
+ require_relative "./utilities"
3
+
4
+ module TeachingPrintables
5
+ # Creates grid layouts for flashcards or math sheets. Delegates Prawn methods to Prawn::Document.
6
+
7
+ module Gridable
8
+
9
+
10
+
11
+ attr_writer :grid_rows, :grid_columns, :grid_gutter, :grid_column_width, :grid_row_height
12
+
13
+ def grid_rows
14
+ @grid_rows ||= 2
15
+ end
16
+ def grid_columns
17
+ @grid_coluns ||= 2
18
+ end
19
+ def grid_gutter
20
+ @grid_gutter ||= 0
21
+ end
22
+ def grid_column_width
23
+ @grid_column_width ||= 100
24
+ end
25
+ def grid_row_height
26
+ @grid_row_height ||= 100
27
+ end
28
+
29
+
30
+ def update_grid_options(options)
31
+ options.each do |k,v|
32
+ instance_variable_set("@grid_#{k}", options[k]) unless options[k].nil?
33
+ end
34
+ end
35
+
36
+ def add_grid_content(content_array, options={})
37
+
38
+ font_size = options[:font_size] || 60
39
+
40
+ if (page_number ==0) || (options[:start_new_page] == true)
41
+ start_new_page
42
+ end
43
+
44
+
45
+ @document.define_grid(grid_options)
46
+ content_array.each_with_index {|obj,ind|
47
+
48
+ if ind%(grid_rows*grid_columns)==0 && ind > 0
49
+ @document.start_new_page
50
+ end
51
+
52
+ subs = ind2sub([grid_rows,grid_columns],ind%(grid_rows*grid_columns))
53
+ @document.grid(subs[0],subs[1]).bounding_box do
54
+ #place_contents_in_gridbox(obj)
55
+ @document.text_box obj.to_s, align: :center, valign: :center, size: font_size, overflow: :shrink_to_fit
56
+ end
57
+ }
58
+ end
59
+
60
+
61
+
62
+ def place_contents_in_gridbox(obj)
63
+ text obj.to_s, fit: [grid_column_width,grid_row_height]
64
+ end
65
+
66
+ private
67
+ def grid_options
68
+ keys = %W[rows columns gutter column_width row_height]
69
+ Hash[keys.map { |key| [key.to_sym, self.send("grid_#{key}")] } ]
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,50 @@
1
+ require_relative "svg/svg_components"
2
+ require "prawn-svg"
3
+ module TeachingPrintables
4
+ # Creates quadrille rulings on paper. Delegates Prawn methods to Prawn::Document.
5
+
6
+ module QuadRulable
7
+ # Make quadrille rules
8
+
9
+ attr_accessor :rule_unit
10
+
11
+ def rule_unit
12
+ @rule_unit ||= 1.cm
13
+ end
14
+ def rule_height
15
+ bounds.top - bounds.bottom
16
+ end
17
+ def rule_width
18
+ bounds.right - bounds.left
19
+ end
20
+
21
+ def create_quad_rule(options={})
22
+ parse_options(options)
23
+ puts rule_unit
24
+ ncols = (rule_width.to_f/rule_unit).ceil
25
+ nrows = (rule_height.to_f/rule_unit).ceil
26
+
27
+
28
+ #Create svg grid with 10pxX10px unit square.
29
+ #str = SVGComponents::header(@width,@height)
30
+ str = SVGComponents::quad_ruled_grid(nrows,ncols)
31
+ #str << SVGComponents::footer
32
+
33
+ if (page_number ==0) || (options[:start_new_page] == true)
34
+ start_new_page
35
+ end
36
+
37
+ svg(str,width: ncols*rule_unit, height: nrows*rule_unit, at:[0,rule_height+1]) #position: :center, vposition: :center)
38
+
39
+ end
40
+
41
+ private
42
+ def parse_options(options)
43
+ allowed_parameters = [:rule_unit]
44
+ options.each do |k,v|
45
+ puts "@#{k.to_s}"
46
+ instance_variable_set("@#{k.to_s}",v) if allowed_parameters.include?(k)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,140 @@
1
+ class SVGComponents
2
+
3
+ SVG_VERSION = "1.1"
4
+
5
+ class << self
6
+ def header(width,height)
7
+ "<svg version=\"#{SVG_VERSION}\"
8
+ baseProfile=\"full\"
9
+ width=\"#{width.to_s}\" height=\"#{height.to_s}\"
10
+ xmlns=\"http://www.w3.org/2000/svg\">".gsub("\n",'')
11
+ end
12
+
13
+ # def line(x1,x2,y1,y2,stroke="black",stroke_width=1)
14
+ # "<line x1=\"#{x1.to_s}\" x2=\"#{x2.to_s}\" y1=\"#{y1.to_s}\" y2=\"#{y2.to_s}\" stroke=\"#{stroke}\" stroke-width=\"#{stroke_width.to_s}\"/>"
15
+ # end
16
+ DEFAULT_LINE = {
17
+ x1: 0,
18
+ x2: 100,
19
+ y1: 0,
20
+ y2: 100,
21
+ stroke: "black",
22
+ stroke_width: 1,
23
+ stroke_dasharray: "none"
24
+ }
25
+
26
+ def line(options={})
27
+ options = DEFAULT_LINE.merge(options)
28
+ "<line x1=\"#{options[:x1].to_s}\" x2=\"#{options[:x2].to_s}\" y1=\"#{options[:y1].to_s}\" y2=\"#{options[:y2].to_s}\" stroke=\"#{options[:stroke]}\" stroke-width=\"#{options[:stroke_width].to_s}\" stroke-dasharray=\"#{options[:stroke_dasharray]}\"/>"
29
+ end
30
+
31
+ DEFAULT_ARROW = {
32
+ xpos: 0,
33
+ ypos: 0,
34
+ base: 10,
35
+ height: 10,
36
+ fill: "black",
37
+ stroke: "black",
38
+ stroke_width: 1,
39
+ }
40
+
41
+ # Create left arrowhead with apex at xpos,ypos and specified base and height
42
+ def left_arrowhead(options={})
43
+ options = DEFAULT_ARROW.merge(options)
44
+ "<polygon points=\"#{options[:xpos]+options[:height]},#{options[:ypos]+options[:height]/2} #{options[:xpos]+options[:height]},#{options[:ypos]-options[:height]/2} #{options[:xpos]},#{options[:ypos]}\" style=\"fill:#{options[:fill]};stroke:#{options[:stroke]};stroke-width:#{options[:stroke_width].to_s}\"/>"
45
+ end
46
+
47
+ def right_arrowhead(options={})
48
+ options = DEFAULT_ARROW.merge(options)
49
+ "<polygon points=\"#{options[:xpos]-options[:height]},#{options[:ypos]+options[:height]/2} #{options[:xpos]-options[:height]},#{options[:ypos]-options[:height]/2} #{options[:xpos]},#{options[:ypos]}\" style=\"fill:#{options[:fill]};stroke:#{options[:stroke]};stroke-width:#{options[:stroke_width].to_s}\"/>"
50
+ end
51
+
52
+ DEFAULT_CIRCLE = {
53
+ xpos: 0,
54
+ ypos: 0,
55
+ radius: 2,
56
+ fill: "black",
57
+ stroke: "black",
58
+ stroke_width: 1,
59
+ }
60
+ def circle(options={})
61
+ options = DEFAULT_CIRCLE.merge(options)
62
+ "<circle cx=\"#{options[:xpos].to_s}\" cy=\"#{options[:ypos].to_s}\" r=\"#{options[:radius].to_s}\" stroke=\"#{options[:stroke]}\" stroke-width=\"#{options[:stroke_width].to_s}\" fill=\"#{options[:fill]}\" />"
63
+ end
64
+
65
+ DEFAULT_LABEL = {
66
+ xpos: 0,
67
+ ypos: 0,
68
+ text: "Label Text",
69
+ font_size: 12,
70
+ text_anchor: "middle",
71
+ fill: "black"
72
+ }
73
+ def label(options={})
74
+ "<text x=\"#{options[:xpos].to_s}\" y=\"#{options[:ypos].to_s}\" font-size=\"#{options[:font_size].to_s}\" text-anchor=\"#{options[:text_anchor]}\" fill=\"#{options[:fill]}\">#{options[:text]}</text>"
75
+ end
76
+
77
+ DEFAULT_RECTANGLE = {
78
+ xpos: 0,
79
+ ypos: 0,
80
+ width: 100,
81
+ height: 100,
82
+ stroke: "black",
83
+ fill: "transparent",
84
+ stroke_width: 2
85
+ }
86
+ def rectangle(options={})
87
+ "<rect x=\"#{options[:xpos].to_s}\" y=\"#{options[:ypos].to_s}\" width=\"#{options[:width].to_s}\" height=\"#{options[:height].to_s}\" stroke=\"#{options[:stroke]}\" fill=\"#{options[:fill]}\" stroke-width=\"#{options[:stroke_width].to_s}\"/>"
88
+ end
89
+
90
+ def footer
91
+ "</svg>"
92
+ end
93
+
94
+ def quad_ruled_grid(m_rows,n_columns)
95
+
96
+ points_per_box = 40
97
+
98
+ width = n_columns * points_per_box;
99
+ height = m_rows * points_per_box;
100
+
101
+ str = header(n_columns*points_per_box,m_rows*points_per_box)
102
+
103
+
104
+ # make vertical lines
105
+ for n in (0..n_columns)
106
+ verticle_line_opts = {
107
+ x1: n*points_per_box,
108
+ x2: n*points_per_box,
109
+ y1: 0,
110
+ y2: height,
111
+ stroke: "gray",
112
+ stroke_width: 0.5,
113
+ stroke_dasharray: "none"
114
+ }
115
+ str << line(verticle_line_opts)
116
+ end
117
+
118
+ # make horizontal lines
119
+ for m in (0..m_rows)
120
+ horizontal_line_opts = {
121
+ x1: 0,
122
+ x2: width,
123
+ y1: m*points_per_box,
124
+ y2: m*points_per_box,
125
+ stroke: "gray",
126
+ stroke_width: 0.5,
127
+ stroke_dasharray: "none"
128
+ }
129
+ str << line(horizontal_line_opts)
130
+ end
131
+
132
+ str<<footer
133
+
134
+
135
+ end
136
+
137
+
138
+ end
139
+
140
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'svg_components'
2
+
3
+ class SVGCreator
4
+ # Use SVGCreator to add svg components to an array
5
+ # Method 'svg' concatenates the array elements, adds header and footer, and returns svg string
6
+
7
+ def initialize(width,height)
8
+ @width = width
9
+ @height = height
10
+ @components = []
11
+ end
12
+
13
+ def svg
14
+ @components.insert(0,SVGComponents::header(@width,@height))
15
+ @components << SVGComponents::footer
16
+ return @components.join
17
+ end
18
+
19
+
20
+ SVGComponents.methods(false).each do |name|
21
+ define_method("add_#{name}") do |options = {}|
22
+ if options
23
+ if SVGComponents.respond_to?(name)
24
+ @components << SVGComponents.send(name,options)
25
+ else
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+
@@ -0,0 +1,7 @@
1
+ def svg_width(svg)
2
+ /(?<=width=\")\d+(?=\"\s)/.match(svg)[0].to_i
3
+ end
4
+
5
+ def svg_height(svg)
6
+ /(?<=height=\")\d+(?=\"\s)/.match(svg)[0].to_i
7
+ end
@@ -0,0 +1,42 @@
1
+ require_relative "./utilities"
2
+ require_relative "./gridable"
3
+
4
+ module TeachingPrintables
5
+ # Creates grid layouts for flashcards or math sheets. Delegates Prawn methods to Prawn::Document.
6
+
7
+ module Templatable
8
+ include Gridable
9
+
10
+ PRINT_TEMPLATES = {
11
+ compulabel: {
12
+ :page_layout => :portrait,
13
+ :page_size => "LETTER",
14
+ :top_margin => 0.25.in,
15
+ :bottom_margin => 0.25.in,
16
+ :right_margin => 0.in,
17
+ :left_margin => 0.in,
18
+ :columns => 3,
19
+ :rows => 7,
20
+ :gutter => 10
21
+ },
22
+
23
+ avery5371: {
24
+ :page_layout => :portrait,
25
+ :page_size => "LETTER",
26
+ :top_margin => 0.5.in,
27
+ :bottom_margin => 0.5.in,
28
+ :right_margin => 0.75.in,
29
+ :left_margin => 0.75.in,
30
+ :columns => 2,
31
+ :rows => 5,
32
+ :gutter => 0
33
+ }
34
+ }
35
+
36
+ def create_page_with_template(template)
37
+ start_new_page(PRINT_TEMPLATES[template])
38
+ update_grid_options(PRINT_TEMPLATES[template])
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,54 @@
1
+ module TeachingPrintables
2
+ # Creates quadrille rulings on paper. Delegates Prawn methods to Prawn::Document.
3
+ class TPDocument
4
+ # Make quadrille rules on pdf page(s)
5
+ #
6
+ include Prawn::View
7
+
8
+ DOC_OPTIONS_DEFAULT = {
9
+ :page_layout => :portrait,
10
+ :margin => 0
11
+ }
12
+
13
+ def initialize(args={})
14
+ args = DOC_OPTIONS_DEFAULT.merge(args).merge({skip_page_creation: true})
15
+ @document = Prawn::Document.new(args)
16
+ end
17
+
18
+ def page_width
19
+ if page_layout == :portrait
20
+ width = PDF::Core::PageGeometry::SIZES[page_size][0]
21
+ else
22
+ width = PDF::Core::PageGeometry::SIZES[page_size][1]
23
+ end
24
+ end
25
+
26
+ def page_height
27
+ if page_layout == :portrait
28
+ height = PDF::Core::PageGeometry::SIZES[page_size][1]
29
+ else
30
+ height = PDF::Core::PageGeometry::SIZES[page_size][0]
31
+ end
32
+ end
33
+
34
+ def method_missing(m, *args)
35
+ method = m.to_s
36
+ if document.class.public_method_defined?(method)
37
+ document.send(method,*args)
38
+ elsif method.start_with?("page_")
39
+ page_method = method[5..-1]
40
+ if state.page.class.public_method_defined?(page_method)
41
+ state.page.send(page_method,*args)
42
+ else
43
+ raise NoMethodError.new("Can't find method",page_method)
44
+ end
45
+ else
46
+ super
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+
54
+
@@ -0,0 +1,3 @@
1
+ module TeachingPrintables
2
+ VERSION = "0.0.4"
3
+ end
@@ -2,8 +2,12 @@ require 'prawn'
2
2
  require 'prawn/measurement_extensions'
3
3
 
4
4
 
5
- require_relative "teaching_printables/grid_sheet/grid_sheet"
6
- require_relative "teaching_printables/print_templates"
5
+ require_relative "teaching_printables/quad_rulable"
6
+ require_relative "teaching_printables/templatable"
7
+ require_relative "teaching_printables/gridable"
8
+ require_relative "teaching_printables/factory"
9
+ require_relative "teaching_printables/tp_document"
10
+ require_relative "teaching_printables/version"
7
11
 
8
12
  module TeachingPrintables
9
13
  extend self
@@ -21,23 +25,6 @@ module TeachingPrintables
21
25
  !filename.start_with?(".") && GRAPHIC_EXTENSIONS.include?(File.extname(filename))
22
26
  end
23
27
 
24
-
25
- class PictureGridSheet < GridSheet
26
- def place_contents_in_gridbox(picture_filename)
27
- image picture_filename, fit: [@column_width,@row_height]
28
- end
29
- end
30
-
31
-
32
-
33
-
34
- def grid_sheet_with_content(content_array)
35
- gs = GridSheet.new(TeachingPrintables::Printing::Templates::AVERY5371)
36
- gs.make_grid(content_array)
37
- gs.save_as("mygrid.pdf")
38
- puts "Sheet saved as mygrid.pdf"
39
- end
40
-
41
28
  end
42
29
 
43
30
 
@@ -1,9 +1,17 @@
1
+ basedir = File.expand_path(File.dirname(__FILE__))
2
+ require "#{basedir}/lib/teaching_printables/version"
3
+
1
4
  Gem::Specification.new do |s|
2
5
  s.name = 'teaching_printables'
3
- s.version = '0.0.3'
6
+ s.version = TeachingPrintables::VERSION
4
7
  s.executables << 'flashcards_AVERY5371'
8
+
5
9
  s.add_runtime_dependency 'prawn', '~> 2'
6
10
  s.add_runtime_dependency 'prawn-svg', '~> 0'
11
+
12
+ s.add_development_dependency 'minitest', '~> 5.0'
13
+ s.add_development_dependency 'minitest-reporters', '1.0'
14
+
7
15
  s.date = '2016-11-18'
8
16
  s.summary = "Create Printable Sheets for Teaching"
9
17
  s.description = "A gem to create printable sheets for teaching"
@@ -0,0 +1,38 @@
1
+ require_relative './test_helper.rb'
2
+
3
+ require 'tmpdir'
4
+ require 'teaching_printables'
5
+
6
+
7
+ class FactoryTest < MiniTest::Test
8
+ def test_avery5371_with_array_content
9
+ content = (1..10).to_a.map{|i| i.to_s}
10
+ Dir.mktmpdir do |dir|
11
+ output_file_name = File.join(dir,"output.pdf")
12
+ TeachingPrintables::Factory::avery5371_with_array_content(content,output_file_name)
13
+ assert File.exist?(output_file_name)
14
+ end
15
+ end
16
+ def test_hundreds_grid
17
+ Dir.mktmpdir do |dir|
18
+ output_file_name = File.join(dir,"output.pdf")
19
+ TeachingPrintables::Factory::hundreds_grid(output_file_name)
20
+ assert File.exist?(output_file_name)
21
+ end
22
+ end
23
+ def test_quad_ruled_paper_with_1_cm_rule
24
+ Dir.mktmpdir do |dir|
25
+ output_file_name = File.join(dir,"output.pdf")
26
+ TeachingPrintables::Factory::quad_ruled_paper("2","1","cm",output_file_name)
27
+ assert File.exist?(output_file_name)
28
+ end
29
+ end
30
+ def test_quad_ruled_paper_with_quarter_inch_rule
31
+ Dir.mktmpdir do |dir|
32
+ output_file_name = File.join(dir,"output.pdf")
33
+ TeachingPrintables::Factory::quad_ruled_paper("2",".25","in",output_file_name)
34
+ assert File.exist?(output_file_name)
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,33 @@
1
+ require_relative './test_helper.rb'
2
+
3
+
4
+
5
+ class GridableTest < Minitest::Test
6
+ def setup
7
+ @doc = TeachingPrintables::TPDocument.new
8
+ class << @doc
9
+ include TeachingPrintables::Gridable
10
+ end
11
+ @content = (1..20).to_a.map{|i| i.to_s}
12
+ end
13
+
14
+ def test_default_options
15
+ @doc.add_grid_content(@content)
16
+ assert_equal 2, @doc.grid_rows
17
+ assert_equal 2, @doc.grid_columns
18
+ end
19
+
20
+ def test_updates_print_template
21
+ @doc.update_grid_options(columns: 2, rows: 5, gutter: 10 )
22
+ @doc.add_grid_content(@content)
23
+ assert_equal 5, @doc.grid.rows
24
+ assert_equal 2, @doc.grid.columns
25
+ assert_equal 10, @doc.grid.gutter
26
+ end
27
+
28
+ def test_adds_content
29
+ @doc.add_grid_content(@content)
30
+ assert_equal 5, @doc.page_number
31
+ end
32
+
33
+ end
@@ -0,0 +1,22 @@
1
+ require_relative './test_helper.rb'
2
+
3
+
4
+
5
+ class QuadRulableTest < Minitest::Test
6
+ def setup
7
+ @doc = TeachingPrintables::TPDocument.new
8
+ class << @doc
9
+ include TeachingPrintables::QuadRulable
10
+ end
11
+
12
+ end
13
+
14
+ def test_default_options
15
+ assert_equal 1.cm, @doc.rule_unit
16
+ end
17
+
18
+ def test_default_options
19
+ @doc.create_quad_rule({rule_unit: 0.25.in})
20
+ assert_equal(0.25.in, @doc.rule_unit)
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class TeachingPrintablesTest < Minitest::Test
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::TeachingPrintables::VERSION
6
+ end
7
+
8
+ end
@@ -0,0 +1,26 @@
1
+ require_relative './test_helper.rb'
2
+
3
+ class TemplatableTest < Minitest::Test
4
+ def setup
5
+ @doc = TeachingPrintables::TPDocument.new
6
+ class << @doc
7
+ include TeachingPrintables::Templatable
8
+ end
9
+ end
10
+
11
+ def test_creates_page_with_correct_template
12
+ @doc.create_page_with_template(:avery5371)
13
+ @doc.add_grid_content(%W[a b c d e f g h i j])
14
+ assert_equal({:left=>54.0, :right=>54.0, :top=>36.0, :bottom=>36.0},@doc.page.margins)
15
+ assert_equal(2, @doc.grid.columns)
16
+ assert_equal(5, @doc.grid.rows)
17
+ assert_equal(144, @doc.grid.row_height)
18
+ assert_equal(252, @doc.grid.column_width)
19
+ assert_equal(0.0,@doc.grid.gutter)
20
+ end
21
+
22
+ def test_is_gridable
23
+ assert (class << @doc; self; end).included_modules.include?(TeachingPrintables::Gridable)
24
+ end
25
+
26
+ end
@@ -0,0 +1,6 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/reporters'
3
+
4
+ Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(:color => true)]
5
+
6
+ require 'teaching_printables'
@@ -0,0 +1,18 @@
1
+ require_relative './test_helper.rb'
2
+
3
+ require 'tmpdir'
4
+ require 'teaching_printables'
5
+
6
+
7
+ describe TeachingPrintables::TPDocument do
8
+ # before do
9
+ # @tp = TeachingPrintables::TPDocument.new
10
+ # end
11
+
12
+ describe "the class" do
13
+ it "contains Prawn::View module" do
14
+ assert TeachingPrintables::TPDocument < Prawn::View
15
+ end
16
+ end
17
+
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teaching_printables
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
  - Jen Dobson
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
41
69
  description: A gem to create printable sheets for teaching
42
70
  email: jendobson@gmail.com
43
71
  executables:
@@ -46,13 +74,29 @@ extensions: []
46
74
  extra_rdoc_files: []
47
75
  files:
48
76
  - Rakefile
77
+ - bin/console
49
78
  - bin/flashcards_AVERY5371
79
+ - bin/quad_ruled_paper
80
+ - bin/setup
50
81
  - lib/teaching_printables.rb
51
- - lib/teaching_printables/grid_sheet/grid_sheet.rb
52
- - lib/teaching_printables/print_templates.rb
82
+ - lib/teaching_printables/factory.rb
83
+ - lib/teaching_printables/gridable.rb
84
+ - lib/teaching_printables/quad_rulable.rb
85
+ - lib/teaching_printables/svg/svg_components.rb
86
+ - lib/teaching_printables/svg/svg_creator.rb
87
+ - lib/teaching_printables/svg/svg_helpers.rb
88
+ - lib/teaching_printables/templatable.rb
89
+ - lib/teaching_printables/tp_document.rb
53
90
  - lib/teaching_printables/utilities.rb
91
+ - lib/teaching_printables/version.rb
54
92
  - teaching_printables.gemspec
55
- - test/test_grid_sheet.rb
93
+ - test/factory_test.rb
94
+ - test/gridable_test.rb
95
+ - test/quad_rulable_test.rb
96
+ - test/teaching_printables_test.rb
97
+ - test/templatable_test.rb
98
+ - test/test_helper.rb
99
+ - test/tp_document_test.rb
56
100
  homepage: https://rubygems.org/gems/teaching_printables
57
101
  licenses:
58
102
  - MIT
@@ -73,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
117
  version: '0'
74
118
  requirements: []
75
119
  rubyforge_project:
76
- rubygems_version: 2.5.1
120
+ rubygems_version: 2.4.8
77
121
  signing_key:
78
122
  specification_version: 4
79
123
  summary: Create Printable Sheets for Teaching
@@ -1,79 +0,0 @@
1
- require "forwardable"
2
-
3
- require_relative "../utilities"
4
-
5
- module TeachingPrintables
6
- # Creates grid layouts for flashcards or math sheets. Delegates Prawn methods to Prawn::Document.
7
- class GridSheet
8
- # Make grid-based pdf page(s)
9
- #
10
- # Example:
11
- # >> gs = TeachingPrintables.GridSheet.new
12
- # >> content = (1..20).to_a.map{|i| i.to_s}
13
- # >> gs.add_content(content)
14
- # >> gs.page_number
15
- # >> gs.save_as("mypdf.pdf")
16
- extend Forwardable
17
- include Prawn::View
18
-
19
- attr_reader :rows, :columns, :gutter, :column_width, :row_height
20
-
21
-
22
- GRID_OPTIONS_DEFAULT = {
23
- columns: 2,
24
- rows: 2,
25
- gutter: 0,
26
- column_width: 100,
27
- row_height: 100
28
- }
29
-
30
- def initialize(args={},doc=nil)
31
- if !doc
32
- @document = Prawn::Document.new(args.merge({skip_page_creation: true }))
33
- elsif doc.kind_of?(Prawn::Document)
34
- @document = doc
35
- else
36
- raise ArgumentError, "Expecting Prawn::Document", caller
37
- end
38
- @font_size = 60
39
- update_grid_options(GRID_OPTIONS_DEFAULT.merge(args))
40
- end
41
-
42
- def_delegators :@document, :font_size, :page_number, :y, :grid
43
-
44
- def update_grid_options(options)
45
- options.each do |k,v|
46
- instance_variable_set("@#{k}", options[k]) unless options[k].nil?
47
- end
48
- end
49
-
50
- def add_content(content_array)
51
- @document.define_grid(grid_options)
52
- content_array.each_with_index {|obj,ind|
53
-
54
- if ind%(@rows*@columns)==0
55
- @document.start_new_page
56
- end
57
-
58
- subs = ind2sub([@rows,@columns],ind%(@rows*@columns))
59
- @document.grid(subs[0],subs[1]).bounding_box do
60
- #place_contents_in_gridbox(obj)
61
- @document.text_box obj.to_s, align: :center, valign: :center, size: @font_size, overflow: :shrink_to_fit
62
- end
63
- }
64
- end
65
-
66
-
67
-
68
- def place_contents_in_gridbox(obj)
69
- text obj.to_s, fit: [@column_width,@row_height]
70
- end
71
-
72
- private
73
- def grid_options
74
- keys = GRID_OPTIONS_DEFAULT.keys
75
- Hash[keys.map { |key| [key.to_sym, instance_variable_get("@#{key}")] } ]
76
- end
77
-
78
- end
79
- end
@@ -1,33 +0,0 @@
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
-
@@ -1,36 +0,0 @@
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