]>
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>Instituto de Investigaciones Económicas</publishername>
42 <address><city>Universidad Nacional Autónoma de México</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 xml
.css('dedication title')[0].content
= ""
90 log
0, 'move legal notice to bookinfo'
91 xml
.css('book bookinfo')[0].last_element_child
.after('<legalnotice>')
92 ln
= xml
.css('book bookinfo legalnotice')[0]
93 xml
.css('para').each
do |para
|
94 if para
.content
=~
/This book is published under a/
101 log
0, 'replace colophon page with one for this edition'
102 xml
.xpath('//colophon/para').remove
103 s
= xml
.xpath('//colophon')[0]
104 s
.first_element_child
.after(<<'XML')
105 <para>Made with Creative Commons</para>
107 <para>by Paul Stacey & Sarah Hinchliff Pearson</para>
109 <para>© 2017 by the Creative Commons Foundation.</para>
111 <para>Published under a Creative Commons Attribution-ShareAlike
112 license (CC BY-SA), version 4.0.</para>
114 <para>ISBN: YET-TO-BE-DECIDED (PDF), YET-TO-BE-DECIDED (ePub),
115 YET-TO-BE-DECIDED (Paperback) </para>
117 <para>Illustrations by Bryan Mathers,
118 <ulink url="https://bryanmmathers.com/"/>.</para>
120 <para>Publisher: Gunnar Wolf.</para>
123 <!--space for information about translators-->
127 <para>Downloadable e-book available at
128 <ulink url="https://madewith.cc/"/>.</para>
130 <para>This book is published under a CC BY-SA license, which means that you
131 can copy, redistribute, remix, transform, and build upon the content for
132 any purpose, even commercially, as long as you give appropriate credit,
133 provide a link to the license, and indicate if changes were made. If you
134 remix, transform, or build upon the material, you must distribute your
135 contributions under the same license as the original. License details:
136 <ulink url="http://creativecommons.org/licenses/by-sa/4.0/"/></para>
138 <para>Made With Creative Commons is published with the kind support of
139 Creative Commons and backers of our crowdfunding-campaign on the
140 Kickstarter.com platform.</para>
142 <para>This edition of the book is maintained on
143 <ulink url="https://gitlab.com/gunnarwolf/madewithcc-es/"/>, and the
144 translations are maintained on
145 <ulink url="https://hosted.weblate.org/projects/madewithcc/"/>. If
146 you find any error in the book, please let us know via Gitlab or Weblate.</para>
153 (Dewey) 346.048, 347.78
161 (US Library of Congress) Z286 O63 S73 2017
174 log
0, 'remove title from colophon'
175 xml
.css('colophon title')[0].content
= ""
177 log
0, 'change CC logo images to informalfigure'
178 xml
.css('figure mediaobject imageobject imagedata[width="40.0%"]').each
do |id
|
179 f
= id
.parent
.parent
.parent
180 f
.name
= 'informalfigure'
183 log
0, 'assigning IDs to formal figures'
185 xml
.css('figure').each
do |fig
|
186 fig
['id'] = 'fig-%d' % seq
190 # Disabled as dblatex do not understand chapter/chapterinfo/author,
191 # see <URL: https://bugs.debian.org/891183 >.
193 log
0, 'migrate chapter author into <chapterinfo> where relevant'
194 xml
.css('chapter para').each
do |para
|
195 if para
.content
=~
/^\s*((Paul|Sarah Hinchliff) (Stacey|Pearson))\s*$/
196 log
1, 'migrated %s %s' % [$2, $3]
197 para
.parent
.css('title')[0].before(<<'XML' % [$2, $3])
200 <firstname>%s</firstname><surname>%s</surname>
209 log
0, 'Writing processed file'
210 # Unable to figure out API way to replace DOCTYPE
211 data = xml
.to_xml().gsub!
(/DOCTYPE article/, 'DOCTYPE book')
212 File
.open(dstfile
, 'w') {|f
| f
.write(data)}