mkbok 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2012 Larry Cai
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.rdoc CHANGED
@@ -5,8 +5,7 @@
5
5
  Author:: Larry Cai (mailto:larry.caiyu@gmail.com)
6
6
 
7
7
  Copyright:: Copyright (c) 2012 by Larry Cai
8
- License:: Distributes under the Apache License,
9
- see LICENSE.txt in the source distro
8
+ License:: Distributes under the Apache License 2.0, see LICENSE in the source distro
10
9
 
11
10
  This application generate ebooks (.pdf,.epub,.mobi) from markdown plaintext files
12
11
 
data/bin/mkbok CHANGED
@@ -13,8 +13,11 @@ def main()
13
13
  options = {
14
14
  "build"=> "pdf",
15
15
  "lang" => "zh",
16
- "config" => "latex/config.yml",
17
- "template" => "latex/template.tex"
16
+ "config" => "latex/config.yml",
17
+ "template" => "latex/template.tex",
18
+ "chapter-files" => "*/*.markdown",
19
+ "appendix-files"=> "*appendix/*.markdown",
20
+ "jeykll" => false
18
21
  }
19
22
  config_file = File.join('.mkbok.yml')
20
23
  if File.exists? config_file
@@ -140,21 +143,23 @@ end
140
143
 
141
144
  def pre_pandoc(string, config)
142
145
  replace(string) do
143
- s /\#\#\#\#\# (.*?) \#\#\#\#\#/, 'PARASECTION: \1'
146
+ s /\#\#\#\#\# (.*?) \#\#\#\#\#/, 'PARASECTION: \1'
144
147
  # Pandoc discards #### subsubsections #### - this hack recovers them
145
148
  s /\#\#\#\# (.*?) \#\#\#\#/, 'SUBSUBSECTION: \1'
146
149
 
150
+ # convert div figures to normal markdown format
151
+ # http://johnmacfarlane.net/pandoc/README.html
152
+ s /^<div class=\"figures\"> <img src=\"..\/figures\/(.*)\".*<\/div>/, '![](figures/\1)\ '
153
+ # "
147
154
  # Turns URLs into clickable links
148
155
  s /\`(http:\/\/[A-Za-z0-9\/\%\&\=\-\_\\\.]+)\`/, '<\1>'
149
156
  s /(\n\n)\t(http:\/\/[A-Za-z0-9\/\%\&\=\-\_\\\.]+)\n([^\t]|\t\n)/, '\1<\2>\1'
150
-
157
+ # `
151
158
  # Process figures
152
159
  s /Insert\s18333fig\d+\.png\s*\n.*?\d{1,2}-\d{1,2}\. (.*)/, 'FIG: \1'
153
160
  end
154
161
  end
155
162
 
156
- # `
157
-
158
163
  def post_pandoc(string, config, lang, chapter=true)
159
164
  replace(string) do
160
165
  space = /\s/
@@ -209,6 +214,9 @@ def post_pandoc(string, config, lang, chapter=true)
209
214
  else
210
215
  s /(^\\item)/m,'\item[*]'
211
216
  end
217
+
218
+ # change the width to standard .6 width
219
+ s /\\includegraphics/m, '\\includegraphics[width=\\imgwidth]'
212
220
  end
213
221
 
214
222
  if chapter != true
@@ -220,6 +228,10 @@ def post_pandoc(string, config, lang, chapter=true)
220
228
  end
221
229
  end
222
230
 
231
+ def check_jekyll(str)
232
+ str.lines.to_a[4..-3].join
233
+ end
234
+
223
235
  def generate_pdf(options)
224
236
  $config = YAML.load_file(options["config"])
225
237
  template = ERB.new(File.read(options["template"]))
@@ -240,10 +252,17 @@ def generate_pdf(options)
240
252
  config = $config['default'].merge($config[lang]) rescue $config['default']
241
253
 
242
254
  puts "#{lang}:"
243
- puts "\tParsing preface markdown... "
244
- prefacemarkdown = Dir["#$root/#{lang}/*preface/*.markdown"].sort.map do |file|
255
+
256
+ prefacefiles = "#$root/#{lang}/#{options['preface-files']}"
257
+
258
+ puts "\tParsing preface markdown... #{prefacefiles} "
259
+ prefacemarkdown = Dir["#{prefacefiles}"].sort.map do |file|
245
260
  puts "\t =>"+file
246
- File.read(file)
261
+ if options["jeykll"]
262
+ check_jekyll(File.read(file))
263
+ else
264
+ File.read(file)
265
+ end
247
266
  end.join("\n\n")
248
267
 
249
268
  preface = IO.popen('pandoc -p --no-wrap -f markdown -t latex', 'w+') do |pipe|
@@ -252,17 +271,17 @@ def generate_pdf(options)
252
271
  post_pandoc(pipe.read, config, lang, false)
253
272
  end
254
273
 
255
- puts "\n\tParsing main chapters markdown... "
256
- found = false
257
- chaptersmarkdown = Dir["#$root/#{lang}/*chapters/*.markdown"].sort.map do |file|
258
- found = true
274
+ chapterfiles = "#$root/#{lang}/#{options['chapter-files']}"
275
+
276
+ puts "\n\tParsing main chapters markdown... #{chapterfiles} "
277
+ chaptersmarkdown = Dir["#{chapterfiles}"].sort{|a,b| [Integer(a[/\d+/]),a]<=>[Integer(b[/\d+/]),b]}.map do |file|
259
278
  puts "\t =>"+file
260
- File.read(file)
279
+ if options["jeykll"]
280
+ check_jekyll(File.read(file))
281
+ else
282
+ File.read(file)
283
+ end
261
284
  end.join("\n\n")
262
- chaptersmarkdown = Dir["#$root/#{lang}/*/*.markdown"].sort.map do |file|
263
- puts "\t =>"+file
264
- File.read(file)
265
- end.join("\n\n") unless found
266
285
  # puts "done"
267
286
 
268
287
  latex = IO.popen('pandoc -p --no-wrap -f markdown -t latex', 'w+') do |pipe|
@@ -272,11 +291,17 @@ def generate_pdf(options)
272
291
  end
273
292
  # puts "done"
274
293
 
275
- puts "\n\tParsing appendix markdown... "
276
- appendixmarkdown = Dir["#$root/#{lang}/*appendix/*.markdown"].sort.map do |file|
277
- puts "\t =>"+file
278
- File.read(file)
279
- end.join("\n\n")
294
+ appendixfiles = "#$root/#{lang}/#{options['appendix-files']}"
295
+
296
+ puts "\n\tParsing appendix markdown... #{appendixfiles} "
297
+ appendixmarkdown = Dir["#{appendixfiles}"].sort.map do |file|
298
+ puts "\t =>"+file
299
+ if options["jeykll"]
300
+ check_jekyll(File.read(file))
301
+ else
302
+ File.read(file)
303
+ end
304
+ end.join("\n\n")
280
305
 
281
306
  appendix = IO.popen('pandoc -p --no-wrap -f markdown -t latex', 'w+') do |pipe|
282
307
  pipe.write(pre_pandoc(appendixmarkdown, config))
@@ -374,6 +399,8 @@ def generate_ebook(options)
374
399
  options["outputformat"].each do | format |
375
400
  system('pandoc',
376
401
  '--standalone',
402
+ '--toc',
403
+ '--template=template.html',
377
404
  '--epub-metadata', 'epub/metadata.xml',
378
405
  '--epub-stylesheet', 'epub/book.css', # this doesn't work
379
406
  '--output', "#{name}.#{lang}.#{format}",
@@ -407,7 +434,10 @@ def generate_project(project)
407
434
  else
408
435
  FileUtils.mkdir_p(File.join(destination, relative.dirname))
409
436
  if pathname.extname == '.erb'
410
- File.open(destination.join(pathname.basename.sub(/\.erb$/, '')), 'w') do |file|
437
+ #puts pathname.basename.sub(/\.erb$/, '')
438
+ #puts destination
439
+ #puts File.join(destination,pathname.basename.sub(/\.erb$/, ''))
440
+ File.open(File.join(destination,pathname.basename.sub(/\.erb$/, '')), 'w') do |file|
411
441
  file.puts(ERB.new(File.read(path)).result(binding))
412
442
  end
413
443
  else
@@ -417,5 +447,6 @@ def generate_project(project)
417
447
  end
418
448
  end
419
449
  end
450
+
420
451
  main
421
452
 
data/lib/mkbok_version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MkBok
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.14'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  # Software Development Book Contents#
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/larrycai/kaiyuanbook.png)](http://travis-ci.org/larrycai/kaiyuanbook)
3
+ [![Build Status](https://secure.travis-ci.org/larrycai/kaiyuanbook.png)](http://travis-ci.org/larrycai/<%= project %>)
4
4
 
5
5
  This is the book for how to write opensource books, it covers markdown,pandoc,latex
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkbok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-13 00:00:00.000000000 Z
12
+ date: 2012-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aruba
16
- requirement: &25098168 !ruby/object:Gem::Requirement
16
+ requirement: &24856032 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.4.6
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *25098168
24
+ version_requirements: *24856032
25
25
  description: the ebook generate tools from markdown plain text
26
26
  email:
27
27
  - larry.caiyu@gmail.com
@@ -42,7 +42,7 @@ files:
42
42
  - templates/latex/README
43
43
  - templates/latex/template.tex
44
44
  - templates/Rakefile
45
- - templates/README.md
45
+ - templates/README.md.erb
46
46
  - templates/summary.rb
47
47
  - templates/zh/appendix/02-chapter1.markdown
48
48
  - templates/zh/chapters/01-chapter2.markdown
@@ -50,6 +50,7 @@ files:
50
50
  - templates/zh/chapters/01-chapter4.markdown
51
51
  - templates/zh/preface/01-chapter1.markdown
52
52
  - README.rdoc
53
+ - LICENSE
53
54
  homepage: http://github.com/larrycai/mkbok
54
55
  licenses: []
55
56
  post_install_message:
@@ -75,3 +76,4 @@ signing_key:
75
76
  specification_version: 3
76
77
  summary: tools to generate ebooks from markdown
77
78
  test_files: []
79
+ has_rdoc: