mkbook 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/mkbook +153 -0
- data/lib/mkbook.rb +2 -1
- data/lib/mkbook/config.yml +20 -0
- data/lib/mkbook/make_book.rb +296 -0
- data/lib/mkbook/mkbook.rb +14 -0
- data/lib/mkbook/mkbook_build.rb +29 -0
- data/lib/mkbook/mkbook_new.rb +12 -0
- data/lib/mkbook/template_article.tex +21 -0
- data/lib/mkbook/template_blog.tex +26 -0
- data/lib/mkbook/template_book.tex +35 -0
- data/lib/mkbook/template_novel.tex +36 -0
- data/lib/mkbook/utils.rb +43 -0
- data/lib/mkbook/version.rb +1 -1
- data/lib/template/.gitignore +3 -0
- data/lib/template/.mkbook.yml +10 -0
- data/lib/template/en/appx0000-plain.md +3 -0
- data/lib/template/en/chap0000-plain.md +3 -0
- data/lib/template/en/desc0000-plain.md +1 -0
- data/lib/template/en/face0000-plain.md +7 -0
- data/lib/template/images/.keep +0 -0
- data/lib/template/resources/.keep +0 -0
- data/lib/template/zh/appx0000-plain.md +3 -0
- data/lib/template/zh/chap0000-plain.md +3 -0
- data/lib/template/zh/desc0000-plain.md +1 -0
- data/lib/template/zh/face0000-plain.md +7 -0
- metadata +72 -16
- data/.gitignore +0 -11
- data/.rspec +0 -2
- data/.travis.yml +0 -4
- data/CODE_OF_CONDUCT.md +0 -13
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -21
- data/README.md +0 -41
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/mkbook.gemspec +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57a0bd50a0c060308fe052fcb400acc3dec207b0
|
4
|
+
data.tar.gz: 574ff20af2853ac8910dbfee0c9e79a0b205c59a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 418de4b9591d442697ab38615775bb43b9d1070f3ee929b3ca9ce6ee4238ce3506a1be586b9e2c2e795a1469a94b9da480eaea02786896903be7cd7c75a7d59a
|
7
|
+
data.tar.gz: 09d2ff83fb9d4d3264e40a0bdb617c276707cc18c01b4e32f34e0e10dba75347d3dcef84edec0a52a93e7fb238e10036056c43a4f89aaaae667a44e32fff6a50
|
data/bin/mkbook
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# mkbook -g name -w workspace
|
4
|
+
# mkbook -s dir_source -o dir_output
|
5
|
+
# Mkbook::MakeBook.find(:dir_source => dir, :dir_output => dir).build
|
6
|
+
|
7
|
+
require "bundler/setup"
|
8
|
+
require "mkbook"
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
12
|
+
# with your gem easier. You can also use a different console, if you like.
|
13
|
+
|
14
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
15
|
+
# require "pry"
|
16
|
+
# Pry.start
|
17
|
+
|
18
|
+
# require "irb"
|
19
|
+
# IRB.start
|
20
|
+
# Mkbook::Mkbook.run(ARGV)
|
21
|
+
|
22
|
+
# 设置全局变量
|
23
|
+
here = Dir.getwd # 工作目录/项目目录
|
24
|
+
root = File.dirname(__FILE__) # program directory
|
25
|
+
|
26
|
+
# 设置默认选项
|
27
|
+
options = {
|
28
|
+
:lang => "zh",
|
29
|
+
:format => "markdown",
|
30
|
+
:build => ["pdf"],
|
31
|
+
:template => "book",
|
32
|
+
:option => "a5paper,centering,openany",
|
33
|
+
:workspace => here,
|
34
|
+
:dir_source => here,
|
35
|
+
:dir_output => File.join(here, "out"),
|
36
|
+
:command => "build",
|
37
|
+
:file_preface => "face*.md",
|
38
|
+
:file_chapters => "chap*.md",
|
39
|
+
:file_appendix => "appx*.md"
|
40
|
+
}
|
41
|
+
|
42
|
+
# 定义选项解析器
|
43
|
+
opts = {}
|
44
|
+
OptionParser.new do |opt|
|
45
|
+
executable_name = File.basename($PROGRAM_NAME)
|
46
|
+
opt.banner = "Make ebooks from markdown plain text
|
47
|
+
Usage: #{executable_name} [options]\n"
|
48
|
+
|
49
|
+
# 定义输出格式
|
50
|
+
opt.on("-b", "--build FORMAT", "build format: pdf,html,epub. seperated by ','") do |format|
|
51
|
+
format_options = format.split(",")
|
52
|
+
format_options.each do |fmt|
|
53
|
+
unless ["pdf", "index", "html", "epub"].include?(fmt)
|
54
|
+
raise ArgumentError, "FORMAT must be one of 'pdf,index,html,epub' format"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
opts[:command] = "build"
|
58
|
+
opts[:build] = format_options
|
59
|
+
end
|
60
|
+
|
61
|
+
# 添加文档
|
62
|
+
opt.on("-a", "--add TYPE", "TYPE: face, chap, appx") do |setting|
|
63
|
+
opts[:command] = "add"
|
64
|
+
opts[:genre] = setting
|
65
|
+
end
|
66
|
+
|
67
|
+
# 定义 debug 模式, 输出更多信息, 用于调试
|
68
|
+
opt.on("-d", "--[no-]debug", "debug mode") do |setting|
|
69
|
+
opts[:debug] = setting
|
70
|
+
end
|
71
|
+
|
72
|
+
# 定义 定稿 模式, 编译三遍, 建立索引、参考文献
|
73
|
+
opt.on("-f", "--[no-]final", "final mode") do |setting|
|
74
|
+
opts[:final] = setting
|
75
|
+
end
|
76
|
+
|
77
|
+
# 选择语言类型
|
78
|
+
opt.on("-l", "--lang LANG", "language selection") do |lang|
|
79
|
+
opts[:lang] = lang
|
80
|
+
end
|
81
|
+
|
82
|
+
# 选择模板
|
83
|
+
opt.on("-t", "--template template.tex", "latex template file") do |template|
|
84
|
+
unless File.exists? File.join(root, "../lib", "template_#{template}.tex")
|
85
|
+
raise ArgumentError, "template file \"#{template}\" doesn't exist"
|
86
|
+
end
|
87
|
+
opts[:template] = template
|
88
|
+
end
|
89
|
+
|
90
|
+
# 设置书的名字
|
91
|
+
opt.on("-n", "--name book name", "book name") do |name|
|
92
|
+
unless name =~ /^[a-zA-Z0-9-]+$/
|
93
|
+
raise ArgumentError, "name should be [a-zA-Z0-9-]"
|
94
|
+
end
|
95
|
+
opts[:name] = name
|
96
|
+
end
|
97
|
+
|
98
|
+
# 定义生成器
|
99
|
+
opt.on("-g", "--generate project", "project name") do |name|
|
100
|
+
unless name =~ /^[a-zA-Z0-9-]+$/
|
101
|
+
raise ArgumentError, "name should be [a-zA-Z0-9-]"
|
102
|
+
end
|
103
|
+
opts[:command] = "generate"
|
104
|
+
opts[:name] = name
|
105
|
+
end
|
106
|
+
|
107
|
+
# 项目路径
|
108
|
+
opt.on("-s", "--src-dir directory", "source directory") do |directory|
|
109
|
+
opts[:dir_source] = directory
|
110
|
+
opts[:dir_output] = File.join(directory, "out")
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
# 输出路径
|
115
|
+
opt.on("-o", "--out-dir directory", "output directory") do |directory|
|
116
|
+
opts[:dir_output] = directory
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
# 工作路径
|
121
|
+
opt.on("-w", "--workspace path", "workspace path") do |directory|
|
122
|
+
opts[:workspace] = directory
|
123
|
+
end
|
124
|
+
end.parse!
|
125
|
+
options.merge!(opts)
|
126
|
+
|
127
|
+
options[:name] = File.basename(here) unless options[:name]
|
128
|
+
|
129
|
+
puts options.inspect if options[:debug]
|
130
|
+
|
131
|
+
if options[:command] == "generate"
|
132
|
+
Mkbook::MakeBook.new.create(options)
|
133
|
+
exit
|
134
|
+
end
|
135
|
+
|
136
|
+
# 加载配置文件
|
137
|
+
options[:project] = options[:dir_source]
|
138
|
+
config_file = File.join(options[:project], '.mkbook.yml')
|
139
|
+
if File.exists? config_file
|
140
|
+
config_options = YAML.load_file(config_file)
|
141
|
+
options.merge!(config_options) if config_options
|
142
|
+
else
|
143
|
+
log_error("This is not an ebook project, or missing .mkbook.yml.
|
144
|
+
Use the following command to generate project first,
|
145
|
+
mkbook --generate <foo>
|
146
|
+
Or create an empty file .mkbook.yml manually.\n")
|
147
|
+
exit
|
148
|
+
end
|
149
|
+
options.merge!(opts)
|
150
|
+
|
151
|
+
if options[:command] == "build"
|
152
|
+
Mkbook::MakeBook.new.build(options)
|
153
|
+
end
|
data/lib/mkbook.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
default:
|
2
|
+
thanks: "Thank you!"
|
3
|
+
zh:
|
4
|
+
title: 书的标题
|
5
|
+
author: 作者
|
6
|
+
date: \today
|
7
|
+
version: 0.0.1
|
8
|
+
contents: 目录
|
9
|
+
figure: 图
|
10
|
+
table: 表
|
11
|
+
appendix: 附录
|
12
|
+
en:
|
13
|
+
title: Book Name
|
14
|
+
author: Author
|
15
|
+
date: \today
|
16
|
+
version: 0.0.1
|
17
|
+
contents: Contents
|
18
|
+
figure: Fig.
|
19
|
+
table: Tab.
|
20
|
+
appendix: Appendix
|
@@ -0,0 +1,296 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'yaml'
|
3
|
+
require 'mkbook/utils'
|
4
|
+
|
5
|
+
module Mkbook
|
6
|
+
class MakeBook
|
7
|
+
HERE = Dir.getwd
|
8
|
+
ROOT = File.dirname(__FILE__)
|
9
|
+
TEMPLATE = File.join(ROOT, "..", "template")
|
10
|
+
SETTING_FILE = ".mkbook.yml"
|
11
|
+
|
12
|
+
def initializes(params)
|
13
|
+
@project = params[:project]
|
14
|
+
@setting_file = File.join(@project, SETTING_FILE)
|
15
|
+
@setting_file = File.join(TEMPLATE, SETTING_FILE) unless File.exist?(@setting_file)
|
16
|
+
@setting = YAML.load_file(@setting_file)
|
17
|
+
@setting.merge!(params)
|
18
|
+
@setting[:name] ||= File.basename(@project)
|
19
|
+
load
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find(params)
|
23
|
+
book = new
|
24
|
+
book.initializes(params)
|
25
|
+
book
|
26
|
+
end
|
27
|
+
|
28
|
+
def create(params)
|
29
|
+
@project = File.join(params[:workspace], params[:name])
|
30
|
+
@setting_file = File.join(TEMPLATE, SETTING_FILE)
|
31
|
+
@setting = YAML.load_file(@setting_file)
|
32
|
+
@setting.merge!(params)
|
33
|
+
@setting[:name] ||= File.basename(@project)
|
34
|
+
load
|
35
|
+
save
|
36
|
+
end
|
37
|
+
|
38
|
+
def build(params)
|
39
|
+
@project = params[:dir_source]
|
40
|
+
@setting_file = File.join(@project, SETTING_FILE)
|
41
|
+
@setting = YAML.load_file(@setting_file)
|
42
|
+
@setting = {} unless @setting
|
43
|
+
@setting.merge!(params)
|
44
|
+
@setting[:name] ||= File.basename(@project)
|
45
|
+
load
|
46
|
+
check_environment
|
47
|
+
load_config
|
48
|
+
@setting[:build].each do |fmt|
|
49
|
+
case fmt
|
50
|
+
when 'pdf' then
|
51
|
+
@preface = markdown2latex(@file_preface)
|
52
|
+
@chapters = markdown2latex(@file_chapters)
|
53
|
+
@appendix = markdown2latex(@file_appendix)
|
54
|
+
generate_main_file
|
55
|
+
latex2pdf
|
56
|
+
when 'index' then
|
57
|
+
index = {}
|
58
|
+
index[:preface] = markdown2index(@file_preface)
|
59
|
+
index[:chapters]= markdown2index(@file_chapters)
|
60
|
+
index[:appendix]= markdown2index(@file_appendix)
|
61
|
+
FileUtils.mkdir_p(@dir_html) unless Dir.exist?(@dir_html)
|
62
|
+
IO.write(File.join(@dir_html, 'index.yml'), index.to_yaml)
|
63
|
+
when 'html' then
|
64
|
+
markdown2html(@file_preface)
|
65
|
+
markdown2html(@file_chapters)
|
66
|
+
markdown2html(@file_appendix)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
save_config
|
70
|
+
save_setting
|
71
|
+
end
|
72
|
+
|
73
|
+
def load
|
74
|
+
@name = @setting[:name]
|
75
|
+
@lang = @setting[:lang]
|
76
|
+
@genre = @setting[:genre]
|
77
|
+
@debug = @setting[:debug]
|
78
|
+
@final = @setting[:final]
|
79
|
+
@option = @setting[:option]
|
80
|
+
@format = @setting[:format] || 'markdown'
|
81
|
+
@template = @setting[:template]
|
82
|
+
@dir_output = @setting[:dir_output] || File.join(@project, "out")
|
83
|
+
@dir_latex = File.join(@dir_output, ".tex")
|
84
|
+
@dir_html = File.join(@dir_output, "html")
|
85
|
+
@file_preface = @setting[:file_preface]
|
86
|
+
@file_chapters = @setting[:file_chapters]
|
87
|
+
@file_appendix = @setting[:file_appendix]
|
88
|
+
end
|
89
|
+
|
90
|
+
def save
|
91
|
+
Utils.log_info("Generate project #{@name.upcase}\n")
|
92
|
+
mkdir
|
93
|
+
mkdir("src")
|
94
|
+
mkdir("images")
|
95
|
+
touch("images", ".keep")
|
96
|
+
mkdir("resources")
|
97
|
+
touch("resources", ".keep")
|
98
|
+
touch(".gitignore")
|
99
|
+
save_setting
|
100
|
+
end
|
101
|
+
|
102
|
+
def mkdir(*string)
|
103
|
+
target = File.join(@project, string)
|
104
|
+
file = File.join(@name, string)
|
105
|
+
unless Dir.exist?(target)
|
106
|
+
puts "\t\033[32mcreate\033[0m #{file}"
|
107
|
+
FileUtils.mkdir_p(target)
|
108
|
+
else
|
109
|
+
puts "\t\033[31mexists\033[0m #{file}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def touch(*string)
|
114
|
+
if string.length < 3
|
115
|
+
source = File.join(TEMPLATE, string)
|
116
|
+
target = File.join(@project, string)
|
117
|
+
else
|
118
|
+
source = File.join(TEMPLATE, string[0..-2])
|
119
|
+
string.delete_at(-2)
|
120
|
+
string[0] = "src"
|
121
|
+
target = File.join(@project, string)
|
122
|
+
end
|
123
|
+
file = File.join(@name, string)
|
124
|
+
unless File.exist?(target)
|
125
|
+
puts "\t\033[32mcreate\033[0m #{file}"
|
126
|
+
template = ERB.new(File.read(source))
|
127
|
+
IO.write(target, template.result(binding))
|
128
|
+
else
|
129
|
+
puts "\t\033[31mexists\033[0m #{file}"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def get_name(template, name=nil)
|
134
|
+
prefix = template[0..3]
|
135
|
+
rank = get_rank(prefix)
|
136
|
+
name = template[9..-4] if name.nil?
|
137
|
+
"#{prefix}#{rank}-#{name}.md"
|
138
|
+
end
|
139
|
+
|
140
|
+
def get_rank(prefix)
|
141
|
+
Dir.chdir(File.join(@project, "src"))
|
142
|
+
num = Dir["#{prefix}*"].length + 10
|
143
|
+
100*num
|
144
|
+
end
|
145
|
+
|
146
|
+
def add(template, name)
|
147
|
+
name = get_name(template, name)
|
148
|
+
touch(@lang, template, name)
|
149
|
+
end
|
150
|
+
|
151
|
+
def list_template
|
152
|
+
Dir.chdir(File.join(TEMPLATE, @lang))
|
153
|
+
Dir["*.md"]
|
154
|
+
end
|
155
|
+
|
156
|
+
def check_environment
|
157
|
+
missing = ['pandoc', 'xelatex'].reject { |command| Utils.command_exists?(command) }
|
158
|
+
unless missing.empty?
|
159
|
+
Utils.log_error "Missing dependencies: #{missing.join(', ')}."
|
160
|
+
puts "\n\tInstall these and try again."
|
161
|
+
exit
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def load_config
|
166
|
+
@config_file = File.join(ROOT, "config.yml")
|
167
|
+
if File.exists? @config_file
|
168
|
+
configs = YAML.load_file(@config_file)
|
169
|
+
@config = configs["default"]
|
170
|
+
@config.merge!(configs[@lang]) if configs[@lang]
|
171
|
+
end
|
172
|
+
|
173
|
+
@config_file = File.join(@project, "src", "config.yml")
|
174
|
+
if File.exists? @config_file
|
175
|
+
configs = YAML.load_file(@config_file)
|
176
|
+
@config.merge!(configs) if configs
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def save_config
|
181
|
+
IO.write(@config_file, @config.to_yaml)
|
182
|
+
end
|
183
|
+
|
184
|
+
def save_setting
|
185
|
+
@setting.delete(:command)
|
186
|
+
@setting.delete(:dir_source)
|
187
|
+
@setting.delete(:dir_output)
|
188
|
+
@setting.delete(:dir_latex)
|
189
|
+
@setting.delete(:workspace)
|
190
|
+
@setting.delete(:project)
|
191
|
+
@setting.delete(:final)
|
192
|
+
@setting.delete(:debug)
|
193
|
+
@setting_file = File.join(@project, SETTING_FILE)
|
194
|
+
IO.write(@setting_file, @setting.to_yaml)
|
195
|
+
end
|
196
|
+
|
197
|
+
def markdown2latex(regex)
|
198
|
+
Dir.chdir(@project)
|
199
|
+
files = File.join("src", regex)
|
200
|
+
|
201
|
+
Utils.log_info("Parsing markdown ... #{files}:\n")
|
202
|
+
markdown = Dir["#{files}"].sort.map do |file|
|
203
|
+
puts "\t\033[32minclude\033[0m #{file}"
|
204
|
+
IO.read(file)
|
205
|
+
end.join("\n\n")
|
206
|
+
|
207
|
+
Utils.log_info("Convert markdown into latex ... ")
|
208
|
+
latex = IO.popen("pandoc --no-wrap --chapters -f #{@format} -t latex", 'w+') do |pipe|
|
209
|
+
pipe.write(Utils.pre_pandoc(markdown))
|
210
|
+
pipe.close_write
|
211
|
+
Utils.post_pandoc(pipe.read)
|
212
|
+
end
|
213
|
+
puts "done"
|
214
|
+
|
215
|
+
return latex
|
216
|
+
end
|
217
|
+
|
218
|
+
def markdown2index(regex)
|
219
|
+
Dir.chdir(@project)
|
220
|
+
files = File.join("src", regex)
|
221
|
+
|
222
|
+
Utils.log_info("Indexing markdown ... #{files}:\n")
|
223
|
+
index_string = []
|
224
|
+
Dir["#{files}"].sort.map do |file|
|
225
|
+
title_raw = IO.readlines(file)[0]
|
226
|
+
title = if title_raw.nil? || title_raw.strip.empty?
|
227
|
+
'未命名'
|
228
|
+
else
|
229
|
+
title_raw
|
230
|
+
.chomp # 删除换行符
|
231
|
+
.gsub(/^#+\s*/, '') # 删除行首的 # 号
|
232
|
+
.gsub(/\s*\{.*?\}\s*$/, '') # 删除行尾的标识符
|
233
|
+
.gsub(/\s*#+\s*$/, '') # 删除行尾的 # 号
|
234
|
+
end
|
235
|
+
name = file.gsub(/^src\//, '')
|
236
|
+
index_string << {name: name, title: title}
|
237
|
+
end
|
238
|
+
index_string
|
239
|
+
end
|
240
|
+
|
241
|
+
def markdown2html(regex)
|
242
|
+
Dir.chdir(@project)
|
243
|
+
FileUtils.mkdir_p(@dir_html) unless Dir.exist?(@dir_html)
|
244
|
+
files = File.join("src", regex)
|
245
|
+
|
246
|
+
Utils.log_info("Parsing markdown ... #{files}:\n")
|
247
|
+
Dir["#{files}"].sort.map do |file|
|
248
|
+
puts "\t\033[32mconvert\033[0m #{file}"
|
249
|
+
markdown = IO.read(file)
|
250
|
+
html = IO.popen("pandoc --no-wrap --chapters -f #{@format} -t html", 'w+') do |pipe|
|
251
|
+
pipe.write(markdown)
|
252
|
+
pipe.close_write
|
253
|
+
pipe.read
|
254
|
+
end
|
255
|
+
IO.write(File.join(@dir_html, "#{File.basename(file, '.md')}.htm"), html)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def generate_main_file
|
260
|
+
Dir.chdir(@project)
|
261
|
+
FileUtils.mkdir_p(@dir_latex) unless Dir.exist?(@dir_latex)
|
262
|
+
|
263
|
+
Utils.log_info("Generate main.tex file ...\n")
|
264
|
+
target = File.join(@dir_latex, "main.tex")
|
265
|
+
source = File.join(ROOT, "template_#{@template}.tex")
|
266
|
+
template = ERB.new(File.read(source))
|
267
|
+
IO.write(target, template.result(binding))
|
268
|
+
end
|
269
|
+
|
270
|
+
def latex2pdf
|
271
|
+
Dir.chdir(@project)
|
272
|
+
Dir.mkdir(@dir_output) unless Dir.exist?(@dir_output)
|
273
|
+
|
274
|
+
Utils.log_info("Run xelatex main.tex ...\n")
|
275
|
+
num = @final ? 2 : 1
|
276
|
+
num.times do |i|
|
277
|
+
IO.popen("xelatex -output-directory='#{@dir_latex}' #{@dir_latex}/main.tex 2>&1") do |pipe|
|
278
|
+
while line = pipe.gets
|
279
|
+
STDERR.print line if @debug
|
280
|
+
end
|
281
|
+
end
|
282
|
+
Utils.log_info("Run xelatex main.tex #{i+1} time(s).\n")
|
283
|
+
end
|
284
|
+
Utils.log_info("Generate PDF Complete!\n")
|
285
|
+
|
286
|
+
source = File.join(@dir_latex, "main.pdf")
|
287
|
+
target = File.join(@dir_output, "#{@name}.#{@lang}.pdf")
|
288
|
+
Utils.log_info("Moving output to #{target}.\n")
|
289
|
+
FileUtils.cp(source, target)
|
290
|
+
end
|
291
|
+
|
292
|
+
def show
|
293
|
+
puts @project
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Mkbook
|
2
|
+
class MkbookBuild < Mkbook
|
3
|
+
self.abstract_command = true
|
4
|
+
self.command = 'build'
|
5
|
+
self.summary = '生成电子书'
|
6
|
+
self.description = '生成各种格式的电子书'
|
7
|
+
|
8
|
+
def run
|
9
|
+
super
|
10
|
+
puts "mkbook build #{self.class.command}"
|
11
|
+
end
|
12
|
+
|
13
|
+
class PDF < MkbookBuild
|
14
|
+
self.summary = 'Generate pdf output'
|
15
|
+
end
|
16
|
+
|
17
|
+
class HTML < MkbookBuild
|
18
|
+
self.summary = 'Generate html output'
|
19
|
+
end
|
20
|
+
|
21
|
+
class EPUB < MkbookBuild
|
22
|
+
self.summary = 'Generate epub output'
|
23
|
+
end
|
24
|
+
|
25
|
+
class MOBI < MkbookBuild
|
26
|
+
self.summary = 'Generate mobi output'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
\documentclass[adobefonts,fancyhdr,fntef,footer,<%= @option %>]{htexart}
|
2
|
+
|
3
|
+
\title{<%= @config["title"] %>}
|
4
|
+
\author{<%= @config["author"] %>}
|
5
|
+
\date{<%= @config["date"] %>}
|
6
|
+
|
7
|
+
\def\contentsname{<%= @config["contents"] %>}
|
8
|
+
\def\figurename{<%= @config["figure"] %>}
|
9
|
+
\def\tablename{<%= @config["table"] %>}
|
10
|
+
\def\appendixname{<%= @config["appendix"] %>}
|
11
|
+
|
12
|
+
\begin{document}
|
13
|
+
\maketitle
|
14
|
+
|
15
|
+
\tableofcontents
|
16
|
+
|
17
|
+
<%= @chapters %>
|
18
|
+
|
19
|
+
\addcontentsline{toc}{section}{\refname}
|
20
|
+
\bibliography{/usr/local/texlive/2013/texmf-dist/tex/latex/htex/htexbib}
|
21
|
+
\end{document}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
\documentclass[adobefonts,fancyhdr,fntef,footer,<%= @option %>]{htexart}
|
2
|
+
|
3
|
+
\title{<%= @config["title"] %>}
|
4
|
+
\author{<%= @config["author"] %>}
|
5
|
+
\date{<%= @config["date"] %>}
|
6
|
+
|
7
|
+
\def\contentsname{<%= @config["contents"] %>}
|
8
|
+
\def\figurename{<%= @config["figure"] %>}
|
9
|
+
\def\tablename{<%= @config["table"] %>}
|
10
|
+
\def\appendixname{<%= @config["appendix"] %>}
|
11
|
+
|
12
|
+
\begin{document}
|
13
|
+
|
14
|
+
<%= @chapters %>
|
15
|
+
|
16
|
+
\addcontentsline{toc}{section}{\refname}
|
17
|
+
\bibliography{/usr/local/texlive/2013/texmf-dist/tex/latex/htex/htexbib}
|
18
|
+
|
19
|
+
|
20
|
+
\vskip2cm
|
21
|
+
|
22
|
+
\begin{quote}
|
23
|
+
\textbf{开源书屋}致力于建立一整套编写电子书的解决方案, 并提供大量开源免费、高质量的电子书.
|
24
|
+
请关注我们的\href{http://weibo.com/oboooks}{官方微博}, 及时获取最新资源!
|
25
|
+
\end{quote}
|
26
|
+
\end{document}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
\documentclass[adobefonts,fancyhdr,fntef,header,<%= @option %>]{htexbook}
|
2
|
+
|
3
|
+
\title{<%= @config["title"] %>}
|
4
|
+
\author{<%= @config["author"] %>}
|
5
|
+
\date{<%= @config["date"] %>}
|
6
|
+
|
7
|
+
\def\contentsname{<%= @config["contents"] %>}
|
8
|
+
\def\figurename{<%= @config["figure"] %>}
|
9
|
+
\def\tablename{<%= @config["table"] %>}
|
10
|
+
\def\appendixname{<%= @config["appendix"] %>}
|
11
|
+
|
12
|
+
\begin{document}
|
13
|
+
\maketitle
|
14
|
+
|
15
|
+
\frontmatter
|
16
|
+
<%= @preface %>
|
17
|
+
|
18
|
+
\tableofcontents
|
19
|
+
% \listoffigures
|
20
|
+
% \listoftables
|
21
|
+
|
22
|
+
\mainmatter
|
23
|
+
<%= @chapters %>
|
24
|
+
|
25
|
+
\begin{appendix}
|
26
|
+
<%= @appendix %>
|
27
|
+
\end{appendix}
|
28
|
+
|
29
|
+
\backmatter
|
30
|
+
\addcontentsline{toc}{chapter}{\refname}
|
31
|
+
\bibliography{/usr/local/texlive/2013/texmf-dist/tex/latex/htex/htexbib}
|
32
|
+
\newpage
|
33
|
+
\addcontentsline{toc}{chapter}{\indexname}
|
34
|
+
\printindex
|
35
|
+
\end{document}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
\documentclass[adobefonts,fancyhdr,fntef,header,<%= @option %>]{htexbook}
|
2
|
+
|
3
|
+
\title{<%= @config["title"] %>}
|
4
|
+
\author{<%= @config["author"] %>}
|
5
|
+
\date{<%= @config["date"] %>}
|
6
|
+
|
7
|
+
\def\contentsname{<%= @config["contents"] %>}
|
8
|
+
\def\figurename{<%= @config["figure"] %>}
|
9
|
+
\def\tablename{<%= @config["table"] %>}
|
10
|
+
\def\appendixname{<%= @config["appendix"] %>}
|
11
|
+
\setcounter{secnumdepth}{-2}
|
12
|
+
\setcounter{tocdepth}{0}
|
13
|
+
\begin{document}
|
14
|
+
\maketitle
|
15
|
+
|
16
|
+
\frontmatter
|
17
|
+
<%= @preface %>
|
18
|
+
|
19
|
+
\tableofcontents
|
20
|
+
% \listoffigures
|
21
|
+
% \listoftables
|
22
|
+
|
23
|
+
\mainmatter
|
24
|
+
<%= @chapters %>
|
25
|
+
|
26
|
+
\begin{appendix}
|
27
|
+
<%= @appendix %>
|
28
|
+
\end{appendix}
|
29
|
+
|
30
|
+
\backmatter
|
31
|
+
\addcontentsline{toc}{chapter}{\refname}
|
32
|
+
\bibliography{/usr/local/texlive/2013/texmf-dist/tex/latex/htex/htexbib}
|
33
|
+
\newpage
|
34
|
+
\addcontentsline{toc}{chapter}{\indexname}
|
35
|
+
\printindex
|
36
|
+
\end{document}
|
data/lib/mkbook/utils.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'replace'
|
2
|
+
|
3
|
+
module Mkbook
|
4
|
+
class Utils
|
5
|
+
def self.pre_pandoc(string)
|
6
|
+
replace = Replace.new(string)
|
7
|
+
replace.pre_pandoc_for_latex
|
8
|
+
replace.string
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.post_pandoc(string)
|
12
|
+
replace = Replace.new(string)
|
13
|
+
replace.post_pandoc_for_latex
|
14
|
+
replace.string
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.command_exists?(command)
|
18
|
+
if File.executable?(command) then
|
19
|
+
return command
|
20
|
+
end
|
21
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).map do |path|
|
22
|
+
cmd = "#{path}/#{command}"
|
23
|
+
File.executable?(cmd) || File.executable?("#{cmd}.exe") || File.executable?("#{cmd}.cmd")
|
24
|
+
end.inject { |a, b| a || b }
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.log(type, msg)
|
28
|
+
print "[#{type}] #{Time.now} #{msg}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.log_info(msg)
|
32
|
+
log("INFO", msg)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.log_error(msg)
|
36
|
+
log("ERROR", msg)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.log_debug(msg)
|
40
|
+
log("DEBUG", msg)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/mkbook/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
This book ...
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
本书...
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mkbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henry He
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
@@ -52,26 +52,82 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: claide
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.9.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colored
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: replace
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.2
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.2
|
55
97
|
description: the ebook generate tools from markdown plain text
|
56
98
|
email:
|
57
99
|
- henryhyn@163.com
|
58
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- mkbook
|
59
102
|
extensions: []
|
60
103
|
extra_rdoc_files: []
|
61
104
|
files:
|
62
|
-
-
|
63
|
-
- .rspec
|
64
|
-
- .travis.yml
|
65
|
-
- CODE_OF_CONDUCT.md
|
66
|
-
- Gemfile
|
67
|
-
- LICENSE.txt
|
68
|
-
- README.md
|
69
|
-
- Rakefile
|
70
|
-
- bin/console
|
105
|
+
- bin/mkbook
|
71
106
|
- bin/setup
|
72
|
-
- lib/mkbook.
|
107
|
+
- lib/mkbook/config.yml
|
108
|
+
- lib/mkbook/make_book.rb
|
109
|
+
- lib/mkbook/mkbook.rb
|
110
|
+
- lib/mkbook/mkbook_build.rb
|
111
|
+
- lib/mkbook/mkbook_new.rb
|
112
|
+
- lib/mkbook/template_article.tex
|
113
|
+
- lib/mkbook/template_blog.tex
|
114
|
+
- lib/mkbook/template_book.tex
|
115
|
+
- lib/mkbook/template_novel.tex
|
116
|
+
- lib/mkbook/utils.rb
|
73
117
|
- lib/mkbook/version.rb
|
74
|
-
- mkbook.
|
118
|
+
- lib/mkbook.rb
|
119
|
+
- lib/template/en/appx0000-plain.md
|
120
|
+
- lib/template/en/chap0000-plain.md
|
121
|
+
- lib/template/en/desc0000-plain.md
|
122
|
+
- lib/template/en/face0000-plain.md
|
123
|
+
- lib/template/zh/appx0000-plain.md
|
124
|
+
- lib/template/zh/chap0000-plain.md
|
125
|
+
- lib/template/zh/desc0000-plain.md
|
126
|
+
- lib/template/zh/face0000-plain.md
|
127
|
+
- lib/template/.mkbook.yml
|
128
|
+
- lib/template/.gitignore
|
129
|
+
- lib/template/images/.keep
|
130
|
+
- lib/template/resources/.keep
|
75
131
|
homepage: https://github.com/henryhyn/mkbook
|
76
132
|
licenses:
|
77
133
|
- MIT
|
@@ -89,9 +145,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
145
|
requirements:
|
90
146
|
- - '>='
|
91
147
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
148
|
+
version: 1.3.6
|
93
149
|
requirements: []
|
94
|
-
rubyforge_project:
|
150
|
+
rubyforge_project: mkbook
|
95
151
|
rubygems_version: 2.0.14
|
96
152
|
signing_key:
|
97
153
|
specification_version: 4
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
-
|
5
|
-
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
-
|
7
|
-
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
-
|
9
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
-
|
11
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
-
|
13
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2015 Henry He
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# Mkbook
|
2
|
-
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mkbook`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'mkbook'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install mkbook
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mkbook. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
-
|
37
|
-
|
38
|
-
## License
|
39
|
-
|
40
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "mkbook"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
data/mkbook.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'mkbook/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'mkbook'
|
8
|
-
spec.version = Mkbook::VERSION
|
9
|
-
spec.authors = ['Henry He']
|
10
|
-
spec.email = ['henryhyn@163.com']
|
11
|
-
|
12
|
-
spec.summary = %q{tools to generate ebooks from markdown}
|
13
|
-
spec.description = %q{the ebook generate tools from markdown plain text}
|
14
|
-
spec.homepage = 'https://github.com/henryhyn/mkbook'
|
15
|
-
spec.license = 'MIT'
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir = 'exe'
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = ['lib']
|
21
|
-
|
22
|
-
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
-
spec.add_development_dependency 'rspec'
|
25
|
-
end
|