burr 0.0.2

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.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE.md +30 -0
  6. data/README.md +180 -0
  7. data/Rakefile +118 -0
  8. data/bin/burr +9 -0
  9. data/burr.gemspec +36 -0
  10. data/generators/Gemfile.txt +3 -0
  11. data/generators/config.yml +55 -0
  12. data/generators/contents/chapter1.md +7 -0
  13. data/generators/contents/chapter2.md +7 -0
  14. data/generators/stylesheets/pdf.css +569 -0
  15. data/generators/stylesheets/site.css +1 -0
  16. data/lib/burr.rb +56 -0
  17. data/lib/burr/book.rb +289 -0
  18. data/lib/burr/cli.rb +64 -0
  19. data/lib/burr/converter.rb +19 -0
  20. data/lib/burr/core_ext/blank.rb +107 -0
  21. data/lib/burr/dependency.rb +28 -0
  22. data/lib/burr/eeepub_ext/maker.rb +131 -0
  23. data/lib/burr/exporter.rb +137 -0
  24. data/lib/burr/exporters/epub.rb +163 -0
  25. data/lib/burr/exporters/pdf.rb +95 -0
  26. data/lib/burr/exporters/site.rb +101 -0
  27. data/lib/burr/generator.rb +41 -0
  28. data/lib/burr/kramdown_ext/converter.rb +145 -0
  29. data/lib/burr/kramdown_ext/options.rb +38 -0
  30. data/lib/burr/kramdown_ext/parser.rb +65 -0
  31. data/lib/burr/liquid_ext/block.rb +58 -0
  32. data/lib/burr/liquid_ext/extends.rb +114 -0
  33. data/lib/burr/plugin.rb +70 -0
  34. data/lib/burr/plugins/aside.rb +44 -0
  35. data/lib/burr/plugins/codeblock.rb +42 -0
  36. data/lib/burr/plugins/figure.rb +62 -0
  37. data/lib/burr/plugins/link.rb +47 -0
  38. data/lib/burr/plugins/parser_plugin.rb +18 -0
  39. data/lib/burr/plugins/table.rb +42 -0
  40. data/lib/burr/plugins/toc.rb +105 -0
  41. data/lib/burr/ruby_version_check.rb +4 -0
  42. data/lib/burr/server.rb +27 -0
  43. data/lib/burr/ui.rb +46 -0
  44. data/lib/burr/version.rb +8 -0
  45. data/resources/locales/labels/en.yml +45 -0
  46. data/resources/locales/labels/zh_CN.yml +46 -0
  47. data/resources/locales/titles/en.yml +21 -0
  48. data/resources/locales/titles/zh_CN.yml +21 -0
  49. data/resources/templates/epub/_layout.liquid +17 -0
  50. data/resources/templates/epub/acknowledgement.liquid +10 -0
  51. data/resources/templates/epub/afterword.liquid +10 -0
  52. data/resources/templates/epub/appendix.liquid +10 -0
  53. data/resources/templates/epub/author.liquid +10 -0
  54. data/resources/templates/epub/chapter.liquid +10 -0
  55. data/resources/templates/epub/conclusion.liquid +10 -0
  56. data/resources/templates/epub/cover.liquid +9 -0
  57. data/resources/templates/epub/dedication.liquid +10 -0
  58. data/resources/templates/epub/edition.liquid +1 -0
  59. data/resources/templates/epub/epilogue.liquid +1 -0
  60. data/resources/templates/epub/foreword.liquid +10 -0
  61. data/resources/templates/epub/glossary.liquid +1 -0
  62. data/resources/templates/epub/introduction.liquid +1 -0
  63. data/resources/templates/epub/license.liquid +1 -0
  64. data/resources/templates/epub/lof.liquid +24 -0
  65. data/resources/templates/epub/lot.liquid +24 -0
  66. data/resources/templates/epub/part.liquid +4 -0
  67. data/resources/templates/epub/preface.liquid +10 -0
  68. data/resources/templates/epub/prologue.liquid +1 -0
  69. data/resources/templates/epub/table.liquid +7 -0
  70. data/resources/templates/epub/title.liquid +3 -0
  71. data/resources/templates/epub/toc.liquid +10 -0
  72. data/resources/templates/pdf/_item.liquid +6 -0
  73. data/resources/templates/pdf/acknowledgement.liquid +1 -0
  74. data/resources/templates/pdf/afterword.liquid +1 -0
  75. data/resources/templates/pdf/appendix.liquid +4 -0
  76. data/resources/templates/pdf/author.liquid +1 -0
  77. data/resources/templates/pdf/blank.liquid +3 -0
  78. data/resources/templates/pdf/book.liquid +42 -0
  79. data/resources/templates/pdf/chapter.liquid +4 -0
  80. data/resources/templates/pdf/code.liquid +3 -0
  81. data/resources/templates/pdf/conclusion.liquid +1 -0
  82. data/resources/templates/pdf/cover.liquid +6 -0
  83. data/resources/templates/pdf/dedication.liquid +3 -0
  84. data/resources/templates/pdf/edition.liquid +1 -0
  85. data/resources/templates/pdf/epilogue.liquid +1 -0
  86. data/resources/templates/pdf/foreword.liquid +1 -0
  87. data/resources/templates/pdf/glossary.liquid +1 -0
  88. data/resources/templates/pdf/introduction.liquid +1 -0
  89. data/resources/templates/pdf/license.liquid +1 -0
  90. data/resources/templates/pdf/lof.liquid +24 -0
  91. data/resources/templates/pdf/lot.liquid +24 -0
  92. data/resources/templates/pdf/part.liquid +4 -0
  93. data/resources/templates/pdf/preface.liquid +1 -0
  94. data/resources/templates/pdf/prologue.liquid +1 -0
  95. data/resources/templates/pdf/table.liquid +7 -0
  96. data/resources/templates/pdf/title.liquid +3 -0
  97. data/resources/templates/pdf/toc.liquid +4 -0
  98. data/resources/templates/site/_layout.liquid +27 -0
  99. data/resources/templates/site/author.liquid +13 -0
  100. data/resources/templates/site/chapter.liquid +13 -0
  101. data/resources/templates/site/foreword.liquid +13 -0
  102. data/resources/templates/site/preface.liquid +13 -0
  103. metadata +232 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f849154fa08f4e730346d3f7568008af38b5a0d4
4
+ data.tar.gz: 04056ac1475498bcfa8afd2eeb8d4313f96b2bf2
5
+ SHA512:
6
+ metadata.gz: 0d046ab33e9dbe39a8a04eb2741a92777be18e3f2b4ae8be5be847d26b1df564452b47fb96d952aa39037ad00dfb445f75ca1164eed3b955954c8d55169ef06e
7
+ data.tar.gz: 1d1fd65b40f58bc4333c0a93d42ae136cd4e182d3575bdc81e95198db184df88ab733881a6c0de05ddac8c2d50949490c6713be85ac64ec855571eddbc95cd8a
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ *.gem
3
+ pkg/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,30 @@
1
+ # License #
2
+
3
+ ## Application Code ##
4
+
5
+ Copyright (c) 2012 Andor Chen <andor.chen.27@gmail.com>
6
+
7
+ Some ideas and minor portions of code inspired by easybook project:
8
+ Copyright (c) 2012 Javier Eguiluz <javier.eguiluz@gmail.com> (details: https://github.com/javiereguiluz/easybook/blob/master/LICENSE.md)
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
11
+ this software and associated documentation files (the "Software"), to deal in
12
+ the Software without restriction, including without limitation the rights to
13
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14
+ of the Software, and to permit persons to whom the Software is furnished to do
15
+ so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ ## Dependency gems ##
29
+
30
+ See their own license files
data/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # burr
2
+
3
+ [![Dependency Status](https://gemnasium.com/AndorChen/burr.png)](https://gemnasium.com/AndorChen/burr)
4
+
5
+ burr 是一个电子书制作工具(命令行)。使用 Markdown 编写书籍内容,burr 可以将其转换成 PDF,ePub 和 Mobi 格式电子书。还能生成 HTML 格式,提供书籍在线阅读。
6
+
7
+ ## 目的
8
+
9
+ 一份文稿,四种输出。
10
+
11
+ ## 示例
12
+
13
+ 《Ruby on Rails 教程》这本书的电子书,以及在线阅读版就是使用 burr 制作的。
14
+
15
+ <http://railstutorial-china.org>
16
+
17
+ ## 特性
18
+
19
+ ### 整体
20
+
21
+ - 章节自动编号;
22
+ - 图片自动编号;
23
+ - 表格自动编号;
24
+ - 代码片段自动编号;
25
+
26
+ ### PDF 格式
27
+
28
+ - 自动生成目录;
29
+ - 自动生成书签;
30
+ - 自动生成交叉引用;
31
+ - 样式可定制;
32
+
33
+ ### ePub 格式
34
+
35
+ - 元信息完整;
36
+ - 支持图书封面;
37
+ - 兼容各主要阅读器(多看,Kindle 等);
38
+ - 自动生成目录;
39
+ - 自动生成交叉引用;
40
+ - 样式可定制;
41
+
42
+ ### mobi 格式
43
+
44
+ - 元信息完整;
45
+ - 支持图书封面;
46
+ - 兼容各主要阅读器(Kindle 等);
47
+ - 自动生成目录;
48
+ - 自动生成交叉引用;
49
+
50
+ ### HTML 在线阅读
51
+
52
+ - 自动生成各章内容;
53
+ - 自动生成各章目录;
54
+ - 自动生成交叉引用;
55
+ - 样式可定制;
56
+
57
+ ## 安装
58
+
59
+ ### 依赖程序
60
+
61
+ burr 只是一个 wrapper,电子书都是通过其他程序生成的。其中 PDF 使用 [PrinceXML](http://www.princexml.com/),ePub 使用 [eeepub](https://github.com/jugyo/eeepub),mobi 使用 [kindlegen](http://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000765211)。所以在使用 burr 之前,请确保安装了这些程序。具体的安装过程请参照相应程序的安装说明。
62
+
63
+ ### burr 本身
64
+
65
+ burr 是一个 Ruby gem,可以像其他 gem 一样安装。但是由于没有推送到 Rubygems.org,所以无法使用 `gem install` 命令安装。
66
+
67
+ 在项目的 `Gemfile` 中加入以下代码:
68
+
69
+ ```ruby
70
+ gem 'burr', github: 'andorchen/burr'
71
+ ```
72
+
73
+ 然后执行 `bundle` 命令安装。
74
+
75
+ ## 使用方法
76
+
77
+ ### 生成新项目
78
+
79
+ 执行 `burr new [path]` 命令会生成一个新项目,生成的目录结构如下:
80
+
81
+ ```text
82
+ - Gemfile
83
+ - config.yml # 项目设置
84
+ - contents # 书稿文件夹
85
+ |- contents/chapter1.md
86
+ |- contents/chapter2.md
87
+ - outputs # 电子书输出文件夹
88
+ |- pdf/
89
+ |- style.css
90
+ |- site/
91
+ |- figures/ # 书中所用图片
92
+ |- style.css
93
+ |- epub/
94
+ |- mobi/
95
+ |- caches/ # 缓存文件夹,暂时未用
96
+ |- code/
97
+ ```
98
+
99
+ ### 生成电子书
100
+
101
+ ```sh
102
+ $ burr export pdf
103
+ $ burr export epub
104
+ $ burr export mobi
105
+ $ burr export site
106
+ ```
107
+
108
+ ### 帮助
109
+
110
+ 更多命令请执行 `burr help` 命令查看。
111
+
112
+ ## 原理
113
+
114
+ 1. 使用 Markdown 语法([kramdown](http://kramdown.rubyforge.org/index.html))撰写文稿;
115
+ 2. burr 根据 `config.yml` 中的设置,套用模板将 Markdown 转换成 HTML 文档;
116
+ 3. 电子书生成工具将 HTML 文档转换成电子书。
117
+
118
+ ## 文稿格式
119
+
120
+ burr 使用 kramdown 的语法,并做了适当扩展。
121
+
122
+ ### burr 的扩展
123
+
124
+ #### 附加信息(来自 Leanpub)
125
+
126
+ ```text
127
+ A> #### 旁注标题
128
+ A>
129
+ A> 注意 > 符号后面要留一个空格。
130
+ A>
131
+ A> 如果旁注中有脚注,一定要写在旁注内。[^fn-1]
132
+ A>
133
+ A> [^fn-1]: 这是一个脚注。
134
+ ```
135
+
136
+ ```text
137
+ W> #### 警告
138
+ W>
139
+ W> 这是一则警告:侵权必究!
140
+ ```
141
+
142
+ ```text
143
+ T> #### 小贴士
144
+ T>
145
+ T> 夏天空调温度不要开的过低哟。
146
+ ```
147
+
148
+ 其他附加信息类型,请参考 [Leanpub 的帮助文档](https://leanpub.com/help/manual#leanpub-auto-asidessidebars)。
149
+
150
+ #### 代码块
151
+
152
+ kramdown 原生支持的代码块由 `~~~` 分隔,但我更习惯使用 GitHub 的句法,所以 burr 提供了对后者的支持。除此之外,因为计算机书籍经常会为代码块加入说明及所在文件位置,所以 burr 利用 kramdown 的 [Block Inline Attribute Lists](http://kramdown.rubyforge.org/syntax.html#block-ials) 实现了这一功能,使用方法如下:
153
+
154
+
155
+ ```ruby
156
+ def hello
157
+ puts "Hello, burr!"
158
+ end
159
+ ```
160
+ {:caption="Ruby 方法定义示例" file="/path/to/file.rb"}
161
+
162
+ 代码高亮通过 [pygments.rb](https://github.com/tmm1/pygments.rb) 实现。
163
+
164
+ ### 图片题注
165
+
166
+ ```text
167
+ ![alt text](path/to/image.jpg){:caption="示例图片"}
168
+ ```
169
+
170
+ ## 作者
171
+
172
+ [Andor Chen](http://about.ac)
173
+
174
+ ## 发布协议
175
+
176
+ [MIT](LICENSE.md)
177
+
178
+ ## 致谢
179
+
180
+ 在 burr 开发中借鉴了 [easybook](https://github.com/javiereguiluz/easybook/) 的很多思路,特此感谢。
data/Rakefile ADDED
@@ -0,0 +1,118 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), *%w[lib]))
2
+
3
+ require 'rake'
4
+ require 'rdoc'
5
+ require 'date'
6
+
7
+ require 'burr'
8
+
9
+ #############################################################################
10
+ #
11
+ # Helper functions
12
+ #
13
+ #############################################################################
14
+
15
+ def name
16
+ @name ||= Dir['*.gemspec'].first.split('.').first
17
+ end
18
+
19
+ def version
20
+ Burr::Version::STRING
21
+ end
22
+
23
+ def date
24
+ Date.today.to_s
25
+ end
26
+
27
+ def rubyforge_project
28
+ name
29
+ end
30
+
31
+ def gemspec_file
32
+ "#{name}.gemspec"
33
+ end
34
+
35
+ def gem_file
36
+ "#{name}-#{version}.gem"
37
+ end
38
+
39
+ #############################################################################
40
+ #
41
+ # Standard tasks
42
+ #
43
+ #############################################################################
44
+
45
+ task :default => [:test, :features]
46
+
47
+ require 'rake/testtask'
48
+ Rake::TestTask.new(:test) do |test|
49
+ test.libs << 'lib' << 'test'
50
+ test.pattern = 'test/**/test_*.rb'
51
+ test.verbose = true
52
+ end
53
+
54
+ desc "Generate RCov test coverage and open in your browser"
55
+ task :coverage do
56
+ require 'rcov'
57
+ sh "rm -fr coverage"
58
+ sh "rcov test/test_*.rb"
59
+ sh "open coverage/index.html"
60
+ end
61
+
62
+ require 'rdoc/task'
63
+ Rake::RDocTask.new do |rdoc|
64
+ rdoc.rdoc_dir = 'rdoc'
65
+ rdoc.title = "#{name} #{version}"
66
+ rdoc.rdoc_files.include('README*')
67
+ rdoc.rdoc_files.include('lib/**/*.rb')
68
+ end
69
+
70
+ desc "Open an irb session preloaded with this library"
71
+ task :console do
72
+ sh "irb -rubygems -r ./lib/#{name}.rb"
73
+ end
74
+
75
+ #############################################################################
76
+ #
77
+ # Custom tasks (add your own tasks here)
78
+ #
79
+ #############################################################################
80
+
81
+ begin
82
+ require 'cucumber/rake/task'
83
+ Cucumber::Rake::Task.new(:features) do |t|
84
+ t.cucumber_opts = "--format progress"
85
+ end
86
+ rescue LoadError
87
+ desc 'Cucumber rake task not available'
88
+ task :features do
89
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
90
+ end
91
+ end
92
+
93
+ #############################################################################
94
+ #
95
+ # Packaging tasks
96
+ #
97
+ #############################################################################
98
+
99
+ desc 'Release the gem, push to github and rubygems.org'
100
+ task :release => :build do
101
+ unless `git branch` =~ /^\* master$/
102
+ puts "You must be on the master branch to release!"
103
+ exit!
104
+ end
105
+ sh "git commit --allow-empty -m 'Release #{version}'"
106
+ sh "git tag v#{version}"
107
+ sh "git push origin master"
108
+ sh "git push origin v#{version}"
109
+ sh "gem push pkg/#{name}-#{version}.gem"
110
+ end
111
+
112
+ desc 'Build the gem and then move to /pkg'
113
+ task :build do
114
+ sh "mkdir -p pkg"
115
+ sh "gem build #{gemspec_file}"
116
+ sh "mv #{gem_file} pkg"
117
+ end
118
+
data/bin/burr ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'burr/ruby_version_check'
6
+
7
+ require 'burr'
8
+
9
+ Burr::Cli.start
data/burr.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require 'burr/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.specification_version = 2 if s.respond_to? :specification_version=
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+
9
+ s.name = 'burr'
10
+ s.version = Burr::Version::STRING
11
+ s.license = 'MIT'
12
+ s.date = '2013-04-21'
13
+
14
+ s.summary = "电子书制作工具"
15
+ s.description = "使用 Markdown 编写书籍内容,通过 burr 将其转换成 PDF,ePub 和 Mobi 格式电子书。"
16
+
17
+ s.authors = ["Andor Chen"]
18
+ s.email = 'andor.chen.27@gmail.com'
19
+ s.homepage = 'https://github.com/AndorChen/burr'
20
+
21
+ s.require_paths = %w[lib]
22
+
23
+ s.executables = ["burr"]
24
+
25
+ s.rdoc_options = ["--charset=UTF-8"]
26
+ s.extra_rdoc_files = %w[README.md LICENSE.md]
27
+
28
+ s.add_runtime_dependency('nokogiri', '~> 1.6.0')
29
+ s.add_runtime_dependency('thor', '~> 0.18.1')
30
+ s.add_runtime_dependency('liquid', '~> 2.5.4')
31
+ s.add_runtime_dependency('kramdown', '~> 1.2.0')
32
+ s.add_runtime_dependency('pygments.rb', '~> 0.5.4')
33
+ s.add_runtime_dependency('eeepub', '~> 0.8.1')
34
+
35
+ s.files = `git ls-files`.split($/)
36
+ end
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gem 'burr', '~> 0.0.1'
@@ -0,0 +1,55 @@
1
+ title: 'Sample Book'
2
+ subtitle: ''
3
+ slug: ''
4
+ author: 'Your Name'
5
+ translator: ''
6
+ edition: 'First edition'
7
+ language: 'zh_CN'
8
+ publisher: ''
9
+ pubdate: ''
10
+ isbn: ''
11
+ identifier: '' # only for epub
12
+ id_scheme: '' # only for epub
13
+
14
+ contents:
15
+ # available content types: acknowledgement, afterword, appendix, author,
16
+ # blank, chapter, conclusion, cover, dedication, edition, epilogue, foreword,
17
+ # glossary, introduction, license, lof (list of figures), lot (list of
18
+ # tables), part, preface, prologue, title, toc (table of contents)
19
+ - { element: cover }
20
+ - { element: toc }
21
+ - { element: chapter, number: 1, file: chapter1.md }
22
+ - { element: chapter, number: 2, file: chapter2.md }
23
+
24
+ formats:
25
+ pdf:
26
+ label:
27
+ deep: 3
28
+ elements: ['appendix', 'chapter', 'part'] # labels also available for: "figure", "table", "codeblock"
29
+ toc:
30
+ deep: 2
31
+ elements: ['appendix', 'chapter', 'part']
32
+
33
+ site:
34
+ label:
35
+ deep: 3
36
+ elements: ['appendix', 'chapter'] # labels also available for: "figure", "table", "codeblock"
37
+ toc:
38
+ deep: 2 # toc in single page
39
+ elements: ['appendix', 'chapter']
40
+
41
+ epub:
42
+ label:
43
+ deep: 3
44
+ elements: ['appendix', 'chapter', 'part'] # labels also available for: "figure", "table", "codeblock"
45
+ toc:
46
+ deep: 1
47
+ elements: ['appendix', 'chapter', 'part']
48
+
49
+ mobi:
50
+ label:
51
+ deep: 3
52
+ elements: ['appendix', 'chapter', 'part'] # labels also available for: "figure", "table", "codeblock"
53
+ toc:
54
+ deep: 1
55
+ elements: ['appendix', 'chapter', 'part']