jekyll-pandoc-multiple-formats 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,105 @@
1
+ # Copyright (c) 2012-2015 Nicolás Reynolds <fauno@endefensadelsl.org>
2
+ # 2012-2013 Mauricio Pasquier Juan <mpj@endefensadelsl.org>
3
+ # 2013 Brian Candler <b.candler@pobox.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ require 'pdf/info'
25
+ require 'rtex'
26
+
27
+ module JekyllPandocMultipleFormats
28
+ class Printer
29
+ TEMPLATE = <<-EOT.gsub(/^\s+/, '')
30
+ \\documentclass[@@sheetsize@@,10pt]{article}
31
+
32
+ \\usepackage{pgfpages}
33
+ \\usepackage{pdfpages}
34
+
35
+ \\pgfpagesuselayout{@@nup@@ on 1}[@@sheetsize@@,@@extra_options@@]
36
+
37
+ \\begin{document}
38
+ \\includepdf[pages={@@pages@@}]{@@document@@}
39
+ \\end{document}
40
+ EOT
41
+
42
+ # TODO allow custom sheet sizes
43
+ SHEET_SIZES = {
44
+ a7paper: 2,
45
+ a6paper: 4,
46
+ a5paper: 8,
47
+ a4paper: 16,
48
+ a3paper: 32,
49
+ a2paper: 64,
50
+ a1paper: 128,
51
+ a0paper: 256
52
+ }
53
+
54
+ attr_accessor :output_file, :original_file, :pages, :template,
55
+ :papersize, :sheetsize, :nup, :extra_options, :relative_path
56
+
57
+ def initialize(file, papersize = nil, sheetsize = nil, extra_options = nil)
58
+ return unless /\.pdf\Z/ =~ file
59
+ return unless pdf = PDF::Info.new(file)
60
+
61
+ @original_file = File.realpath(file)
62
+ @papersize = papersize || 'a5paper'
63
+ @sheetsize = sheetsize || 'a4paper'
64
+ @pages = pdf.metadata[:page_count]
65
+ @nup = SHEET_SIZES[@sheetsize.to_sym] / SHEET_SIZES[@papersize.to_sym]
66
+ @extra_options = extra_options || ''
67
+
68
+ # These layouts require a landscape page
69
+ @extra_options << 'landscape' if is_landscape?
70
+
71
+ self
72
+ end
73
+
74
+ def relative_path(from)
75
+ @relative_path ||= Pathname.new(output_file).relative_path_from(Pathname.new(from)).to_s
76
+ end
77
+
78
+ def write
79
+ # Create the imposed file
80
+ pdflatex = RTeX::Document.new(template)
81
+ pdflatex.to_pdf do |pdf_file|
82
+ FileUtils.cp pdf_file, @output_file
83
+ end
84
+
85
+ File.exists? @output_file
86
+ end
87
+
88
+ def is_landscape?
89
+ [2,8,32,128].include? @nup
90
+ end
91
+
92
+ def round_to_nearest(int, near)
93
+ (int + (near - 1)) / near * near
94
+ end
95
+
96
+ def render_template
97
+ @template = TEMPLATE
98
+ .gsub('@@nup@@', @nup.to_s)
99
+ .gsub('@@sheetsize@@', @sheetsize)
100
+ .gsub('@@extra_options@@', @extra_options)
101
+ .gsub('@@document@@', @original_file)
102
+ .gsub('@@pages@@', to_nup * ',')
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,70 @@
1
+ # Copyright (c) 2012-2015 Nicolás Reynolds <fauno@endefensadelsl.org>
2
+ # 2012-2013 Mauricio Pasquier Juan <mpj@endefensadelsl.org>
3
+ # 2013 Brian Candler <b.candler@pobox.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ module JekyllPandocMultipleFormats
25
+ class Unite < Printer
26
+ TEMPLATE = <<-EOT.gsub(/^\s+/, '')
27
+ \\documentclass{article}
28
+ \\usepackage{pdfpages}
29
+
30
+ \\begin{document}
31
+ @@include@@
32
+ \\end{document}
33
+ EOT
34
+
35
+ INCLUDE_TEMPLATE = '\\includepdf[fitpaper=true,pages=-]{@@document@@}'
36
+
37
+ attr_accessor :files, :template
38
+
39
+ def initialize(output_file, files)
40
+ raise ArgumentError.new 'An array of filenames is required' unless files.is_a? Array
41
+
42
+ @output_file = output_file
43
+ self.files = files
44
+
45
+ render_template
46
+ self
47
+ end
48
+
49
+ def <<(file)
50
+ @files ||= []
51
+ @files << File.realpath(file) if /\.pdf\Z/ =~ file
52
+ end
53
+
54
+ def files=(file_array)
55
+ return unless file_array.respond_to? :each
56
+
57
+ file_array.each do |f|
58
+ self << f
59
+ end
60
+ end
61
+
62
+ def render_template
63
+ includes = @files.map do |f|
64
+ INCLUDE_TEMPLATE.gsub(/@@document@@/, f)
65
+ end
66
+
67
+ @template = TEMPLATE.gsub('@@include@@', includes.join("\n"))
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllPandocMultipleFormats
2
+ VERSION = '0.2.8'
3
+ end
Binary file
@@ -0,0 +1 @@
1
+ {{ yield }}
@@ -0,0 +1,10 @@
1
+ ---
2
+ layout: nil
3
+ title: A Title
4
+ author: minitest
5
+ categories: [ test ]
6
+ ---
7
+
8
+ # A Title
9
+
10
+ Some text.
@@ -0,0 +1,11 @@
1
+ ---
2
+ layout: nil
3
+ title: Another Title
4
+ author: minitest
5
+ categories: [ test ]
6
+ ---
7
+
8
+ # Another Title
9
+
10
+ Some text.
11
+
@@ -0,0 +1,37 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ TEST_PDF = File.join(File.dirname(__FILE__),'fixtures/test.pdf')
5
+ TEST_IMPOSED_PDF = File.join(File.dirname(__FILE__),'fixtures/test-imposed.pdf')
6
+ TEST_BINDER_PDF = File.join(File.dirname(__FILE__),'fixtures/test-binder.pdf')
7
+
8
+ TEST_DIR = File.expand_path("../", __FILE__)
9
+ SOURCE_DIR = File.expand_path("source", TEST_DIR)
10
+ DEST_DIR = File.expand_path("destination", TEST_DIR)
11
+
12
+ require 'rubygems'
13
+ require 'minitest/autorun'
14
+ require 'shoulda'
15
+ require 'jekyll'
16
+ require 'jekyll-pandoc-multiple-formats'
17
+
18
+
19
+ # Copied from jekyll-archives (c) Alfred Xing, licensed under MIT with
20
+ # the following note:
21
+ # Taken from jekyll-mentions (Copyright (c) 2014 GitHub, Inc. Licensened under the MIT).
22
+ class Minitest::Test
23
+ def fixture_site(config = {})
24
+ Jekyll::Site.new(
25
+ Jekyll::Utils.deep_merge_hashes(
26
+ Jekyll::Utils.deep_merge_hashes(
27
+ Jekyll::Configuration::DEFAULTS,
28
+ {
29
+ "source" => SOURCE_DIR,
30
+ "destination" => DEST_DIR
31
+ }
32
+ ),
33
+ config
34
+ )
35
+ )
36
+ end
37
+ end
@@ -0,0 +1,106 @@
1
+ require 'test_helper'
2
+
3
+ class TestPandocFile < MiniTest::Test
4
+ context 'single post' do
5
+ setup do
6
+ @site = fixture_site({ 'pandoc' => { }})
7
+ @site.read
8
+ @pandoc_file = Jekyll::PandocFile.new(@site, 'pdf', @site.posts.docs.first)
9
+ end
10
+
11
+ should 'be a single post' do
12
+ assert @pandoc_file.single_post?
13
+ end
14
+
15
+ should 'have a format' do
16
+ assert_equal 'pdf', @pandoc_file.format
17
+ end
18
+
19
+ should 'have an extension' do
20
+ assert @pandoc_file.path.end_with?('pdf')
21
+ end
22
+
23
+ should 'share the same path with different extension' do
24
+ assert @pandoc_file.path.end_with?(@site.posts.docs.first.url.gsub(/html\Z/, 'pdf'))
25
+ end
26
+
27
+ should 'share the same title' do
28
+ assert_equal @site.posts.docs.first.data['title'], @pandoc_file.title
29
+ end
30
+
31
+ should 'have an url' do
32
+ assert_equal @site.posts.docs.first.url.gsub(/html\Z/, 'pdf'), @pandoc_file.url
33
+ end
34
+
35
+ should 'have metadata in yaml format' do
36
+ assert @pandoc_file.yaml_metadata.start_with?('---')
37
+ assert @pandoc_file.yaml_metadata.end_with?("---\n")
38
+ end
39
+
40
+ should 'have content' do
41
+ assert @pandoc_file.content.is_a?(String)
42
+ assert_equal @site.posts.docs.first.content, @pandoc_file.content
43
+ end
44
+
45
+ should 'be a pdf' do
46
+ assert @pandoc_file.pdf?
47
+ assert @pandoc_file.binary?
48
+ refute @pandoc_file.epub?
49
+ end
50
+
51
+ should 'not have a cover' do
52
+ refute @pandoc_file.has_cover?
53
+ refute @pandoc_file.cover
54
+ end
55
+
56
+ should 'have a papersize' do
57
+ refute @pandoc_file.papersize.empty?
58
+ end
59
+
60
+ should 'have a sheetsize' do
61
+ refute @pandoc_file.sheetsize.empty?
62
+ end
63
+
64
+ should 'have flags' do
65
+ assert @pandoc_file.flags.is_a?(String)
66
+ assert @pandoc_file.flags.length > 0
67
+ end
68
+
69
+ should 'create a file' do
70
+ assert @pandoc_file.write
71
+ assert File.exists?(@pandoc_file.path)
72
+ end
73
+
74
+ end
75
+
76
+ context 'several posts' do
77
+ setup do
78
+ @site = fixture_site({ 'pandoc' => { }})
79
+ @site.read
80
+ @pandoc_file = Jekyll::PandocFile.new(@site, 'pdf', @site.posts.docs, 'Multipost test')
81
+ end
82
+
83
+ should 'be multipost' do
84
+ refute @pandoc_file.single_post?
85
+ end
86
+
87
+ should 'have a title' do
88
+ assert_raises(ArgumentError) { Jekyll::PandocFile.new(@site, 'pdf', @site.posts.docs) }
89
+ refute @pandoc_file.title.empty?
90
+ end
91
+
92
+ should 'have a path' do
93
+ assert @pandoc_file.path.end_with?("#{@pandoc_file.slug}.#{@pandoc_file.format}")
94
+ end
95
+
96
+ should 'have metadata in yaml format' do
97
+ assert @pandoc_file.yaml_metadata.start_with?('---')
98
+ assert @pandoc_file.yaml_metadata.end_with?("---\n")
99
+ end
100
+
101
+ should 'create a file' do
102
+ assert @pandoc_file.write
103
+ assert File.exists?(@pandoc_file.path)
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,483 @@
1
+ require 'test_helper'
2
+
3
+ class TestJekyllPandocMultipleFormats < MiniTest::Test
4
+ context 'imposition' do
5
+ setup do
6
+ @imposition = JekyllPandocMultipleFormats::Imposition.new(TEST_PDF)
7
+ end
8
+
9
+ should 'have a new file name' do
10
+ assert_equal TEST_IMPOSED_PDF, @imposition.output_file
11
+ end
12
+
13
+ should 'write a new filename' do
14
+ assert @imposition.write
15
+ assert File.exists?(TEST_IMPOSED_PDF)
16
+ assert FileUtils.rm(TEST_IMPOSED_PDF)
17
+ end
18
+
19
+ should 'have number of pages' do
20
+ assert_equal 23, @imposition.pages
21
+ end
22
+
23
+ should 'have a sheet size' do
24
+ assert_equal 'a4paper', @imposition.sheetsize
25
+ end
26
+
27
+ should 'have a page size' do
28
+ assert_equal 'a5paper', @imposition.papersize
29
+ end
30
+
31
+ should 'have rounded pages' do
32
+ assert_equal 24, @imposition.rounded_pages
33
+ end
34
+
35
+ should 'have blank pages' do
36
+ assert_equal 1, @imposition.blank_pages
37
+ end
38
+
39
+ should 'have a signature' do
40
+ assert_equal 24, @imposition.signature
41
+ end
42
+
43
+ should 'have ordered pages' do
44
+ assert_equal ["{}", 1, 2, 23, 22, 3, 4, 21, 20, 5, 6, 19, 18, 7, 8, 17, 16, 9, 10, 15, 14, 11, 12, 13], @imposition.to_nup
45
+ end
46
+ end
47
+
48
+ context 'signed imposition' do
49
+ setup do
50
+ @imposition = JekyllPandocMultipleFormats::Imposition.new(TEST_PDF, 'a5paper', 'a4paper', 12)
51
+ end
52
+
53
+ should 'have a sheet size' do
54
+ assert_equal 'a4paper', @imposition.sheetsize
55
+ end
56
+
57
+ should 'have a page size' do
58
+ assert_equal 'a5paper', @imposition.papersize
59
+ end
60
+
61
+ should 'have a signature' do
62
+ assert_equal 12, @imposition.signature
63
+ end
64
+
65
+ should 'have ordered pages' do
66
+ assert_equal [12, 1, 2, 11, 10, 3, 4, 9, 8, 5, 6, 7, "{}", 13, 14, 23, 22, 15, 16, 21, 20, 17, 18, 19], @imposition.to_nup
67
+ end
68
+ end
69
+
70
+ context '2x1 imposition' do
71
+ setup do
72
+ @impositions = []
73
+
74
+ [
75
+ { p: 'a7paper', s: 'a6paper' },
76
+ { p: 'a6paper', s: 'a5paper' },
77
+ { p: 'a5paper', s: 'a4paper' },
78
+ { p: 'a4paper', s: 'a3paper' },
79
+ { p: 'a3paper', s: 'a2paper' },
80
+ { p: 'a2paper', s: 'a1paper' },
81
+ { p: 'a1paper', s: 'a0paper' }
82
+ ].each do |i|
83
+ @impositions << JekyllPandocMultipleFormats::Imposition.new(TEST_PDF, i[:p], i[:s])
84
+ end
85
+ end
86
+
87
+ should 'have ordered pages' do
88
+ @impositions.each do |i|
89
+ assert_equal ["{}", 1, 2, 23, 22, 3, 4, 21, 20, 5, 6, 19, 18, 7, 8, 17, 16, 9, 10, 15, 14, 11, 12, 13], i.to_nup
90
+ end
91
+ end
92
+ end
93
+
94
+ context '4x1 imposition' do
95
+ setup do
96
+ @impositions = []
97
+
98
+ [
99
+ { p: 'a7paper', s: 'a5paper' },
100
+ { p: 'a6paper', s: 'a4paper' },
101
+ { p: 'a5paper', s: 'a3paper' },
102
+ { p: 'a4paper', s: 'a2paper' },
103
+ { p: 'a3paper', s: 'a1paper' },
104
+ { p: 'a2paper', s: 'a0paper' }
105
+ ].each do |i|
106
+ @impositions << JekyllPandocMultipleFormats::Imposition.new(TEST_PDF, i[:p], i[:s])
107
+ end
108
+ end
109
+
110
+ should 'have ordered pages' do
111
+ @impositions.each do |i|
112
+ assert_equal ["{}", 1, "{}", 1,
113
+ 2, 23, 2, 23,
114
+ 22, 3, 22, 3,
115
+ 4, 21, 4, 21,
116
+ 20, 5, 20, 5,
117
+ 6, 19, 6, 19,
118
+ 18, 7, 18, 7,
119
+ 8, 17, 8, 17,
120
+ 16, 9, 16, 9,
121
+ 10, 15, 10, 15,
122
+ 14, 11, 14, 11,
123
+ 12, 13, 12, 13],
124
+ i.to_nup
125
+ end
126
+ end
127
+ end
128
+
129
+ context '8x1 imposition' do
130
+ setup do
131
+ @impositions = []
132
+
133
+ [
134
+ { p: 'a7paper', s: 'a4paper' },
135
+ { p: 'a6paper', s: 'a3paper' },
136
+ { p: 'a5paper', s: 'a2paper' },
137
+ { p: 'a4paper', s: 'a1paper' },
138
+ { p: 'a3paper', s: 'a0paper' }
139
+ ].each do |i|
140
+ @impositions << JekyllPandocMultipleFormats::Imposition.new(TEST_PDF, i[:p], i[:s])
141
+ end
142
+ end
143
+
144
+ should 'have ordered pages' do
145
+ @impositions.each do |i|
146
+ assert_equal [
147
+ "{}", 1, "{}", 1, "{}", 1, "{}", 1,
148
+ 2, 23, 2, 23, 2, 23, 2, 23,
149
+ 22, 3, 22, 3, 22, 3, 22, 3,
150
+ 4, 21, 4, 21, 4, 21, 4, 21,
151
+ 20, 5, 20, 5, 20, 5, 20, 5,
152
+ 6, 19, 6, 19, 6, 19, 6, 19,
153
+ 18, 7, 18, 7, 18, 7, 18, 7,
154
+ 8, 17, 8, 17, 8, 17, 8, 17,
155
+ 16, 9, 16, 9, 16, 9, 16, 9,
156
+ 10, 15, 10, 15, 10, 15, 10, 15,
157
+ 14, 11, 14, 11, 14, 11, 14, 11,
158
+ 12, 13, 12, 13, 12, 13, 12, 13],
159
+ i.to_nup
160
+ end
161
+ end
162
+ end
163
+
164
+ context '16x1 imposition' do
165
+ setup do
166
+ @impositions = []
167
+
168
+ [
169
+ { p: 'a7paper', s: 'a3paper' },
170
+ { p: 'a6paper', s: 'a2paper' },
171
+ { p: 'a5paper', s: 'a1paper' },
172
+ { p: 'a4paper', s: 'a0paper' }
173
+ ].each do |i|
174
+ @impositions << JekyllPandocMultipleFormats::Imposition.new(TEST_PDF, i[:p], i[:s])
175
+ end
176
+ end
177
+
178
+ should 'have ordered pages' do
179
+ @impositions.each do |i|
180
+ assert_equal [
181
+ "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1,
182
+ 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23,
183
+ 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3,
184
+ 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21,
185
+ 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5,
186
+ 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19,
187
+ 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7,
188
+ 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17,
189
+ 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9,
190
+ 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15,
191
+ 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11,
192
+ 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13],
193
+ i.to_nup
194
+ end
195
+ end
196
+ end
197
+
198
+ context '32x1 imposition' do
199
+ setup do
200
+ @impositions = []
201
+
202
+ [
203
+ { p: 'a7paper', s: 'a2paper' },
204
+ { p: 'a6paper', s: 'a1paper' },
205
+ { p: 'a5paper', s: 'a0paper' }
206
+ ].each do |i|
207
+ @impositions << JekyllPandocMultipleFormats::Imposition.new(TEST_PDF, i[:p], i[:s])
208
+ end
209
+ end
210
+
211
+ should 'have ordered pages' do
212
+ @impositions.each do |i|
213
+ assert_equal [
214
+ "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1, "{}", 1,
215
+ 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23, 2, 23,
216
+ 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3,
217
+ 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21, 4, 21,
218
+ 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5, 20, 5,
219
+ 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19, 6, 19,
220
+ 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7, 18, 7,
221
+ 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17, 8, 17,
222
+ 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9, 16, 9,
223
+ 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15, 10, 15,
224
+ 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11, 14, 11,
225
+ 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13],
226
+ i.to_nup
227
+ end
228
+ end
229
+ end
230
+
231
+ context 'binder' do
232
+ setup do
233
+ @binder = JekyllPandocMultipleFormats::Binder.new(TEST_PDF)
234
+ end
235
+
236
+ should 'write a new filename' do
237
+ assert @binder.write
238
+ assert File.exists?(TEST_BINDER_PDF)
239
+ assert FileUtils.rm(TEST_BINDER_PDF)
240
+ end
241
+
242
+ should 'have number of pages' do
243
+ assert_equal 23, @binder.pages
244
+ end
245
+
246
+ should 'have a sheet size' do
247
+ assert_equal 'a4paper', @binder.sheetsize
248
+ end
249
+
250
+ should 'have a page size' do
251
+ assert_equal 'a5paper', @binder.papersize
252
+ end
253
+ end
254
+
255
+ context '2x1 binder' do
256
+ setup do
257
+ @binder = []
258
+
259
+ [
260
+ { p: 'a7paper', s: 'a6paper' },
261
+ { p: 'a6paper', s: 'a5paper' },
262
+ { p: 'a5paper', s: 'a4paper' },
263
+ { p: 'a4paper', s: 'a3paper' },
264
+ { p: 'a3paper', s: 'a2paper' },
265
+ { p: 'a2paper', s: 'a1paper' },
266
+ { p: 'a1paper', s: 'a0paper' }
267
+ ].each do |i|
268
+ @binder << JekyllPandocMultipleFormats::Binder.new(TEST_PDF, i[:p], i[:s])
269
+ end
270
+ end
271
+
272
+ should 'have ordered pages' do
273
+ @binder.each do |i|
274
+ assert_equal [
275
+ 1, 1,
276
+ 2, 2,
277
+ 3, 3,
278
+ 4, 4,
279
+ 5, 5,
280
+ 6, 6,
281
+ 7, 7,
282
+ 8, 8,
283
+ 9, 9,
284
+ 10, 10,
285
+ 11, 11,
286
+ 12, 12,
287
+ 13, 13,
288
+ 14, 14,
289
+ 15, 15,
290
+ 16, 16,
291
+ 17, 17,
292
+ 18, 18,
293
+ 19, 19,
294
+ 20, 20,
295
+ 21, 21,
296
+ 22, 22,
297
+ 23, 23 ], i.to_nup
298
+ end
299
+ end
300
+ end
301
+
302
+ context '4x1 binder' do
303
+ setup do
304
+ @binder = []
305
+
306
+ [
307
+ { p: 'a7paper', s: 'a5paper' },
308
+ { p: 'a6paper', s: 'a4paper' },
309
+ { p: 'a5paper', s: 'a3paper' },
310
+ { p: 'a4paper', s: 'a2paper' },
311
+ { p: 'a3paper', s: 'a1paper' },
312
+ { p: 'a2paper', s: 'a0paper' }
313
+ ].each do |i|
314
+ @binder << JekyllPandocMultipleFormats::Binder.new(TEST_PDF, i[:p], i[:s])
315
+ end
316
+ end
317
+
318
+ should 'have ordered pages' do
319
+ @binder.each do |i|
320
+ assert_equal [
321
+ 1, 1, 1, 1,
322
+ 2, 2, 2, 2,
323
+ 3, 3, 3, 3,
324
+ 4, 4, 4, 4,
325
+ 5, 5, 5, 5,
326
+ 6, 6, 6, 6,
327
+ 7, 7, 7, 7,
328
+ 8, 8, 8, 8,
329
+ 9, 9, 9, 9,
330
+ 10, 10, 10, 10,
331
+ 11, 11, 11, 11,
332
+ 12, 12, 12, 12,
333
+ 13, 13, 13, 13,
334
+ 14, 14, 14, 14,
335
+ 15, 15, 15, 15,
336
+ 16, 16, 16, 16,
337
+ 17, 17, 17, 17,
338
+ 18, 18, 18, 18,
339
+ 19, 19, 19, 19,
340
+ 20, 20, 20, 20,
341
+ 21, 21, 21, 21,
342
+ 22, 22, 22, 22,
343
+ 23, 23, 23, 23],
344
+ i.to_nup
345
+ end
346
+ end
347
+ end
348
+
349
+ context '8x1 binder' do
350
+ setup do
351
+ @binder = []
352
+
353
+ [
354
+ { p: 'a7paper', s: 'a4paper' },
355
+ { p: 'a6paper', s: 'a3paper' },
356
+ { p: 'a5paper', s: 'a2paper' },
357
+ { p: 'a4paper', s: 'a1paper' },
358
+ { p: 'a3paper', s: 'a0paper' }
359
+ ].each do |i|
360
+ @binder << JekyllPandocMultipleFormats::Binder.new(TEST_PDF, i[:p], i[:s])
361
+ end
362
+ end
363
+
364
+ should 'have ordered pages' do
365
+ @binder.each do |i|
366
+ assert_equal [
367
+ 1, 1, 1, 1, 1, 1, 1, 1,
368
+ 2, 2, 2, 2, 2, 2, 2, 2,
369
+ 3, 3, 3, 3, 3, 3, 3, 3,
370
+ 4, 4, 4, 4, 4, 4, 4, 4,
371
+ 5, 5, 5, 5, 5, 5, 5, 5,
372
+ 6, 6, 6, 6, 6, 6, 6, 6,
373
+ 7, 7, 7, 7, 7, 7, 7, 7,
374
+ 8, 8, 8, 8, 8, 8, 8, 8,
375
+ 9, 9, 9, 9, 9, 9, 9, 9,
376
+ 10, 10, 10, 10, 10, 10, 10, 10,
377
+ 11, 11, 11, 11, 11, 11, 11, 11,
378
+ 12, 12, 12, 12, 12, 12, 12, 12,
379
+ 13, 13, 13, 13, 13, 13, 13, 13,
380
+ 14, 14, 14, 14, 14, 14, 14, 14,
381
+ 15, 15, 15, 15, 15, 15, 15, 15,
382
+ 16, 16, 16, 16, 16, 16, 16, 16,
383
+ 17, 17, 17, 17, 17, 17, 17, 17,
384
+ 18, 18, 18, 18, 18, 18, 18, 18,
385
+ 19, 19, 19, 19, 19, 19, 19, 19,
386
+ 20, 20, 20, 20, 20, 20, 20, 20,
387
+ 21, 21, 21, 21, 21, 21, 21, 21,
388
+ 22, 22, 22, 22, 22, 22, 22, 22,
389
+ 23, 23, 23, 23, 23, 23, 23, 23],
390
+ i.to_nup
391
+ end
392
+ end
393
+ end
394
+
395
+ context '16x1 binder' do
396
+ setup do
397
+ @binder = []
398
+
399
+ [
400
+ { p: 'a7paper', s: 'a3paper' },
401
+ { p: 'a6paper', s: 'a2paper' },
402
+ { p: 'a5paper', s: 'a1paper' },
403
+ { p: 'a4paper', s: 'a0paper' }
404
+ ].each do |i|
405
+ @binder << JekyllPandocMultipleFormats::Binder.new(TEST_PDF, i[:p], i[:s])
406
+ end
407
+ end
408
+
409
+ should 'have ordered pages' do
410
+ @binder.each do |i|
411
+ assert_equal [
412
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
413
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
414
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
415
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
416
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
417
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
418
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
419
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
420
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
421
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
422
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
423
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
424
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
425
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
426
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
427
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
428
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
429
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
430
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
431
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
432
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
433
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
434
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23],
435
+ i.to_nup
436
+ end
437
+ end
438
+ end
439
+
440
+ context '32x1 binder' do
441
+ setup do
442
+ @binder = []
443
+
444
+ [
445
+ { p: 'a7paper', s: 'a2paper' },
446
+ { p: 'a6paper', s: 'a1paper' },
447
+ { p: 'a5paper', s: 'a0paper' }
448
+ ].each do |i|
449
+ @binder << JekyllPandocMultipleFormats::Binder.new(TEST_PDF, i[:p], i[:s])
450
+ end
451
+ end
452
+
453
+ should 'have ordered pages' do
454
+ @binder.each do |i|
455
+ assert_equal [
456
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
457
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
458
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
459
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
460
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
461
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
462
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
463
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
464
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
465
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
466
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
467
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
468
+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
469
+ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
470
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
471
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
472
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
473
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
474
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
475
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
476
+ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
477
+ 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
478
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23],
479
+ i.to_nup
480
+ end
481
+ end
482
+ end
483
+ end