mkbok 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/mkbok CHANGED
@@ -5,6 +5,7 @@ require 'optparse'
5
5
  require 'fileutils'
6
6
  require 'erb'
7
7
  require 'yaml'
8
+ require 'pathname'
8
9
 
9
10
  include FileUtils
10
11
 
@@ -65,6 +66,13 @@ def main()
65
66
  end
66
67
  options["name"] = name
67
68
  end
69
+ opts.on("-g","--generate project","project name") do |name|
70
+ unless name =~ /^[a-zA-Z0-9]+$/
71
+ raise ArgumentError,"name should be [a-zA-Z0-9]"
72
+ end
73
+ options["command"] = "generate"
74
+ options["name"] = name
75
+ end
68
76
  end
69
77
 
70
78
  option_parser.parse!
@@ -77,7 +85,12 @@ def main()
77
85
  options["outputformat"] = options["build"].split(',')
78
86
 
79
87
  puts options.inspect if options["debug"]
80
-
88
+
89
+ if options["command"] == "generate"
90
+ generate_project(options["name"])
91
+ exit
92
+ end
93
+
81
94
  if options["outputformat"].include?("pdf")
82
95
  #puts "pdf"
83
96
  generate_pdf(options)
@@ -372,5 +385,37 @@ def generate_ebook(options)
372
385
  end
373
386
  end
374
387
 
388
+ # http://stackoverflow.com/questions/5074327/most-appropriate-way-to-generate-directory-of-files-from-directory-of-template-f
389
+ def generate_project(project)
390
+ destination = project
391
+ source = File.dirname(__FILE__)+"/../templates"
392
+ #puts "generate project \"#{destination}\" from source \"#{source}\""
393
+ FileUtils.rmtree(destination)
394
+ FileUtils.mkdir_p(destination)
395
+ sourceroot=Pathname.new(source)
396
+ sourcerealpath = sourceroot.cleanpath
397
+ puts "generate project \"#{destination}\" from source \"#{sourcerealpath}\""
398
+ Dir.glob(File.join(source, '**/*')).each do |path|
399
+ pathname = Pathname.new(path)
400
+ relative = pathname.relative_path_from(sourceroot)
401
+ #puts "parent:" , sourceroot
402
+ #puts "relative:", relative
403
+ if File.directory?(pathname)
404
+ destdir = File.join(destination, relative.dirname)
405
+ #puts "create #{destdir} "
406
+ FileUtils.mkdir_p(destdir)
407
+ else
408
+ FileUtils.mkdir_p(File.join(destination, relative.dirname))
409
+ if pathname.extname == '.erb'
410
+ File.open(destination.join(pathname.basename.sub(/\.erb$/, '')), 'w') do |file|
411
+ file.puts(ERB.new(File.read(path)).result(binding))
412
+ end
413
+ else
414
+ print pathname.cleanpath, " => ", File.join(destination, relative.dirname),"\n"
415
+ FileUtils.cp(pathname, File.join(destination, relative.dirname))
416
+ end
417
+ end
418
+ end
419
+ end
375
420
  main
376
421
 
data/lib/mkbok_version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MkBok
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
@@ -0,0 +1,43 @@
1
+ # Introduction #
2
+
3
+ As open source books, ebooks and pdf format should be created on fly, the following sections describe those solution in detail.
4
+
5
+ The solution below is based on [Pro Git][progit]; while it is little updated on format inside.
6
+
7
+ # Making Pdf books #
8
+ PDF format is used to read/print in nice way like real book, [pandoc][pandoc] good at this and it is used instead to generate latex from markdown, and latex tool `xelatex` (is part of [TexLive][texlive] now) is used to convert pdf from latex.
9
+
10
+ Please check [ctax](http://www.ctan.org/) and [TexLive][texlive] for more background for latex, which is quite complicated and elegant if you have never touched before.
11
+
12
+ ## Ubuntu Platform ##
13
+
14
+ Ubuntu Platform Oneiric (11.10) is used mainly due to pandoc.
15
+
16
+ [pandoc][pandoc] can be installed directly from source, which version is 1.8.x. If you use Ubuntu 11.04, then it is just 1.5.x.
17
+
18
+ Though texlive 2011 can be installed separately, the default one texlive 2009 from Ubuntu repository is good enough so far.
19
+
20
+ $ sudo apt-get install ruby1.9.1
21
+ $ sudo apt-get install pandoc
22
+ $ sudo apt-get install texlive-xetex
23
+ $ sudo apt-get install texlive-latex-recommended # main packages
24
+ $ sudo apt-get install texlive-latex-extra # package titlesec
25
+
26
+ You need to install related fonts for Chinese, fortunately they exist in ubuntu source also.
27
+
28
+ $ sudo apt-get install ttf-arphic-gbsn00lp ttf-arphic-ukai # from arphic
29
+ $ sudo apt-get install ttf-wqy-microhei ttf-wqy-zenhei # from WenQuanYi
30
+
31
+ Then it should work perfectly
32
+
33
+ $ ./mkbok
34
+
35
+ Just remind you, some [extra pandoc markdown format](http://johnmacfarlane.net/pandoc/README.html) is used inside this book:
36
+
37
+ * code syntax highlight (doesn't work in pdf, while it should work in html/epub which needed later)
38
+ * footnote
39
+
40
+ [pandoc]: http://johnmacfarlane.net/pandoc/
41
+ [calibre]: http://calibre-ebook.com/
42
+ [progit]: http://github.com/progit/progit
43
+ [texlive]: http://www.tug.org/texlive/
@@ -0,0 +1,20 @@
1
+ # Software Development Book Contents#
2
+
3
+ [![Build Status](https://secure.travis-ci.org/larrycai/kaiyuanbook.png)](http://travis-ci.org/larrycai/kaiyuanbook)
4
+
5
+ This is the book for how to write opensource books, it covers markdown,pandoc,latex
6
+
7
+ Hope you enjoy it, I hope it helps you learn better software development.
8
+
9
+ Please check BUILD.md for how to making ebooks by yourself,
10
+
11
+ credit to [Pro Git](http://github.com/progit/progit)
12
+
13
+ #Errata#
14
+
15
+ If you see anything that is technically wrong or otherwise in need of
16
+ correction, please email me at larry dot caiyu at gmail dot com to inform me.
17
+
18
+ ### License
19
+ The license is under ![](http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png), see [CC BY NC ND 3.0](http://creativecommons.org/licenses/by-nc-nd/3.0/) for more
20
+
@@ -0,0 +1,160 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rake/clean'
4
+
5
+
6
+ $lang = ENV['language']
7
+ $lang ||= 'en'
8
+
9
+ namespace :epub do
10
+ TMP_DIR = File.join('epub', 'temp', $lang)
11
+ INDEX_FILEPATH = File.join(TMP_DIR, 'sdcamp.html')
12
+ TARGET_FILEPATH = "sdcamp-#{$lang}.epub"
13
+
14
+ SOURCE_FILES = FileList.new(File.join($lang, '**', '*.markdown')).sort
15
+ CONVERTED_MK_FILES = SOURCE_FILES.pathmap(File.join(TMP_DIR, '%f'))
16
+ HTML_FILES = CONVERTED_MK_FILES.ext('html')
17
+
18
+ desc "generate EPUB ebook (add language=xx to build lang xx)"
19
+ task :generate => :check
20
+ task :generate => TARGET_FILEPATH
21
+
22
+ desc "check whether all the required tools are installed"
23
+ task :check do
24
+ begin
25
+ require 'maruku'
26
+ found_maruku = true
27
+ rescue LoadError
28
+ found_maruku = false
29
+ end
30
+
31
+ $ebook_convert_cmd = ENV['ebook_convert_path'].to_s
32
+ if $ebook_convert_cmd.empty?
33
+ $ebook_convert_cmd = `which ebook-convert`.chomp
34
+ end
35
+ if $ebook_convert_cmd.empty?
36
+ mac_osx_path = '/Applications/calibre.app/Contents/MacOS/ebook-convert'
37
+ $ebook_convert_cmd = mac_osx_path
38
+ end
39
+ found_calibre = File.executable?($ebook_convert_cmd)
40
+
41
+ if !found_maruku
42
+ puts 'EPUB generation requires the Maruku gem.'
43
+ puts ' On Ubuntu call "sudo apt-get install libmaruku-ruby".'
44
+ end
45
+ if !found_calibre
46
+ puts 'EPUB generation requires Calibre.'
47
+ puts ' On Ubuntu call "sudo apt-get install calibre".'
48
+ end
49
+
50
+ if !found_calibre || !found_maruku then exit 1 end
51
+ end
52
+
53
+ directory TMP_DIR
54
+
55
+ rule '.html' => '.mk' do |t|
56
+ require 'maruku'
57
+
58
+ mk_filename = t.source
59
+ html_filename = t.name
60
+ puts "Converting #{mk_filename} -> #{html_filename}"
61
+
62
+ mk_file = File.open(mk_filename, 'r') do |mk|
63
+ html_file = File.open(html_filename, 'w') do |html|
64
+ code = Maruku.new(mk.read.encode("UTF-8")).to_html
65
+ code.gsub!(/^(<h.) (id='[^']+?')/, '\1')
66
+ html << code
67
+ html << "\n"
68
+ end
69
+ end
70
+ end
71
+
72
+ src_for_converted = proc do |dst|
73
+ base_name = dst.pathmap('%n')
74
+ SOURCE_FILES.find { |s| s.pathmap('%n') == base_name }
75
+ end
76
+
77
+ rule '.mk' => src_for_converted do |t|
78
+ src_filename = t.source
79
+ dest_filename = t.name
80
+ puts "Processing #{src_filename} -> #{dest_filename}"
81
+
82
+ figures_dir = "../../../figures"
83
+
84
+ dest_file = File.open(dest_filename, 'w')
85
+ src_file = File.open(src_filename, 'r')
86
+ until src_file.eof?
87
+ line = src_file.readline
88
+
89
+ matches = line.match /^\s*Insert\s(.*)/
90
+ if matches
91
+ image_path = matches[1]
92
+ real_image_path = image_path.pathmap("#{figures_dir}/%X-tn%x")
93
+
94
+ next_line = src_file.readline.chomp
95
+
96
+ line = "![#{next_line}](#{real_image_path} \"#{next_line}\")\n"
97
+ end
98
+
99
+ dest_file << line
100
+ end
101
+ src_file.close
102
+ dest_file.close
103
+ end
104
+
105
+ file INDEX_FILEPATH => TMP_DIR
106
+ file INDEX_FILEPATH => HTML_FILES do
107
+ index_file = File.open(INDEX_FILEPATH, 'w') do |file|
108
+ file << '<?xml version="1.0" encoding="UTF-8"?>'
109
+ file << "\n"
110
+ file << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '
111
+ file << '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
112
+ file << "\n"
113
+ file << "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='#{$lang}'>"
114
+ file << '<head>'
115
+ file << '<title>Pro Git - professional version control</title>'
116
+ file << '</head>'
117
+ file << '<body>'
118
+ file << "\n"
119
+
120
+ HTML_FILES.each do |chapter_file|
121
+ file << File.open(chapter_file).read
122
+ file << "\n"
123
+ end
124
+
125
+ file << '</body></html>'
126
+ file << "\n"
127
+ end
128
+ end
129
+
130
+ file TARGET_FILEPATH => INDEX_FILEPATH do
131
+ opts = [
132
+ '--language', $lang,
133
+ '--authors', 'Scott Chacon',
134
+ '--comments', 'Licensed under the Creative Commons Attribution-Non Commercial-Share Alike 3.0 license',
135
+
136
+ '--cover', 'epub/title.png',
137
+ '--extra-css', 'epub/ProGit.css',
138
+
139
+ '--chapter', '//h:h1',
140
+ '--level1-toc', '//h:h1',
141
+ '--level2-toc', '//h:h2',
142
+ '--level3-toc', '//h:h3',
143
+ ]
144
+
145
+ sh $ebook_convert_cmd, INDEX_FILEPATH, TARGET_FILEPATH, *opts
146
+ end
147
+
148
+ CLEAN.push(*CONVERTED_MK_FILES)
149
+ CLEAN.push(*HTML_FILES)
150
+ CLEAN << INDEX_FILEPATH
151
+ CLEAN << TMP_DIR
152
+ CLOBBER << TARGET_FILEPATH
153
+ end
154
+
155
+ namespace :pdf do
156
+ desc "generate a pdf"
157
+ task :generate do
158
+ system("ruby makepdfs")
159
+ end
160
+ end
@@ -0,0 +1,28 @@
1
+ ul {
2
+ margin: 20px;
3
+ }
4
+
5
+ ol {
6
+ margin: 20px;
7
+ }
8
+
9
+ body pre {
10
+ margin: 10px;
11
+ font-weight: bold;
12
+ }
13
+
14
+ body pre2 {
15
+ background-color: silver;
16
+ padding: 10px;
17
+ border-top-style: solid;
18
+ border-left-style: solid;
19
+ border-left-width: 1px;
20
+ border-top-width: 1px;
21
+ overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
22
+ white-space: pre-wrap; /* css-3 */
23
+ white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
24
+ white-space: -pre-wrap; /* Opera 4-6 */
25
+ white-space: -o-pre-wrap; /* Opera 7 */
26
+ /* width: 99%; */
27
+ word-wrap: break-word; /* Internet Explorer 5.5+ */
28
+ }
@@ -0,0 +1,2 @@
1
+ <dc:rights>Creative Commons Non-Commercial Share Alike 3.0</dc:rights>
2
+ <dc:language>zh</dc:language>
@@ -0,0 +1,45 @@
1
+ <mockup version="1.0" skin="sketch" measuredW="1052" measuredH="1382" mockupW="1052" mockupH="1382">
2
+ <controls>
3
+ <control controlID="2" controlTypeID="com.balsamiq.mockups::Title" x="78" y="512" w="-1" h="-1" measuredW="664" measuredH="87" zOrder="2" locked="false" isInGroup="-1">
4
+ <controlProperties>
5
+ <color>16777215</color>
6
+ <size>72</size>
7
+ <text>Software%20Development</text>
8
+ </controlProperties>
9
+ </control>
10
+ <control controlID="4" controlTypeID="com.balsamiq.mockups::Canvas" x="3" y="498" w="807" h="334" measuredW="100" measuredH="70" zOrder="1" locked="false" isInGroup="-1">
11
+ <controlProperties>
12
+ <backgroundAlpha>0.75</backgroundAlpha>
13
+ <borderColor>0</borderColor>
14
+ <color>545684</color>
15
+ </controlProperties>
16
+ </control>
17
+ <control controlID="5" controlTypeID="com.balsamiq.mockups::Canvas" x="187" y="0" w="651" h="50" measuredW="100" measuredH="70" zOrder="5" locked="false" isInGroup="-1">
18
+ <controlProperties>
19
+ <backgroundAlpha>0.75</backgroundAlpha>
20
+ <borderColor>0</borderColor>
21
+ <color>545684</color>
22
+ </controlProperties>
23
+ </control>
24
+ <control controlID="6" controlTypeID="com.balsamiq.mockups::TextArea" x="0" y="0" w="1052" h="1382" measuredW="200" measuredH="140" zOrder="0" locked="false" isInGroup="-1">
25
+ <controlProperties>
26
+ <text/>
27
+ </controlProperties>
28
+ </control>
29
+ <control controlID="7" controlTypeID="com.balsamiq.mockups::Label" x="512" y="716" w="413" h="61" measuredW="218" measuredH="39" zOrder="3" locked="false" isInGroup="-1">
30
+ <controlProperties>
31
+ <italic>true</italic>
32
+ <size>28</size>
33
+ <text>Learning%20in%204%20days</text>
34
+ </controlProperties>
35
+ </control>
36
+ <control controlID="8" controlTypeID="com.balsamiq.mockups::Label" x="708" y="1272" w="-1" h="-1" measuredW="132" measuredH="43" zOrder="4" locked="false" isInGroup="-1">
37
+ <controlProperties>
38
+ <color>6710886</color>
39
+ <italic>true</italic>
40
+ <size>32</size>
41
+ <text>Larry%20Cai</text>
42
+ </controlProperties>
43
+ </control>
44
+ </controls>
45
+ </mockup>
@@ -0,0 +1,27 @@
1
+ PDF Version of Pro Git
2
+ ======================
3
+
4
+ To get a PDF version of Pro Git in English, run `makepdf en` and a file called
5
+ `progit.en.pdf` will appear in the root of the project. `makepdf` required
6
+ pandoc and XeTeX as dependencies.
7
+
8
+ * `config.yml`: this is a simple configuration file which allows you to
9
+ specify language-specific customisations.
10
+ * `template.tex`: this is the main LaTeX file which determines the style of the
11
+ PDF version of the book. Its contents is run through the ERB templating
12
+ language to include language-specific customisations from config.yml.
13
+
14
+
15
+ For Windows
16
+ ===========
17
+
18
+ Windows build is tested with Pandoc 1.8 and MixTeX 2.9. Install MixTeX with all
19
+ font options. Only `en` has been tested so far. To make it work, it needs some
20
+ tweaks.
21
+
22
+ * `pandoc` and `xelatex` binaries must be on the PATH
23
+ * Change the default fonts in `config.yml` to something that exists in Windows.
24
+ Example for working fonts:
25
+ font: Latin Modern Roman
26
+ mono: Courier
27
+ bold: "{*}"
@@ -0,0 +1,138 @@
1
+ default:
2
+ title: Learn writing opensource book
3
+ font: Liberation Serif
4
+ bold: "{* Bold}"
5
+ mono: Liberation Mono
6
+ prechap: "Chapter "
7
+ postchap: ""
8
+ presect: "Section "
9
+ postsect: ""
10
+ dql: "“"
11
+ dqr: "”"
12
+ con: "Contents"
13
+ fig: "Figure "
14
+ tab: "Table "
15
+ indent: "\\qquad"
16
+ thanks: "This is the PDF file for the how to write opensource book contents. It is licensed under the Creative Commons Attribution-Non Commercial-Share Alike 3.0 license. I hope you enjoy it, I hope it helps you learn the software development, and I hope you'll continuously watch this : \\url{http://github.com/larrycai/kaiyuanbook}, will be happy if you follow my weibo \\url{http://weibo.com/larrycaiyu}, and if you want to donate, please visit: \\url{https://me.alipay.com/larrycai}"
17
+ zh:
18
+ title: 跟我学开源技术书
19
+ langrule: "\\XeTeXlinebreakskip=0em plus 0.1em minus 0.01em\n\\XeTeXlinebreakpenalty=0"
20
+ font: AR PL SungtiL GB
21
+ bold: WenQuanYi Micro Hei
22
+ mono: WenQuanYi Zen Hei Mono
23
+ # AR is 文鼎字体,中文缺省 http://www.arphic.com/cn/home.html
24
+ # http://www.debian.org/international/Chinese/software
25
+ # AR PL UMing: 文鼎PL细上海宋 : 句号有问题
26
+ # AR PL UKai: 文鼎PL中楷
27
+ # AR PL SungtiL GB : 文鼎PL简报宋 , * (item) 有问题!为空
28
+ # AR PL KaitiM GB : 文鼎PL简中楷
29
+ # WenQuanYi is 文泉驿 http://wenq.org/
30
+ # WenQuanYi Bitmap Song: 点阵宋 (! had problem ?)
31
+ # WenQuanYi Micro Hei:微米黑
32
+ # WenQuanYi Zen Hei Mono:正黑
33
+ # Adobe Song Std: Adobe 宋体 , * (item) 有问题!为框
34
+ #
35
+ # default below
36
+ #font: AR PL UMing CN
37
+ #bold: AR PL UKai CN
38
+ #mono: AR PL UKai CN
39
+ prechap: "第"
40
+ postchap: "章"
41
+ presect: ""
42
+ postsect: "节"
43
+ con: "目录"
44
+ fig: "图 "
45
+ tab: "表 "
46
+ # 首段落空两格字。
47
+ indent: "文文"
48
+ zh-tw:
49
+ langrule: "\\XeTeXlinebreakskip=0em plus 0.1em minus 0.01em\n\\XeTeXlinebreakpenalty=0"
50
+ font: AR PL UMing TW
51
+ bold: AR PL UKai TW
52
+ mono: AR PL UKai TW
53
+ prechap: "第"
54
+ postchap: "章"
55
+ presect: ""
56
+ postsect: "節"
57
+ dql: "『"
58
+ dqr: "』"
59
+ con: "目錄"
60
+ fig: "圖 "
61
+ tab: "表 "
62
+ indent: "文"
63
+ ja:
64
+ langrule: "\\XeTeXlinebreakskip=0em plus 0.1em minus 0.01em\n\\XeTeXlinebreakpenalty=0"
65
+ # font: Japan
66
+ # font: Sazanami Mincho
67
+ font: IPAPMincho
68
+ bold: VL PGothic
69
+ # bold: Sazanami Gothic
70
+ # bold: IPAPGothic
71
+ mono: VL Gothic
72
+ prechap: "第"
73
+ postchap: "章"
74
+ presect: ""
75
+ postsect: "節"
76
+ dql: "『"
77
+ dqr: "』"
78
+ con: "目次"
79
+ fig: "図"
80
+ tab: "表"
81
+ indent: "あ"
82
+ ru:
83
+ prechap: "Глава "
84
+ presect: "Раздел "
85
+ con: "Содержание"
86
+ fig: "Рисунок "
87
+ tab: "Таблица "
88
+ dql: "«"
89
+ dqr: "»"
90
+ cs:
91
+ prechap: "Kapitola "
92
+ presect: "Oddíl "
93
+ dql: "„"
94
+ dqr: "“"
95
+ fig: "Obrázek "
96
+ tab: "Tabulka "
97
+ fr:
98
+ prechap: "Chapitre "
99
+ presect: "Section "
100
+ fig: "Figure "
101
+ tab: "Tableau "
102
+ font: Linux Libertine
103
+ mono: Courier New
104
+ con: "Table des matières"
105
+ langrule: "\\frenchspacing\\usepackage{fontspec}\n\\fontspec[Ligatures={Common}]{Linux Libertine}\n"
106
+ thanks: "Ce fichier PDF est la traduction française du livre Pro Git. Il est publié sous license Creative Commons Attribution-Non Commercial-Share Alike 3.0. J'espère que vous l'apprécierez, qu'il vous permettra d'apprendre à utiliser Git et que vous aiderez Apress en achetant le livre original sur Amazon : \\url{http://tinyurl.com/amazonprogit}"
107
+ dql: "«\\,"
108
+ dqr: "\\,»"
109
+ mk:
110
+ fig: "Слика"
111
+ con: "Содржина"
112
+ prechap: "Поглавје"
113
+ presect: "Секција"
114
+ dql: "„"
115
+ dqr: "“"
116
+ tab: "Табела"
117
+ de:
118
+ langrule: "\\frenchspacing"
119
+ dql: "„"
120
+ dqr: "“"
121
+ ko:
122
+ langrule: "\\XeTeXlinebreakskip=0em plus 0.1em minus 0.01em\n\\XeTeXlinebreakpenalty=0"
123
+ font: UnBatang
124
+ bold: UnGraphic
125
+ mono: UnDotum
126
+ prechap: ""
127
+ postchap: "장"
128
+ presect: ""
129
+ postsect: "절"
130
+ con: "목차"
131
+ fig: "그림"
132
+ tab: "표"
133
+ be:
134
+ prechap: "Глава "
135
+ presect: "Раздзел "
136
+ con: "Змест"
137
+ fig: "Малюнак "
138
+ tab: "Табліца "