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').select
{|p
| p
.attributes
['id'].value
== partid
}.each
do |part
|
30 log
0, 'replace article* with book*'
31 xml
.children
[0].name
= 'book'
32 xml
.children
[1].name
= 'book'
33 xml
.css('info').each
do |node
|
34 node
.last_element_child
.after(<<'XML')
37 <holder>Creative Commons</holder>
40 node
.last_element_child
.after(<<'XML')
42 <publishername>Gunnar Wolf</publishername>
43 <address><city>Mexico City</city></address>
47 xml
.css('article').each
do |node
|
52 log
0, 'change parts to colophon, dedication and chapter'
53 partreplace(xml
, 'colophon', 'colophon')
54 partreplace(xml
, 'dedication', 'dedication')
55 partreplace(xml
, 'foreword', 'preface')
56 partreplace(xml
, 'introduction', 'preface')
57 partreplace(xml
, 'bibliography', 'chapter')
58 partreplace(xml
, 'acknowledgments', 'chapter')
60 log
0, 'place part introduction into <partintro>'
61 s
= xml
.search('part title').select
{|tit
| tit
.content
=~
/The Case Studies/}[0]
64 s
.after('<partintro>')
65 p
= xml
.css('part partintro')[0]
66 s
.parent
.children
.select
{|c
| c
.name
== 'para'}.each
do |node
|
70 log
0, 'Adding <partintro> failed!'
74 log 0, 'remove empty notes
/web links sections
'
80 xml.search('title
').select {|t| t.content == title}.each do |node|
83 if p.content =~ /^\s*$/
86 raise RuntimeError, 'Non-empty «
%s» found
' % title
91 log 0, 'remove title from dedication
'
92 xml.css('dedication title
')[0].content = ""
94 log 0, 'move legal notice to bookinfo
'
95 xml.css('book info
')[0].last_element_child.after('<legalnotice
>')
96 ln = xml.css('book info legalnotice
')[0]
97 xml.css('para
').each do |para|
98 if para.content =~ /This book is published under a/
105 log 0, 'replace colophon page with one
for this edition
'
106 xml.search('colophon para
').map {|p| p.remove}
107 s = xml.search('colophon
')[0]
108 s.first_element_child.after(<<'XML')
109 <para>Made with Creative Commons</para>
111 <para>by Paul Stacey & Sarah Hinchliff Pearson</para>
113 <para>© 2017 by the Creative Commons Foundation.</para>
115 <para>Published under a Creative Commons Attribution-ShareAlike
116 license (CC BY-SA), version 4.0.</para>
118 <para>ISBN: YET-TO-BE-DECIDED (PDF), YET-TO-BE-DECIDED (ePub),
119 YET-TO-BE-DECIDED (Paperback) </para>
121 <para>Illustrations by Bryan Mathers,
122 <ulink url="https://bryanmmathers.com/"/>.</para>
124 <para>Publisher: Gunnar Wolf.</para>
127 <!--space for information about translators-->
131 <para>Downloadable e-book available at
132 <ulink url="https://madewith.cc/"/>.</para>
134 <para>This book is published under a CC BY-SA license, which means that you
135 can copy, redistribute, remix, transform, and build upon the content for
136 any purpose, even commercially, as long as you give appropriate credit,
137 provide a link to the license, and indicate if changes were made. If you
138 remix, transform, or build upon the material, you must distribute your
139 contributions under the same license as the original. License details:
140 <ulink url="http://creativecommons.org/licenses/by-sa/4.0/"/></para>
142 <para>Made With Creative Commons is published with the kind support of
143 Creative Commons and backers of our crowdfunding-campaign on the
144 Kickstarter.com platform.</para>
146 <para>This edition of the book is maintained on
147 <ulink url="https://gitlab.com/gunnarwolf/madewithcc-es/"/>, and the
148 translations are maintained on
149 <ulink url="https://hosted.weblate.org/projects/madewithcc/"/>. If
150 you find any error in the book, please let us know via gitlab.</para>
157 (Dewey) 346.048, 347.78
165 (US Library of Congress) Z286 O63 S73 2017
178 log
0, 'remove title from colophon'
179 xml
.css('colophon title')[0].content
= ""
181 log
0, 'change CC logo images to informalfigure'
182 xml
.css('figure mediaobject imageobject imagedata[width="40.0%"]').each
do |id
|
183 f
= id
.parent
.parent
.parent
184 f
.name
= 'informalfigure'
187 log
0, 'assigning IDs to formal figures'
189 xml
.css('figure').each
do |fig
|
190 fig
['id'] = 'fig-%d' % seq
194 # Disabled as dblatex do not understand chapter/chapterinfo/author,
195 # see <URL: https://bugs.debian.org/891183 >.
197 log
0, 'migrate chapter author into <chapterinfo> where relevant'
198 xml
.css('chapter para').each
do |para
|
199 if para
.content
=~
/^\s*((Paul|Sarah Hinchliff) (Stacey|Pearson))\s*$/
200 log
1, 'migrated %s %s' % [$2, $3]
201 para
.parent
.css('title')[0].before(<<'XML' % [$2, $3])
204 <firstname>%s</firstname><surname>%s</surname>
213 log
0, 'Writing processed file (%s)' % dstfile
214 File
.open(dstfile
, 'w') {|f
| f
.write(xml
.to_xml())}