]>
pere.pagekite.me Git - text-madewithcc.git/blob - fixup.rb
4 raise ArgumentError
, 'Source/destination files not specified' if ARGV.size !
= 2
8 data=File
.open(srcfile
).readlines
.map
{|l
| l
.chomp!
}
10 data.map
{|lin
| lin
.gsub!
(/\[\]{#anchor-?\d*}/, '')}
13 indicators
= %w(! •
# -)
15 print indicators
[level
]
17 print
"\n%s %s\n" % ['*' * (level+
1), what
]
21 # There are several titles that are spread in more than one line. Make
22 # them into translatable sentences.
23 log
0, 'Merging multiline sentences '
24 [ ['Made', '', 'with', '', 'Creative', '', 'Commons'],
25 ['The New','', 'World of', '', 'Digital', '', 'Commons'],
26 ['How', '', 'to Be', '', 'Made with', '', 'Creative', '', 'Commons'],
27 ['Providing a custom service to consumers of your work *', '\[MARKET-BASED\]*'],
28 ['Memberships and individual donations', '*\[RECIPROCITY-BASED\]*'],
29 ['The', '', 'Creative', '', 'Commons', '', 'Licenses'],
30 ['PLOS','', '(Public Library of Science)']
32 # This should be done more generic, more robust... But before
33 # burning brain cells, verify if it's needed!
36 data.each_with_index
do |lin
, idx
|
42 raise RuntimeError
, 'Anchor string («%s» for «%s») not found' %
43 [str
[0], str
.reject
{|word
| word
==''}.join(' ')]
44 elsif matches
.size
> 1
45 raise RuntimeError
, 'Anchor string (%s) appears multiple times: %s' %
46 [str
[0], matches
.map
{|i
| i
.to_s
}.join(', ')]
48 log
2, 'Matches %s: %d - %s' % [str
.join(' '), matches
.size
, matches
.join(',')]
51 at
= data.index(str
[0])
52 joined
= str
.reject
{|word
| word
==''}.join(' ')
54 if str
[offset
] !
= data[at+offset
]
56 'Warning: String does not match ("%s" of "%s", offset %d, book at %d)' %
57 [str
[offset
], joined
, offset
, at+offset
]
62 (str
.size
- 1).times
{ data.delete_at(at+
1) }
65 # Mark up headings: Very artisanal and suboptimal, but should do the
68 # For every heading, put here the full string and its heading level,
76 # Try to keep this ordered as it appears within the book, as it will
77 # help us spot omissions and mistakes!
78 log
0, 'Mark up headings'
82 [1, 'The Big Picture'],
83 [2, 'The New World of Digital Commons'],
84 [3, 'The Commons, the Market, and the State'],
85 [3, 'The Four Aspects of a Resource'],
86 [4, 'Characteristics'],
87 [4, 'People and processes'],
88 [4, 'Norms and rules'],
90 [3, 'A Short History of the Commons'],
91 [3, 'The Digital Revolution'],
92 [3, 'The Birth of Creative Commons'],
93 [3, 'The Changing Market'],
94 [3, 'Benefits of the Digital Commons'],
95 [3, 'Our Case Studies'],
97 [2, 'How to Be Made with Creative Commons'],
98 [3, 'Problem Zero: Getting Discovered'],
99 [4, 'Use CC to grow a larger audience'],
100 [4, 'Use CC to get attribution and name recognition'],
101 [4, 'Use CC-licensed content as a marketing tool'],
102 [4, 'Use CC to enable hands-on engagement with your work'],
103 [4, 'Use CC to differentiate yourself'],
105 [4, 'Market-based revenue streams'],
106 [4, 'Providing a custom service to consumers of your work * \[MARKET-BASED\]*'],
107 [4, 'Charging for the physical copy * \[MARKET-BASED\]*'],
108 [4, 'Charging for the in-person version * \[MARKET-BASED\]*'],
109 [4, 'Selling merchandise * \[MARKET-BASED\]*'],
110 [4, 'Charging advertisers or sponsors * \[MARKET-BASED\]*'],
111 [4, 'Charging your content creators * \[MARKET-BASED\]*'],
112 [4, 'Charging a transaction fee * \[MARKET-BASED\]*'],
113 [4, 'Providing a service to your creators* \[MARKET-BASED\]*'],
114 [4, 'Licensing a trademark* \[MARKET-BASED\]*'],
115 [4, 'Reciprocity-based revenue streams'],
116 [4, 'Memberships and individual donations *\[RECIPROCITY-BASED\]*'],
117 [4, 'The pay-what-you-want model *\[RECIPROCITY-BASED\]*'],
118 [4, 'Crowdfunding *\[RECIPROCITY-BASED\]*'],
119 [3, 'Making Human Connections'],
121 [4, 'Be open and accountable'],
122 [4, 'Design for the good actors'],
123 [4, 'Treat humans like, well, humans'],
124 [4, 'State your principles and stick to them'],
125 [4, 'Build a community'],
126 [4, 'Give more to the commons than you take'],
127 [4, 'Involve people in what you do'],
129 [2, 'The Creative Commons Licenses'],
131 [1, 'The Case Studies'],
134 [2, 'Blender Institute'],
135 [2, 'Cards Against Humanity'],
136 [2, 'The Conversation'],
137 [2, 'Cory Doctorow'],
140 [2, 'Knowledge Unlatched'],
141 [2, 'Lumen Learning'],
142 [2, 'Jonathan Mann'],
144 [2, 'Open Data Institute'],
147 [2, 'Amanda Palmer'],
148 [2, 'PLOS (Public Library of Science)'],
154 [2, 'Tribe of Noise'],
155 [2, 'Wikimedia Foundation'],
157 [2, 'Acknowledgments'],
160 log
1, item
.join(' -> ')
161 at
= data.index
{|i
| i
== item
[1]}
163 raise RuntimeError
, 'Heading string (level %d) not found: «%s»' % item
165 data[at
] = '%s %s' % ['#' * item
[0], data[at
]]
170 # Join erroneously split paragraphs: Write the contents of the line
171 # _preceding_ the unneeded break, the break will be removed.
172 log
0, 'Join erroneously split paragraphs'
173 ['content and, in turn, spend money and',
175 'content functions as a marketing tool for the paid product or',
176 'to the values symbolized by',
177 'the kinds of participative communities that drive open',
178 'At a minimum, a CC-',
180 'free download, the',
181 'openness to fans remixing the game—give',
183 'both journal publishers and researchers. Figshare now provides',
184 'get the “network effect”—',
185 'access to scholarly books. For Frances, the current scholarly-',
188 'contributing to the open',
189 'doesn’t seem like it should be sung about',
190 'songwriter, and he has found a way to keep it interesting for',
191 'building trust is the top',
193 'authors and Shuttleworth; Mark remains incredibly proud of this',
194 'BY-SA and opting in others with collecting societies like',
195 'Cecilie Maria, Cedric Howe, Cefn Hoile,',
196 'Braddlee, Drew Spencer, Duncan',
197 'Elizabeth Holloway, Ellen Buecher, Ellen Kaye-',
201 at
= data.index
{|i
| i
== line
}
202 if !at
.nil? and data[at+
1] == ''
207 log
0, 'Writing processed file'
208 File
.open(dstfile
, 'w') {|f
| f
.puts
data.join("\n")}