Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6db6c4e

Browse files
--wip-- [skip ci]
1 parent fa638c2 commit 6db6c4e

File tree

5 files changed

+121
-6
lines changed

5 files changed

+121
-6
lines changed

‎book/chapters/colophon.adoc‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
[colophon]
2-
= Colophon
3-
4-
{doctitle}
1+
[colophon#colophon%nonfacing]
2+
= {doctitle}
53

64
Copyright © {docyear} Adrian Mejia
75

‎book/chapters/sample.adoc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[[chapter-1]]
12
= Sample Section
23

34

@@ -338,6 +339,7 @@ digraph g {
338339
:leveloffset: -1
339340

340341

342+
[[chapter-2]]
341343
= Section 2
342344

343345
== Another sample
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
require 'asciidoctor-pdf' unless defined? ::Asciidoctor::Pdf
2+
3+
module AsciidoctorPdfExtensions
4+
# Override the built-in layout_toc to move colophon before front of table of contents
5+
# NOTE we assume that the colophon fits on a single page
6+
def layout_toc doc, num_levels = 2, toc_page_number = 2, num_front_matter_pages = 0
7+
go_to_page toc_page_number unless (page_number == toc_page_number) || scratch?
8+
if scratch?
9+
colophon = doc.find_by(context: :section) {|sect| sect.sectname == 'colophon' }
10+
if (colophon = colophon.first)
11+
doc.instance_variable_set :@colophon, colophon
12+
colophon.parent.blocks.delete colophon
13+
end
14+
else
15+
if (colophon = doc.instance_variable_get :@colophon)
16+
# if prepress book, consume blank page before table of contents
17+
go_to_page(page_number - 1) if @ppbook
18+
convert_section colophon
19+
go_to_page(page_number + 1)
20+
end
21+
end
22+
offset = colophon && !@ppbook ? 1 : 0
23+
toc_page_numbers = super doc, num_levels, (toc_page_number + offset), num_front_matter_pages
24+
scratch? ? ((toc_page_numbers.begin - offset)..toc_page_numbers.end) : toc_page_numbers
25+
end
26+
27+
# force chapters to start on new page;
28+
# force select chapters to start on the recto (odd-numbered, right-hand) page
29+
def start_new_chapter chapter
30+
start_new_page unless at_page_top?
31+
if @ppbook && verso_page? && !(chapter.option? 'nonfacing')
32+
update_colors # prevents Ghostscript from reporting a warning when running content is written to blank page
33+
start_new_page
34+
end
35+
end
36+
37+
def layout_chapter_title node, title, opts = {}
38+
puts node.id
39+
40+
if (sect_id = node.id) == '_dedication' || sect_id == 'acknowledgements'
41+
layout_heading_custom title, align: :center
42+
elsif sect_id == 'colophon'
43+
puts 'Processing.. ' + node.sectname + '...'
44+
if node.document.attr? 'media', 'prepress'
45+
move_down 225
46+
else
47+
move_down 360
48+
end
49+
layout_heading title, size: @theme.base_font_size
50+
elsif sect_id.include? 'chapter' # chapters
51+
puts 'Processing ' + sect_id + '...'
52+
# use Akkurat font for all custom headings
53+
font 'Akkurat' do
54+
if node.document.attr? 'media', 'prepress'
55+
move_down 120
56+
else
57+
move_down 180
58+
end
59+
if @ppbook
60+
layout_heading 'PART', align: :right, size: 100, style: :normal
61+
else
62+
layout_heading 'PART', align: :right, size: 100, color: [91, 54, 8, 13], style: :normal
63+
end
64+
move_up 40
65+
66+
part_number = 'ONE'
67+
if sect_id.include? 'chapter-2'
68+
part_number = 'TWO'
69+
elsif sect_id.include? 'chapter-3'
70+
part_number = 'THREE'
71+
end
72+
if @ppbook
73+
layout_heading part_number, align: :right, size: 100, style: :bold
74+
layout_heading title, align: :right, style: :normal, size: 30
75+
else
76+
layout_heading part_number, align: :right, size: 100, color: [42, 1, 83, 1], style: :bold
77+
layout_heading title, align: :right, color: [42, 1, 83, 1], style: :normal, size: 30
78+
end
79+
end
80+
81+
bounds.move_past_bottom
82+
else
83+
super # delegate to default implementation
84+
end
85+
end
86+
87+
def layout_heading_custom string, opts = {}
88+
move_down 100
89+
typeset_text string, calc_line_metrics((opts.delete :line_height) || @theme.heading_line_height), {
90+
inline_format: true
91+
}.merge(opts)
92+
move_up 5
93+
i = 0
94+
underline = ''
95+
while i < string.length do
96+
if string == 'Dedication'
97+
underline += '/////'
98+
else
99+
underline += '//////'
100+
end
101+
i += 1
102+
end
103+
if string == 'Dedication'
104+
underline += '////'
105+
end
106+
typeset_text underline, calc_line_metrics((opts.delete :line_height) || @theme.heading_line_height), {
107+
inline_format: true, color: 'B0B0B0', size: 8, style: :italic
108+
}.merge(opts)
109+
move_down 20
110+
end
111+
end
112+
113+
Asciidoctor::Pdf::Converter.prepend AsciidoctorPdfExtensions

‎book/sample.adoc‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ include::chapters/colophon.adoc[]
1010

1111
// Abstract and Dedication MUST have a level-0 heading in EPUB and Kindle
1212
// but level-1 in PDF and HTML
13-
ifndef::backend-epub3[:leveloffset: +1]
13+
// ifndef::backend-epub3[:leveloffset: +1]
14+
// include::chapters/dedication.adoc[]
15+
// ifndef::backend-epub3[:leveloffset: -1]
1416
include::chapters/dedication.adoc[]
15-
ifndef::backend-epub3[:leveloffset: -1]
1617

1718
// (g)
1819
include::chapters/preface.adoc[]

‎minibook/src/docs/asciidoc/chapters/preface.adoc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[preface]
12
= Preface
23

34
== What is in this book?

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /