]>
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
.first_element_child
.before(<<'XML')
35 <publishername>Gunnar Wolf</publishername>
36 <address><city>Mexico City</city></address>
39 node
.first_element_child
.before(<<'XML')
42 <holder>Creative Commons</holder>
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
|
69 log
0, 'remove title from dedication'
70 xml
.css('dedication title')[0].content
= ""
72 log
0, 'move legal notice to bookinfo'
73 xml
.css('book bookinfo')[0].first_element_child
.before('<legalnotice>')
74 ln
= xml
.css('book bookinfo legalnotice')[0]
75 xml
.css('para').each
do |para
|
76 if para
.content
=~
/This book is published under a/
83 log
0, 'replace colophon page with one for this edition'
84 xml
.xpath('//colophon/para').remove
85 s
= xml
.xpath('//colophon')[0]
86 s
.first_element_child
.after(<<'XML')
87 <para>Made With Creative Commons</para>
89 <para>by Paul Stacey & Sarah Hinchliff Pearson</para>
91 <para>© 2017 by the Creative Commons Foundation.</para>
93 <para>Published under a Creative Commons Attribution-ShareAlike
94 license (CC BY-SA), version 4.0.</para>
96 <para>ISBN: YET-TO-BE-DECIDED (PDF), YET-TO-BE-DECIDED (ePub),
97 YET-TO-BE-DECIDED (Paperback) </para>
99 <para>Illustrations by Bryan Mathers, <ulink url="https://bryanmathers.com/"/></para>
101 <para>Publisher: Gunnar Wolf.</para>
103 <!-- space for information about translators -->
106 <para>Downloadable e-book available at
107 <ulink url="https://madewith.cc/"/></para>
109 <para>This book is published under a CC BY-SA license, which means that you
110 can copy, redistribute, remix, transform, and build upon the content for
111 any purpose, even commercially, as long as you give appropriate credit,
112 provide a link to the license, and indicate if changes were made. If you
113 remix, transform, or build upon the material, you must distribute your
114 contributions under the same license as the original. License details:
115 <ulink url="http://creativecommons.org/licenses/by-sa/4.0/"/></para>
117 <para>Made With Creative Commons is published with the kind support of
118 Creative Commons and backers of our crowdfunding-campaign on the
119 Kickstarter.com platform.</para>
123 log
0, 'change CC logo images to informalfigure'
124 xml
.css('figure mediaobject imageobject imagedata[width="40.0%"]').each
do |id
|
125 f
= id
.parent
.parent
.parent
126 f
.name
= 'informalfigure'
129 log
0, 'Writing processed file'
130 # Unable to figure out API way to replace DOCTYPE
131 data = xml
.to_xml().gsub!
(/DOCTYPE article/, 'DOCTYPE book')
132 File
.open(dstfile
, 'w') {|f
| f
.write(data)}