mkbook 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d464ccfc2afc5aa1c72a74b59909ce2d7e9fae09
4
- data.tar.gz: d3b84a9df4b9c82240f0efe27a258f1b76ec2605
3
+ metadata.gz: 93b82aa96b3be588a1a1c4af627e232daa692e4f
4
+ data.tar.gz: bbc7a86a68941dacfaeeb3d74c55a07970305fd0
5
5
  SHA512:
6
- metadata.gz: ec1bf3dbbc331b68a41fde3705343c97c5ebd11399e285aef8e1312f2dfcff1ebc91719be8c14eecdf42b9b87f27c432977131cf7afcb0dcf13b53f77d4d5b74
7
- data.tar.gz: 09ee583d76ba889e33228407c4fee6e63179434996e76edf9d4b58e213492911458217a623f9bf35b841d8e70d80c30eeacfed8db05e709b2a0677b7a87d1b1d
6
+ metadata.gz: 5961f02634aa1eb6d50c8075a32b7ef69edd4fea4970684a9a9878a0009db08b82e014a755bdcbfd17704604b5df3b8985176ef6fd730be7201bb37f0634828a
7
+ data.tar.gz: f71e2e152243f5f8398bfe6b5ffa06907e529bb41d10462350a6d14cb3bd5e3132957108ba313aef7f7a0becaf6e2a651067fcfa484fa0605e19655f18f65b70
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ *.gem
2
+ /.idea/
3
+ /.bundle/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
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 ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mkbook.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
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 ADDED
@@ -0,0 +1,41 @@
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 ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
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/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module Mkbook
2
+ VERSION = '2.0.0'
3
+ end
data/lib/mkbook.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "mkbook/version"
2
+
3
+ module Mkbook
4
+ # Your code goes here...
5
+ end
data/mkbook.gemspec ADDED
@@ -0,0 +1,25 @@
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
metadata CHANGED
@@ -1,43 +1,80 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry He
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2013-08-26 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  description: the ebook generate tools from markdown plain text
14
56
  email:
15
57
  - henryhyn@163.com
16
- executables:
17
- - mkbook
58
+ executables: []
18
59
  extensions: []
19
60
  extra_rdoc_files: []
20
61
  files:
21
- - bin/mkbook
22
- - lib/config.yml
23
- - lib/make_book.rb
24
- - lib/template_article.tex
25
- - lib/template_blog.tex
26
- - lib/template_book.tex
27
- - lib/template_fancy.tex
28
- - lib/template_novel.tex
29
- - lib/template_plain.tex
30
- - template/.mkbook.yml
31
- - template/en/appx01-abbreviation.md
32
- - template/en/chap01-introduce.md
33
- - template/en/preface.md
34
- - template/images/README.md
35
- - template/resources/README.md
36
- - template/zh/appx01-abbreviation.md
37
- - template/zh/chap01-introduce.md
38
- - template/zh/preface.md
39
- homepage:
40
- licenses: []
62
+ - .gitignore
63
+ - .rspec
64
+ - .travis.yml
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/mkbook.rb
73
+ - lib/mkbook/version.rb
74
+ - mkbook.gemspec
75
+ homepage: https://github.com/henryhyn/mkbook
76
+ licenses:
77
+ - MIT
41
78
  metadata: {}
42
79
  post_install_message:
43
80
  rdoc_options: []
@@ -55,8 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
92
  version: '0'
56
93
  requirements: []
57
94
  rubyforge_project:
58
- rubygems_version: 2.0.3
95
+ rubygems_version: 2.0.14
59
96
  signing_key:
60
97
  specification_version: 4
61
- summary: mkbook is a ebook maker.
98
+ summary: tools to generate ebooks from markdown
62
99
  test_files: []
data/bin/mkbook DELETED
@@ -1,117 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
-
4
- require 'optparse'
5
- require 'fileutils'
6
- require 'erb'
7
- require 'yaml'
8
- require 'make_book'
9
-
10
- include FileUtils
11
-
12
- # here -- work directory
13
- here = Dir.getwd
14
- # root -- program directory
15
- root = File.dirname(__FILE__)
16
-
17
- # 设置默认选项
18
- options = {
19
- "lang" => "zh",
20
- "build" => "pdf",
21
- "template" => "book",
22
- "option" => "a5paper,openany",
23
- "dir.output" => "out",
24
- "dir.latex" => ".tex",
25
- "file.preface" => "preface.md",
26
- "file.chapters" => "chap*.md",
27
- "file.appendix" => "appx*.md"
28
- }
29
-
30
- # 加载配置文件
31
- config_file = File.join('.mkbook.yml')
32
- if File.exists? config_file
33
- config_options = YAML.load_file(config_file)
34
- options.merge!(config_options) if config_options
35
- end
36
-
37
- # 定义选项解析器
38
- OptionParser.new do |opts|
39
- executable_name = File.basename($PROGRAM_NAME)
40
- opts.banner = "Make ebooks from markdown plain text
41
- Usage: #{executable_name} [options]\n"
42
-
43
- # 定义输出格式
44
- opts.on("-b","--build FORMAT","build format: pdf,html,epub. seperated by ','") do |format|
45
- formatOptions = format.split(",")
46
- formatOptions.each do |fmt|
47
- unless ["pdf","html","epub"].include?(fmt)
48
- raise ArgumentError,"FORMAT must be one of 'pdf,html,epub' format"
49
- end
50
- end
51
- options["build"] = formatOptions
52
- end
53
-
54
- # 定义 debug 模式, 输出更多信息, 用于调试
55
- opts.on("-d","--[no-]debug","debug mode") do |setting|
56
- options["debug"] = setting
57
- end
58
-
59
- # 定义 定稿 模式, 编译三遍, 建立索引、参考文献
60
- opts.on("-f","--[no-]final","final mode") do |setting|
61
- options["final"] = setting
62
- end
63
-
64
- # 选择语言类型
65
- opts.on("-l","--lang LANG","language selection") do |lang|
66
- options["lang"] = lang
67
- end
68
-
69
- # 选择模板
70
- opts.on("-t","--template template.tex","latex template file") do |template|
71
- unless File.exists? template
72
- raise ArgumentError,"template file \"#{template}\" doesn't exist"
73
- end
74
- options["template"] = template
75
- end
76
-
77
- # 设置书的名字
78
- opts.on("-n","--name book name","book name") do |name|
79
- unless name =~ /^[a-zA-Z0-9-]+$/
80
- raise ArgumentError,"name should be [a-zA-Z0-9-]"
81
- end
82
- options["name"] = name
83
- end
84
-
85
- # 定义生成器
86
- opts.on("-g","--generate project","project name") do |name|
87
- unless name =~ /^[a-zA-Z0-9-]+$/
88
- raise ArgumentError,"name should be [a-zA-Z0-9-]"
89
- end
90
- options["command"] = "generate"
91
- options["name"] = name
92
- end
93
- end.parse!
94
-
95
- options["name"] = File.basename(here) unless options["name"]
96
-
97
- puts options.inspect if options["debug"]
98
-
99
- if options["command"] == "generate"
100
- generate_project(options)
101
- exit
102
- end
103
-
104
- unless File.exists? config_file
105
- log_error("This is not an ebook project, or missing .mkbook.yml.
106
- Use the following command to generate project first,
107
- mkbook --generate <foo>
108
- Or create an empty file .mkbook.yml manually.\n")
109
- exit
110
- end
111
-
112
- if options["build"].include?("pdf")
113
- generate_pdf(options)
114
- end
115
-
116
- # 将选项写入文件
117
- File.write('.mkbook.yml',options.to_yaml)
data/lib/config.yml DELETED
@@ -1,20 +0,0 @@
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
data/lib/make_book.rb DELETED
@@ -1,267 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
-
4
- require 'pathname'
5
-
6
- def generate_project(options)
7
- root = File.dirname(__FILE__)
8
- source = "#{root}/../template"
9
- target = options["name"]
10
- lang = options["lang"]
11
- log_info("Generate project #{target.upcase}\n")
12
- create_from_template("#{source}", "#{target}", :recursive => false)
13
- create_from_template("#{source}/.mkbook.yml", "#{target}/.mkbook.yml")
14
- create_from_template("#{source}/images", "#{target}/images")
15
- create_from_template("#{source}/resources", "#{target}/resources")
16
- create_from_template("#{source}/#{lang}", "#{target}/#{lang}")
17
- log_info("Generate #{target.upcase} complete!\n")
18
- end
19
-
20
- def create_from_template(source, target, options={:recursive => true})
21
- if File.directory? source
22
- if !Dir.exist? target
23
- Dir.mkdir(target)
24
- puts "\t\033[32mcreate\033[0m #{target}"
25
- else
26
- puts "\t\033[31mexists\033[0m #{target}"
27
- end
28
- if options[:recursive]
29
- Dir.foreach(source) do |file|
30
- if file != "." and file != ".."
31
- sub_source = File.join(source, file)
32
- sub_target = File.join(target, file)
33
- create_from_template(sub_source, sub_target)
34
- end
35
- end
36
- end
37
- else
38
- if !File.exists? target
39
- cp(source, target)
40
- puts "\t\033[32mcreate\033[0m #{target}"
41
- else
42
- puts "\t\033[31mexists\033[0m #{target}"
43
- end
44
- end
45
- end
46
-
47
- def traverse_dir(path)
48
- if File.directory? path
49
- Dir.foreach(path) do |file|
50
- if file != "." and file != ".."
51
- traverse_dir(File.join(path, file))
52
- end
53
- end
54
- else
55
- puts path
56
- end
57
- end
58
-
59
- def generate_pdf(options)
60
- log_info("Generate PDF ...\n")
61
-
62
- root = File.dirname(__FILE__)
63
- lang = options["lang"]
64
-
65
- config_file = "#{root}/config.yml"
66
- if File.exists? config_file
67
- opts = YAML.load_file(config_file)
68
- config_options = opts["default"]
69
- config_options.merge!(opts[lang]) if opts[lang]
70
- end
71
-
72
- config_file = "#{lang}/config.yml"
73
- if File.exists? config_file
74
- opts = YAML.load_file(config_file)
75
- config_options.merge!(opts) if opts
76
- end
77
-
78
- template = ERB.new(File.read("#{root}/template_#{options["template"]}.tex"))
79
-
80
- missing = ['pandoc', 'xelatex'].reject{|command| command_exists?(command)}
81
- unless missing.empty?
82
- log_error "Missing dependencies: #{missing.join(', ')}."
83
- puts "\n\tInstall these and try again."
84
- exit
85
- end
86
-
87
- Dir.mkdir(options["dir.latex"]) if !Dir.exist? options["dir.latex"]
88
- Dir.mkdir(options["dir.output"]) if !Dir.exist? options["dir.output"]
89
-
90
- preface = markdown2latex("file.preface" ,options)
91
- chapters = markdown2latex("file.chapters",options)
92
- appendix = markdown2latex("file.appendix",options)
93
-
94
- File.open("#{options["dir.latex"]}/main.tex", 'w') do |file|
95
- file.write(template.result(binding))
96
- end
97
-
98
- abort = false
99
- log_info("Running xelatex main.tex:\n")
100
- num = options["final"] ? 3 : 1
101
- num.times do |i|
102
- print "\tPass #{i+1} ... "
103
- line = ""
104
- IO.popen("xelatex -output-directory=\"#{options["dir.latex"]}\" \"#{options["dir.latex"]}/main.tex\" 2>&1") do |pipe|
105
- unless options["debug"]
106
- while line = pipe.gets and not abort
107
- if (RUBY_VERSION >= "1.9" and line.valid_encoding? and line =~ /^!\s/) or (RUBY_VERSION < "1.9" and line =~ /^!\s/)
108
- puts "failed with:\n\t\t\t#{line.strip}"
109
- puts "\tConsider running this again with --debug."
110
- abort = true
111
- end
112
- end
113
- else
114
- STDERR.print while pipe.gets rescue abort = true
115
- end
116
- end
117
- break if abort
118
- puts "done"
119
- next unless i == 0 and options["final"]
120
- IO.popen("cd #{options["dir.latex"]}; bibtex main 2>&1") do |pipe|
121
- if options["debug"]
122
- STDERR.print while pipe.gets rescue abort = true
123
- end
124
- end
125
- end
126
-
127
- unless abort
128
- log_info("Moving output to #{options["dir.output"]}/#{options["name"]}.#{options["lang"]}.pdf ... ")
129
- cp("#{options["dir.latex"]}/main.pdf", "#{options["dir.output"]}/#{options["name"]}.#{options["lang"]}.pdf")
130
- puts "done"
131
- else
132
- log_error("Convert error, exit!\n")
133
- exit 1
134
- end
135
-
136
- File.write(config_file,config_options.to_yaml)
137
-
138
- log_info("Generate PDF Complete!\n")
139
- end
140
-
141
-
142
- def markdown2latex(regex, options)
143
- files = "#{options["lang"]}/#{options[regex]}"
144
- log_info("Parsing markdown ... #{files}:\n")
145
- markdown = Dir["#{files}"].sort.map do |file|
146
- list = file.split('.')
147
- file_name = list[0]
148
- file_ext = list[1]
149
- if file_ext == 'rmd'
150
- puts "\t\033[32mconvert\033[0m #{file}"
151
- system("rmd2md #{file}; mv *.md zh")
152
- file = "#{file_name}.md"
153
- end
154
- puts "\t\033[32minclude\033[0m #{file}"
155
- if options["jeykll"]
156
- check_jekyll(File.read(file))
157
- else
158
- File.read(file)
159
- end
160
- end.join("\n\n")
161
- log_info("Convert markdown into latex ... ")
162
- latex = IO.popen('pandoc --no-wrap --chapters -f markdown -t latex', 'w+') do |pipe|
163
- pipe.write(pre_pandoc(markdown))
164
- pipe.close_write
165
- post_pandoc(pipe.read)
166
- end
167
- puts "done"
168
- latex
169
- end
170
-
171
- def command_exists?(command)
172
- if File.executable?(command) then
173
- return command
174
- end
175
- ENV['PATH'].split(File::PATH_SEPARATOR).map do |path|
176
- cmd = "#{path}/#{command}"
177
- File.executable?(cmd) || File.executable?("#{cmd}.exe") || File.executable?("#{cmd}.cmd")
178
- end.inject{|a, b| a || b}
179
- end
180
-
181
- def replace(string, &block)
182
- string.instance_eval do
183
- alias :s :gsub!
184
- instance_eval(&block)
185
- end
186
- string
187
- end
188
-
189
- def pre_pandoc(string)
190
- prefix = "resources/"
191
- replace(string) do
192
- s /Insert\s(18333fig\d+)\.png\s*\n.*?\d{1,2}-\d{1,2}\. (.*)/, '![\2](\1-tn)'
193
- s /images\/(.*)\?raw=true/, '\1'
194
- s /\[@(.*?)\]/, '\citep{\1}'
195
- s /% latex table generated in R.*?2013\r?\n/m, ''
196
- s /\.\.\/images\//, ''
197
- s /{@code\s*(.*?)}/m, '`\1`'
198
- s /{@link\s*([^ ]*?)\s*([^ ]*?)}/m, '[\1](\2)'
199
- # s /^\r?\n([ ]{4}>)/m, '\n```{r}\n\1'
200
- # s /([ ]{4}>.*?)\r?\n([ ]{4}[^>])/m, '\1\n```\2'
201
- s /```{\.(\S*?) label="(.*?)", eval=TRUE}(.*?)```/m do |match|
202
- source_file = prefix + $2 + extension($1)
203
- result_file = prefix + $2 + ".res"
204
- code = File.new(source_file, "w")
205
- code.puts include_before($1)
206
- code.puts $3
207
- code.close
208
- `chmod a+x #{source_file}`
209
- `./#{source_file} > #{result_file} 2>&1`
210
- "```{.#{$1}}#{$3}```\n\n输出结果\n\n```\n#{IO.read(result_file)}```"
211
- end
212
- s /^---\r?\n(.*?)^---\r?\n/m do |match|
213
- doc_options=YAML::load($1)
214
- '#' + doc_options['title'] if doc_options['title']
215
- # about_title = doc_options['source'] ? "本文选自 #{doc_options['source']}." : ""
216
- # about_title += doc_options['date'] ? "修改日期: #{doc_options['date']}." : ""
217
- # about_title = '\thanks{' + about_title + '}' unless about_title == ""
218
- # meta_info = ''
219
- # meta_info += ('\title{' + doc_options['title'] + about_title + '}') if doc_options['title']
220
- # meta_info += ('\author{' + doc_options['author'] + '}') if doc_options['author']
221
- # meta_info += '\date{}\maketitle'
222
- end
223
- end
224
- end
225
-
226
- def include_before(lang)
227
- case lang
228
- when "ruby" ; "#!/usr/bin/env ruby"
229
- when "bash" ; "#!/bin/bash"
230
- when "python"; "#!/usr/bin/python"
231
-
232
- end
233
- end
234
-
235
- def extension(lang)
236
- case lang
237
- when "ruby" ; ".rb"
238
- when "bash" ; ".sh"
239
- when "python"; ".py"
240
- end
241
- end
242
-
243
- def post_pandoc(string)
244
- replace(string) do
245
- s /{verbatim}/, '{Verbatim}'
246
- # s /^.*{Shaded}.*\r?\n/, ''
247
- # s /^.*begin{Highlighting}.*\r?\n/, '\\obeylines\\obeyspace'
248
- # s /^.*end{Highlighting}.*\r?\n/, ''
249
- end
250
- end
251
-
252
-
253
- def log(type,msg)
254
- print "[#{type}] #{Time.now} #{msg}"
255
- end
256
-
257
- def log_info(msg)
258
- log("INFO",msg)
259
- end
260
-
261
- def log_error(msg)
262
- log("ERROR",msg)
263
- end
264
-
265
- def log_debug(msg)
266
- log("DEBUG",msg)
267
- end
@@ -1,22 +0,0 @@
1
- \documentclass[adobefonts,fancyhdr,fntef,footer,<%= options["option"] %>]{htexart}
2
-
3
- \title{<%= config_options["title"] %>}
4
- \author{<%= config_options["author"] %>}
5
- \date{<%= config_options["date"] %>}
6
-
7
- \def\contentsname{<%= config_options["contents"] %>}
8
- \def\figurename{<%= config_options["figure"] %>}
9
- \def\tablename{<%= config_options["table"] %>}
10
- \def\appendixname{<%= config_options["appendix"] %>}
11
-
12
- \begin{document}
13
- \maketitle
14
- <%= preface %>
15
-
16
- \tableofcontents
17
-
18
- <%= chapters %>
19
-
20
- %\addcontentsline{toc}{section}{\refname}
21
- %\bibliography{/usr/local/texlive/2013/texmf-dist/tex/latex/htex/htexbib}
22
- \end{document}
@@ -1,26 +0,0 @@
1
- \documentclass[adobefonts,fancyhdr,fntef,footer,<%= options["option"] %>]{htexart}
2
-
3
- \title{<%= config_options["title"] %>}
4
- \author{<%= config_options["author"] %>}
5
- \date{<%= config_options["date"] %>}
6
-
7
- \def\contentsname{<%= config_options["contents"] %>}
8
- \def\figurename{<%= config_options["figure"] %>}
9
- \def\tablename{<%= config_options["table"] %>}
10
- \def\appendixname{<%= config_options["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}
@@ -1,36 +0,0 @@
1
- \documentclass[adobefonts,fancyhdr,fntef,header,<%= options["option"] %>]{htexbook}
2
-
3
- \title{<%= config_options["title"] %>}
4
- \author{<%= config_options["author"] %>}
5
- \date{<%= config_options["date"] %>}
6
-
7
- \def\contentsname{<%= config_options["contents"] %>}
8
- \def\figurename{<%= config_options["figure"] %>}
9
- \def\tablename{<%= config_options["table"] %>}
10
- \def\appendixname{<%= config_options["appendix"] %>}
11
- % \setcounter{secnumdepth}{1}
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}
@@ -1,33 +0,0 @@
1
- \documentclass[a5paper,final,narrow,fancyhdr,adobefonts,<%= "english," if options["lang"]=="en" %><%= options["template"] %>,equal,openany,code]{htexbook}
2
-
3
- \title{<%= config_options["title"] %>}
4
- \author{<%= config_options["author"] %>}
5
- \date{<%= config_options["date"] %>}
6
- \no{1}
7
-
8
- \def\contentsname{<%= config_options["contents"] %>}
9
- \def\figurename{<%= config_options["figure"] %>}
10
- \def\tablename{<%= config_options["table"] %>}
11
- \def\appendixname{<%= config_options["appendix"] %>}
12
- \begin{document}
13
- \include{head}
14
- \maketitle
15
-
16
- \AddToShipoutPicture{\oldincludegraphics[width=\paperwidth,height=\paperheight]{background}}
17
- \pagenumbering{roman}
18
- <%= preface %>
19
-
20
- \tableofcontents
21
- % \listoffigures
22
- % \listoftables
23
-
24
- \newpage
25
- \pagenumbering{arabic}
26
- <%= chapters %>
27
-
28
- \begin{appendix}
29
- <%= appendix %>
30
- \end{appendix}
31
-
32
- % \include{foot}
33
- \end{document}
@@ -1,36 +0,0 @@
1
- \documentclass[adobefonts,fancyhdr,fntef,header,<%= options["option"] %>]{htexbook}
2
-
3
- \title{<%= config_options["title"] %>}
4
- \author{<%= config_options["author"] %>}
5
- \date{<%= config_options["date"] %>}
6
-
7
- \def\contentsname{<%= config_options["contents"] %>}
8
- \def\figurename{<%= config_options["figure"] %>}
9
- \def\tablename{<%= config_options["table"] %>}
10
- \def\appendixname{<%= config_options["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}
@@ -1,31 +0,0 @@
1
- \documentclass[a5paper,final,narrow,fancyhdr,adobefonts,graph,<%= "english," if options["lang"]=="en" %><%= options["template"] %>,equal,openany,code]{htexbook}
2
-
3
- \title{<%= config_options["title"] %>}
4
- \author{<%= config_options["author"] %>}
5
- \date{<%= config_options["date"] %>}
6
-
7
- \def\contentsname{<%= config_options["contents"] %>}
8
- \def\figurename{<%= config_options["figure"] %>}
9
- \def\tablename{<%= config_options["table"] %>}
10
- \def\appendixname{<%= config_options["appendix"] %>}
11
- \begin{document}
12
- \include{head}
13
- \maketitle
14
-
15
- \pagenumbering{roman}
16
- <%= preface %>
17
-
18
- \tableofcontents
19
- % \listoffigures
20
- % \listoftables
21
-
22
- \newpage
23
- \pagenumbering{arabic}
24
- <%= chapters %>
25
-
26
- \begin{appendix}
27
- <%= appendix %>
28
- \end{appendix}
29
-
30
- % \include{foot}
31
- \end{document}
data/template/.mkbook.yml DELETED
@@ -1,10 +0,0 @@
1
- ---
2
- lang: zh
3
- build: pdf
4
- template: book
5
- option: a5paper,openany
6
- dir.output: out
7
- dir.latex: .tex
8
- file.preface: preface.md
9
- file.chapters: chap*.md
10
- file.appendix: appx*.md
@@ -1,3 +0,0 @@
1
- # Abbreviation
2
-
3
- Item ...
@@ -1,3 +0,0 @@
1
- # Introduce
2
-
3
- Content ...
@@ -1,7 +0,0 @@
1
- # Preface
2
-
3
- This book ...
4
-
5
- #### Rule
6
-
7
- #### Reader
@@ -1,3 +0,0 @@
1
- # 图片目录
2
-
3
- 记录图片资料的来源, 以及转化过程.
@@ -1,3 +0,0 @@
1
- # 资料目录
2
-
3
- 记录各种资料的来源, 以及转化过程.
@@ -1,3 +0,0 @@
1
- # 缩略词
2
-
3
- 词条 ...
@@ -1,3 +0,0 @@
1
- # 简介
2
-
3
- 正文 ...
@@ -1,7 +0,0 @@
1
- # 前言
2
-
3
- 本书 ...
4
-
5
- #### 编写约定
6
-
7
- #### 适合读者