]>
pere.pagekite.me Git - text-madewithcc.git/blob - fixup-docbook.rb
7 raise ArgumentError
, 'Source/destination files not specified' if ARGV.size !
= 2
12 xml
= Nokogiri
::XML(f
)
15 indicators
= %w(! •
# -)
17 print indicators
[level
]
19 print
"\n%s %s\n" % ['*' * (level+
1), what
]
23 def partreplace(xml
, partid
, tag
)
24 xml
.css('part[id=' + partid +
']').each
do |part
|
30 log
0, 'replace article* with book*'
31 xml
.css('articleinfo').each
do |node
|
32 node
.name
= 'bookinfo'
33 node
.last_element_child
.after(<<'XML')
36 <holder>Creative Commons</holder>
39 node
.last_element_child
.after(<<'XML')
41 <publishername>Gunnar Wolf</publishername>
42 <address><city>Mexico City</city></address>
46 xml
.css('article').each
do |node
|
51 log
0, 'change parts to colophon, dedication and chapter'
52 partreplace(xml
, 'colophon', 'colophon')
53 partreplace(xml
, 'dedication', 'dedication')
54 partreplace(xml
, 'foreword', 'preface')
55 partreplace(xml
, 'introduction', 'preface')
56 partreplace(xml
, 'bibliography', 'chapter')
57 partreplace(xml
, 'acknowledgments', 'chapter')
59 log
0, 'place part introduction into <partintro>'
60 s
= xml
.xpath("//part/title[text()='The Case Studies']")[0]
62 s
.after('<partintro>')
63 p
= xml
.css('part partintro')[0]
64 s
.parent
.xpath("//part/para").each
do |node
|
70 log
0, 'remove empty notes/web links sections'
76 xml
.xpath("//title[text()='%s']" % title
).each
do |node
|
79 if p
.content
=~
/^\s*$/
82 raise RuntimeError
, 'Non-empty «%s» found' % title
87 log
0, 'remove title from dedication'
88 if ! xml
.css('dedication title').empty
?
89 xml
.css('dedication title')[0].content
= ""
92 log
0, 'move legal notice to bookinfo'
93 xml
.css('book bookinfo')[0].last_element_child
.after('<legalnotice>')
94 ln
= xml
.css('book bookinfo legalnotice')[0]
95 xml
.css('para').each
do |para
|
96 if para
.content
=~
/This book is published under a/
103 log
0, 'replace colophon page with one for this edition'
104 xml
.xpath('//colophon/para').remove
105 s
= xml
.xpath('//colophon')[0]
106 s
.first_element_child
.after(<<'XML')
107 <para>Made with Creative Commons</para>
109 <para>by Paul Stacey & Sarah Hinchliff Pearson</para>
111 <para>© 2017 by the Creative Commons Foundation.</para>
113 <para>Published under a Creative Commons Attribution-ShareAlike
114 license (CC BY-SA), version 4.0.</para>
116 <para>ISBN: YET-TO-BE-DECIDED (PDF), YET-TO-BE-DECIDED (ePub),
117 YET-TO-BE-DECIDED (Paperback) </para>
119 <para>Illustrations by Bryan Mathers,
120 <ulink url="https://bryanmmathers.com/"/>.</para>
122 <para>Publisher: Gunnar Wolf.</para>
125 <!--space for information about translators-->
129 <para>Downloadable e-book available at
130 <ulink url="https://madewith.cc/"/>.</para>
132 <para>This book is published under a CC BY-SA license, which means that you
133 can copy, redistribute, remix, transform, and build upon the content for
134 any purpose, even commercially, as long as you give appropriate credit,
135 provide a link to the license, and indicate if changes were made. If you
136 remix, transform, or build upon the material, you must distribute your
137 contributions under the same license as the original. License details:
138 <ulink url="http://creativecommons.org/licenses/by-sa/4.0/"/></para>
140 <para>Made With Creative Commons is published with the kind support of
141 Creative Commons and backers of our crowdfunding-campaign on the
142 Kickstarter.com platform.</para>
144 <para>This edition of the book is maintained on
145 <ulink url="https://gitlab.com/gunnarwolf/madewithcc-es/"/>, and the
146 translations are maintained on
147 <ulink url="https://hosted.weblate.org/projects/madewithcc/"/>. If
148 you find any error in the book, please let us know via Gitlab or Weblate.</para>
155 (Dewey) 346.048, 347.78
163 (US Library of Congress) Z286 O63 S73 2017
176 log
0, 'remove title from colophon'
177 xml
.css('colophon title')[0].content
= ""
179 log
0, 'change CC logo images to informalfigure'
180 xml
.css('figure mediaobject imageobject imagedata[width="40.0%"]').each
do |id
|
181 f
= id
.parent
.parent
.parent
182 f
.name
= 'informalfigure'
185 log
0, 'assigning IDs to formal figures'
187 xml
.css('figure').each
do |fig
|
188 fig
['id'] = 'fig-%d' % seq
192 # Disabled as dblatex do not understand chapter/chapterinfo/author,
193 # see <URL: https://bugs.debian.org/891183 >.
195 log
0, 'migrate chapter author into <chapterinfo> where relevant'
196 xml
.css('chapter para').each
do |para
|
197 if para
.content
=~
/^\s*((Paul|Sarah Hinchliff) (Stacey|Pearson))\s*$/
198 log
1, 'migrated %s %s' % [$2, $3]
199 para
.parent
.css('title')[0].before(<<'XML' % [$2, $3])
202 <firstname>%s</firstname><surname>%s</surname>
211 log
0, 'Writing processed file'
212 # Unable to figure out API way to replace DOCTYPE
213 data = xml
.to_xml().gsub!
(/DOCTYPE article/, 'DOCTYPE book')
214 File
.open(dstfile
, 'w') {|f
| f
.write(data)}