xpub 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c84badd5401427653a180811baaa090496227d5
4
+ data.tar.gz: 052e466221750865095a8e09961aa93a925a46df
5
+ SHA512:
6
+ metadata.gz: a254fa14825cd92a0852893951428e1a89c3848134baaca5ec9ce64d25706a71c2e1e006d0b4f75263597ac0973ef82308dfeb51678fd46c628f19f6eb1c6ec9
7
+ data.tar.gz: dd6b91f65f41b3f0ce57d85a90ecb1800644de9e235a8f48f9f43ce0bc5f8560d67979ab750df105fc4e0165b1d41eb51c5b5aecb49400a1fb9143b367bbce93
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xpub.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Yoshihisa AMAKATA
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,161 @@
1
+ # Xpub
2
+
3
+ Markdownから、PDFやEPUBを生成するためのフレームワークのプロトタイプです。
4
+
5
+ Ruby DSLによって1ファイルで生成のためのルールを設定できるようにし、
6
+ PDFやEPUB3の生成を自動化します。
7
+
8
+ このプロトタイプの目的は
9
+
10
+ * 多様化する出力フォーマットを1ソースで生成できるようにする場合のシンプルで、柔軟な定義方法の検証
11
+
12
+ です。
13
+
14
+ ## Installation
15
+
16
+ 動作確認はMacでしています。それ以外の環境については把握していませんがおそらくLinuxでも利用できると思います。
17
+
18
+ ```
19
+ $ gem install xpub
20
+ ```
21
+
22
+ でインストールします。
23
+
24
+ このツールを使うには他にPandocとLatexが必要です。
25
+
26
+
27
+ ### TeX Live
28
+
29
+ #### MacTex.pkgをダウンロードしてインストール
30
+
31
+ http://tug.org/mactex/
32
+
33
+ 参考) http://tandoori.hatenablog.com/entry/20130802/1375451791
34
+
35
+ #### TeX Live Utility.appを起動して、アップデート
36
+
37
+ ```
38
+ Yosemiteを使う場合は、まずTeX Live Utilityを更新すること、メニューの「TeX Liveユーティリティ > 更新があるか確認」で更新すること。
39
+ そうしないとうまくTeXをアップデートできない
40
+ ```
41
+
42
+ または
43
+
44
+ ```
45
+ $ sudo tlmgr update --self --all
46
+ ```
47
+
48
+ でもよいかも。
49
+
50
+ インストールディレクトリは
51
+
52
+ * 基本インストール
53
+ /usr/local/texlive/2014
54
+ * TEXMFLOCAL
55
+ /usr/local/texlive/texmf-local
56
+ * TEXMFHOME
57
+ ~/Library/texmf
58
+
59
+ になるらしい。
60
+
61
+ ```
62
+ $ kpsewhich -var-value TEXMF
63
+ ```
64
+ で検索の優先順位がわかるらしい。
65
+
66
+
67
+ ### pandoc 1.13.2
68
+
69
+ https://github.com/jgm/pandoc/releases
70
+
71
+ からダウンロードしてインストールしたり、 brew等でインストールしてください。
72
+
73
+ ```
74
+ $ brew install pandoc
75
+ ```
76
+
77
+ ## Usage
78
+
79
+ ## 初期化
80
+
81
+ ```
82
+ $ mkdir project
83
+ $ cd project
84
+ $ xpub init
85
+ ```
86
+
87
+ 上記コマンドを実行することで、Xpubファイル、サンプルデータ、デフォルトテーマや各種からディレクトリをスケルトンを元に作成します。
88
+
89
+ ## ビルド
90
+
91
+ ```
92
+ $ xpub build
93
+ ```
94
+
95
+ カレントディレクトリのXpub設定ファイルを元にビルドします。
96
+
97
+ ```
98
+ $ xpub book --book=sample
99
+ ```
100
+
101
+ Xpub設定ファイルのbook sampleのみビルドします。
102
+
103
+ ```
104
+ $ xpub book --builder=epub
105
+ ```
106
+
107
+ Xpub設定ファイルのbuilder epubのみビルドします。
108
+
109
+ ```
110
+ $ xpub book -v
111
+ ```
112
+
113
+ コマンドラインの実行結果を結果にかかわらず詳細に出力します。
114
+
115
+ ```
116
+ $ xpub book --pandoc-json-output
117
+ ```
118
+
119
+ pandocのjsonオブジェクトをtmpフォルダに生成します。デバック用です。
120
+
121
+
122
+ ## クリア
123
+
124
+ ```
125
+ $ xpub clean
126
+ ```
127
+
128
+ カレントディレクトリのtmpディレクトリ、outputディレクトリをクリアします。
129
+
130
+
131
+ # メモ
132
+
133
+ ## MacでのTeXのフォントの設定メモ
134
+
135
+ ### 游明朝体・游ゴシック体
136
+
137
+ ```
138
+ $ sudo mkdir -p /usr/local/texlive/texmf-local/fonts/opentype/yu-osx
139
+ $ cd /usr/local/texlive/texmf-local/fonts/opentype/yu-osx
140
+ $ sudo ln -fs "/Library/Fonts/Yu Gothic Bold.otf" YuGo-Bold.otf
141
+ $ sudo ln -fs "/Library/Fonts/Yu Gothic Medium.otf" YuGo-Medium.otf
142
+ $ sudo ln -fs "/Library/Fonts/Yu Mincho Demibold.otf" YuMin-Demibold.otf
143
+ $ sudo ln -fs "/Library/Fonts/Yu Mincho Medium.otf" YuMin-Medium.otf
144
+ $ sudo mktexlsr
145
+ $ sudo updmap-sys --setoption kanjiEmbed yu-osx
146
+ ```
147
+
148
+ ### ヒラギノフォント
149
+
150
+ ```
151
+ $ sudo mkdir -p /usr/local/texlive/texmf-local/fonts/opentype/hiragino/
152
+ $ cd /usr/local/texlive/texmf-local/fonts/opentype/hiragino/
153
+ $ sudo ln -fs "/Library/Fonts/ヒラギノ明朝 Pro W3.otf" ./HiraMinPro-W3.otf
154
+ $ sudo ln -fs "/Library/Fonts/ヒラギノ明朝 Pro W6.otf" ./HiraMinPro-W6.otf
155
+ $ sudo ln -fs "/Library/Fonts/ヒラギノ丸ゴ Pro W4.otf" ./HiraMaruPro-W4.otf
156
+ $ sudo ln -fs "/Library/Fonts/ヒラギノ角ゴ Pro W3.otf" ./HiraKakuPro-W3.otf
157
+ $ sudo ln -fs "/Library/Fonts/ヒラギノ角ゴ Pro W6.otf" ./HiraKakuPro-W6.otf
158
+ $ sudo ln -fs "/Library/Fonts/ヒラギノ角ゴ Std W8.otf" ./HiraKakuStd-W8.otf
159
+ $ sudo mktexlsr
160
+ $ sudo updmap-sys --setoption kanjiEmbed hiragino
161
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/xpub ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+
5
+ require 'rainbow/ext/string'
6
+ require "open3"
7
+ require 'optparse'
8
+ require 'fileutils'
9
+ require 'pathname'
10
+ require 'shellwords'
11
+ require 'erb'
12
+ require 'time'
13
+
14
+ require 'xpub/version.rb'
15
+
16
+ option={}
17
+ opt = OptionParser.new do |opt|
18
+ opt.version = Xpub::VERSION
19
+ opt.summary_indent = ' ' * 4
20
+ opt.banner = 'Usage: xpub [cmd] [options]'
21
+ opt.on_head('[cmd]',
22
+ ' init Xpubファイルの生成',
23
+ ' build ビルド',
24
+ ' clean テンポラリフォルダと出力フォルダをクリア')
25
+ opt.on('-v', '出力を詳細にする') { |v| option[:v] = v }
26
+ opt.on('--book=VALUE', 'ビルドするbookを指定する') { |v| option[:book] = v }
27
+ opt.on('--builder=VALUE', 'ビルドするbuilderを指定する') { |v| option[:builder] = v }
28
+ opt.on('--pandoc-json-output', 'ビルド時にpandocのjsonを出力') { |v| option['pandoc-json-output'] = v }
29
+ opt.permute!(ARGV)
30
+ end
31
+
32
+ curDir = Dir::getwd
33
+
34
+ unless File.file?("#{curDir}/Xpub") || ARGV[0] == "init"
35
+ puts "File does not exist. #{curDir}/Xpub".color :red
36
+ exit
37
+ end
38
+
39
+ $:.unshift "#{curDir}/lib"
40
+ $:.unshift File.dirname(__FILE__) + "/../lib"
41
+
42
+ require "xpub/dsl/book"
43
+ require "xpub/dsl/src_file"
44
+ require "xpub/dsl/builder"
45
+ require "xpub/dsl/page"
46
+
47
+ if File.file?("#{curDir}/Xpub") && ARGV[0] != "init"
48
+ load "#{curDir}/Xpub"
49
+ end
50
+
51
+ if ARGV.length != 1
52
+ puts opt.help
53
+ exit
54
+ elsif ARGV[0] == "build"
55
+ puts "build...".color :green
56
+ Xpub::BookManager.instance.build option
57
+ elsif ARGV[0] == "clean"
58
+ puts "clean...".color :green
59
+ FileUtils.remove_entry_secure("#{curDir}/tmp")
60
+ Dir::mkdir("#{curDir}/tmp")
61
+ FileUtils.remove_entry_secure("#{curDir}/output")
62
+ Dir::mkdir("#{curDir}/output")
63
+ elsif ARGV[0] == "init"
64
+ if File.file?("#{curDir}/Xpub")
65
+ puts "File exist. #{curDir}/Xpub".color :red
66
+ exit
67
+ end
68
+ puts "init...".color :green
69
+ FileUtils.cp_r(Dir.glob(File.dirname(__FILE__) + "/../skel/*"),"./")
70
+ else
71
+ puts opt.help
72
+ exit
73
+ end
74
+
data/lib/xpub.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "xpub/version"
2
+
3
+ module Xpub
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,261 @@
1
+ require 'singleton'
2
+
3
+ module Xpub
4
+ class CallBook
5
+ attr_reader :name, :src_files, :resource_files, :creators, :contributors, :identifiers
6
+
7
+ def initialize name
8
+ @name = name
9
+ @title = "UNTITLED"
10
+ @subtitle = nil
11
+ @short = nil
12
+ @collection = nil
13
+ @edition = nil
14
+ @extended = nil
15
+ @publisher = nil
16
+ @rights = nil
17
+ @publication = nil
18
+ @modification = nil
19
+ @lang = "ja"
20
+ @creators = []
21
+ @contributors = []
22
+ @identifiers = []
23
+ @description = nil
24
+
25
+ @src_files = []
26
+ @resource_files = []
27
+ @builders = []
28
+ end
29
+
30
+
31
+ def validate
32
+ end
33
+
34
+ def _set_or_get values
35
+ # 引数が 2 つ以上ならエラー
36
+ raise ArgumentError, "wrong number of arguments (#{ values.length} for 0..1)" if values.length > 1
37
+ values.empty?
38
+ end
39
+
40
+ def title *values
41
+ if _set_or_get values
42
+ @title
43
+ else
44
+ @title = values[0]
45
+ end
46
+ end
47
+
48
+ def subtitle *values
49
+ if _set_or_get values
50
+ @subtitle
51
+ else
52
+ @subtitle = values[0]
53
+ end
54
+ end
55
+
56
+ def short *values
57
+ if _set_or_get values
58
+ @short
59
+ else
60
+ @short = values[0]
61
+ end
62
+ end
63
+
64
+ def collection *values
65
+ if _set_or_get values
66
+ @collection
67
+ else
68
+ @collection = values[0]
69
+ end
70
+ end
71
+
72
+ def edition *values
73
+ if _set_or_get values
74
+ @edition
75
+ else
76
+ @edition = values[0]
77
+ end
78
+ end
79
+
80
+ def extended *values
81
+ if _set_or_get values
82
+ @extended
83
+ else
84
+ @extended = values[0]
85
+ end
86
+ end
87
+
88
+ def publisher *values
89
+ if _set_or_get values
90
+ @publisher
91
+ else
92
+ @publisher = values[0]
93
+ end
94
+ end
95
+
96
+ def rights *values
97
+ if _set_or_get values
98
+ @rights
99
+ else
100
+ @rights = values[0]
101
+ end
102
+ end
103
+
104
+ def publication *values
105
+ if _set_or_get values
106
+ @publication
107
+ else
108
+ @publication = values[0]
109
+ end
110
+ end
111
+
112
+ def modification *values
113
+ if _set_or_get values
114
+ @modification
115
+ else
116
+ @modification = values[0]
117
+ end
118
+ end
119
+
120
+ def lang *values
121
+ if _set_or_get values
122
+ @lang
123
+ else
124
+ @lang = values[0]
125
+ end
126
+ end
127
+
128
+ def description *values
129
+ if _set_or_get values
130
+ @description
131
+ else
132
+ @description = values[0]
133
+ end
134
+ end
135
+
136
+ def build option
137
+ puts "build #{@name} book.".color :green
138
+ @builders.each { |b|
139
+ if !option[:builder] || option[:builder] == b.name
140
+ b.build option
141
+ end
142
+ }
143
+ end
144
+
145
+ class CallAuthor
146
+ attr_reader :name
147
+
148
+ def initialize name
149
+ @name = name
150
+ @role = nil
151
+ end
152
+
153
+ def validate
154
+ end
155
+
156
+ def _set_or_get values
157
+ # 引数が 2 つ以上ならエラー
158
+ raise ArgumentError, "wrong number of arguments (#{ values.length} for 0..1)" if values.length > 1
159
+ values.empty?
160
+ end
161
+
162
+ def role *values
163
+ if _set_or_get values
164
+ @role
165
+ else
166
+ @role = values[0]
167
+ end
168
+ end
169
+ end
170
+
171
+ def creator name, &block
172
+ call = CallAuthor.new name
173
+ if block
174
+ call.instance_eval &block
175
+ end
176
+ call.validate
177
+ @creators << call
178
+ end
179
+
180
+ def contributor name, &block
181
+ call = CallAuthor.new name
182
+ if block
183
+ call.instance_eval &block
184
+ end
185
+ call.validate
186
+ @contributors << call
187
+ end
188
+
189
+ class CallIdentifier
190
+ attr_reader :identifier
191
+
192
+ def initialize identifier
193
+ @identifier = identifier
194
+ @scheme = nil
195
+ @type_value = nil
196
+ end
197
+
198
+ def validate
199
+ end
200
+
201
+ def _set_or_get values
202
+ # 引数が 2 つ以上ならエラー
203
+ raise ArgumentError, "wrong number of arguments (#{ values.length} for 0..1)" if values.length > 1
204
+ values.empty?
205
+ end
206
+
207
+ def scheme *values
208
+ if _set_or_get values
209
+ @scheme
210
+ else
211
+ @scheme = values[0]
212
+ end
213
+ end
214
+
215
+ def type_value *values
216
+ if _set_or_get values
217
+ @type_value
218
+ else
219
+ @type_value = values[0]
220
+ end
221
+ end
222
+ end
223
+
224
+ def identifier identifier, &block
225
+ call = CallIdentifier.new identifier
226
+ if block
227
+ call.instance_eval &block
228
+ end
229
+ call.validate
230
+ @identifiers << call
231
+ end
232
+ end
233
+
234
+ def self.book name, &block
235
+ call = CallBook.new name
236
+ if block
237
+ call.instance_eval &block
238
+ end
239
+ call.validate
240
+ BookManager.instance.add call
241
+ end
242
+
243
+ class BookManager
244
+ include Singleton
245
+ def initialize
246
+ @books = []
247
+ end
248
+
249
+ def add c
250
+ @books << c
251
+ end
252
+
253
+ def build option
254
+ @books.each { |book|
255
+ if !option[:book] || option[:book] == book.name
256
+ book.build option
257
+ end
258
+ }
259
+ end
260
+ end
261
+ end