xpub 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +23 -0
- data/README.md +2 -2
- data/bin/xpub +52 -55
- data/lib/xpub.rb +1 -1
- data/lib/xpub/dsl/book.rb +97 -113
- data/lib/xpub/dsl/builder.rb +307 -307
- data/lib/xpub/dsl/checker.rb +53 -58
- data/lib/xpub/dsl/page.rb +71 -82
- data/lib/xpub/dsl/src_file.rb +99 -119
- data/lib/xpub/dsl_accessor.rb +1 -1
- data/lib/xpub/version.rb +1 -1
- data/skel/theme/default/latex/template.tex +3 -1
- data/xpub.gemspec +12 -12
- metadata +8 -7
data/lib/xpub/dsl/checker.rb
CHANGED
@@ -1,70 +1,65 @@
|
|
1
|
+
# Xpub module
|
1
2
|
module Xpub
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
class CallBook
|
4
|
+
class CallChecker
|
5
|
+
def initialize(name, book)
|
6
|
+
@name = name
|
7
|
+
@book = book
|
8
|
+
end
|
9
|
+
|
10
|
+
def validate
|
11
|
+
end
|
9
12
|
|
10
|
-
|
11
|
-
|
13
|
+
def _check(_option, pattern)
|
14
|
+
words = {}
|
15
|
+
@book.src_files.each do |file|
|
16
|
+
f = open file.full_path
|
17
|
+
f.each_with_index do |line, index|
|
18
|
+
line.match(pattern) do |md|
|
19
|
+
if words[md[1]]
|
20
|
+
words[md[1]] << { file: file.file, line: (index + 1) }
|
21
|
+
else
|
22
|
+
words[md[1]] = [{ file: file.file, line: (index + 1) }]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
f.close
|
27
|
+
end
|
12
28
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
words[md[1]] << { :file => file.file, :line => (index + 1) }
|
21
|
-
else
|
22
|
-
words[md[1]] = [{ :file => file.file, :line => (index + 1) }]
|
23
|
-
end
|
29
|
+
words.sort.each do |word, infos|
|
30
|
+
next unless word
|
31
|
+
puts word.color :red
|
32
|
+
infos.each do |info|
|
33
|
+
puts " #{info[:file]}(#{info[:line]})"
|
34
|
+
end
|
35
|
+
end
|
24
36
|
end
|
25
|
-
end
|
26
|
-
f.close
|
27
37
|
end
|
28
38
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
puts " #{info[:file]}(#{info[:line]})"
|
34
|
-
}
|
35
|
-
end
|
39
|
+
class CallNumberChecker < CallChecker
|
40
|
+
def check(option)
|
41
|
+
_check option, /([0-9一二三四五六七八九十百千万億兆京〇零]+)/
|
42
|
+
end
|
36
43
|
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class CallNumberChecker < CallChecker
|
41
|
-
def check option
|
42
|
-
_check option, /([0-9一二三四五六七八九十百千万億兆京〇零]+)/
|
43
|
-
end
|
44
|
-
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
class CallKanaChecker < CallChecker
|
46
|
+
def check(option)
|
47
|
+
_check option, /([\p{Katakana}ー-]+)/
|
48
|
+
end
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@checkers << call
|
59
|
-
end
|
51
|
+
def number_checker(name, &block)
|
52
|
+
call = CallNumberChecker.new name, self
|
53
|
+
call.instance_eval(&block) if block
|
54
|
+
call.validate
|
55
|
+
@checkers << call
|
56
|
+
end
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
@checkers << call
|
58
|
+
def kana_checker(name, &block)
|
59
|
+
call = CallKanaChecker.new name, self
|
60
|
+
call.instance_eval(&block) if block
|
61
|
+
call.validate
|
62
|
+
@checkers << call
|
63
|
+
end
|
68
64
|
end
|
69
|
-
end
|
70
65
|
end
|
data/lib/xpub/dsl/page.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
+
# Xpub module
|
1
2
|
module Xpub
|
2
|
-
|
3
|
-
|
4
|
-
|
3
|
+
class CallBook
|
4
|
+
class CallLatexBuilder
|
5
|
+
class CallLatexOp
|
6
|
+
def initialize(name, book, builder)
|
7
|
+
@name = name
|
8
|
+
@book = book
|
9
|
+
@builder = builder
|
10
|
+
end
|
5
11
|
|
6
|
-
|
7
|
-
|
8
|
-
@book = book
|
9
|
-
@builder = builder
|
10
|
-
end
|
11
|
-
def validate
|
12
|
-
end
|
12
|
+
def validate
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def template_path
|
16
|
+
"#{Dir.getwd}/theme/#{@builder.theme}/#{@name}/#{@metadata}.erb"
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def latex(book, builder)
|
20
|
+
f = open template_path
|
21
|
+
erb = ERB.new f.read, nil, '-'
|
22
|
+
f.close
|
23
|
+
erb.result(binding)
|
24
|
+
end
|
25
|
+
end
|
24
26
|
|
25
|
-
|
27
|
+
class CallImgPageLatexOp < CallLatexOp
|
28
|
+
dsl_accessor :topoffset, default: '0in'
|
29
|
+
dsl_accessor :leftoffset, default: '0in'
|
30
|
+
dsl_accessor :file
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
dsl_accessor :leftoffset, :default => "0in"
|
30
|
-
dsl_accessor :file
|
31
|
-
|
32
|
-
def latex book, builder
|
33
|
-
<<"EOS"
|
32
|
+
def latex(_book, _builder)
|
33
|
+
<<"EOS"
|
34
34
|
\\enlargethispage{200truemm}%
|
35
35
|
\\thispagestyle{empty}%
|
36
36
|
\\vspace*{-1truein}
|
@@ -41,20 +41,20 @@ module Xpub
|
|
41
41
|
\\includegraphics[width=\\paperheight,height=\\paperwidth]{#{file}}
|
42
42
|
\\clearpage\n
|
43
43
|
EOS
|
44
|
-
|
45
|
-
|
44
|
+
end
|
45
|
+
end
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
class CallEmptyPageLatexOp < CallLatexOp
|
48
|
+
dsl_accessor :no_page_number, default: false
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def latex(_book, _builder)
|
51
|
+
(no_page_number ? '\\thispagestyle{empty}' : '') + " \\clearpage\n"
|
52
|
+
end
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
class CallInnerTitlePageLatexOp < CallLatexOp
|
56
|
+
def latex(book, _builder)
|
57
|
+
<<"EOS"
|
58
58
|
\\makeatletter
|
59
59
|
{
|
60
60
|
\\thispagestyle{empty}%
|
@@ -71,7 +71,7 @@ EOS
|
|
71
71
|
\\end{center}
|
72
72
|
\\vspace*{1.5cm}
|
73
73
|
\\begin{center}
|
74
|
-
{\\Large #{book.creators.map
|
74
|
+
{\\Large #{book.creators.map(&:name).join ' '}}
|
75
75
|
\\end{center}
|
76
76
|
\\vspace*{1.5cm}
|
77
77
|
\\begin{flushleft}
|
@@ -82,54 +82,43 @@ EOS
|
|
82
82
|
}%
|
83
83
|
\\makeatother
|
84
84
|
EOS
|
85
|
-
|
86
|
-
|
85
|
+
end
|
86
|
+
end
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
@hyoushi << call
|
95
|
-
end
|
88
|
+
def hyoushi_image_page(name, &block)
|
89
|
+
call = CallImgPageLatexOp.new name, @book, self
|
90
|
+
call.instance_eval(&block) if block
|
91
|
+
call.validate
|
92
|
+
@hyoushi << call
|
93
|
+
end
|
96
94
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
@hyoushi << call
|
104
|
-
end
|
95
|
+
def hyoushi_empty_page(name, &block)
|
96
|
+
call = CallEmptyPageLatexOp.new name, @book, self
|
97
|
+
call.instance_eval(&block) if block
|
98
|
+
call.validate
|
99
|
+
@hyoushi << call
|
100
|
+
end
|
105
101
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
@hyoushi << call
|
113
|
-
end
|
102
|
+
def hyoushi_inner_title_page(name, &block)
|
103
|
+
call = CallInnerTitlePageLatexOp.new name, @book, self
|
104
|
+
call.instance_eval(&block) if block
|
105
|
+
call.validate
|
106
|
+
@hyoushi << call
|
107
|
+
end
|
114
108
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
@urahyoushi << call
|
122
|
-
end
|
109
|
+
def urahyoushi_image_page(name, &block)
|
110
|
+
call = CallImgPageLatexOp.new name, @book, self
|
111
|
+
call.instance_eval(&block) if block
|
112
|
+
call.validate
|
113
|
+
@urahyoushi << call
|
114
|
+
end
|
123
115
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
116
|
+
def urahyoushi_empty_page(name, &block)
|
117
|
+
call = CallEmptyPageLatexOp.new name, @book, self
|
118
|
+
call.instance_eval(&block) if block
|
119
|
+
call.validate
|
120
|
+
@urahyoushi << call
|
121
|
+
end
|
128
122
|
end
|
129
|
-
call.validate
|
130
|
-
@urahyoushi << call
|
131
|
-
end
|
132
|
-
|
133
123
|
end
|
134
|
-
end
|
135
124
|
end
|
data/lib/xpub/dsl/src_file.rb
CHANGED
@@ -1,139 +1,119 @@
|
|
1
1
|
module Xpub
|
2
|
-
|
2
|
+
class CallBook
|
3
|
+
class CallSrcFile
|
4
|
+
attr_reader :file
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
+
def initialize(file)
|
7
|
+
@file = file
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
def full_path
|
11
|
+
"#{Dir.getwd}/src/#{@file}"
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
def validate
|
15
|
+
raise "File does not exist.#{full_path}" unless File.exist? full_path
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
def debug
|
19
|
+
p full_path
|
20
|
+
end
|
18
21
|
end
|
19
|
-
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
class CallMdFile < CallSrcFile
|
27
|
-
def initialize file
|
28
|
-
if !file.match "\.md$"
|
29
|
-
file = file + ".md"
|
23
|
+
class CallMdFile < CallSrcFile
|
24
|
+
def initialize(file)
|
25
|
+
file += '.md' unless file =~ /.md$/
|
26
|
+
super file
|
27
|
+
end
|
30
28
|
end
|
31
|
-
super file
|
32
|
-
end
|
33
|
-
end
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
30
|
+
class CallImgFile < CallSrcFile
|
31
|
+
def validate
|
32
|
+
super
|
33
|
+
raise "Image File Ext is not Image Ext. #{@file}" unless @file =~ /.(jpeg|jpg|png|bmp|pdf)$/
|
34
|
+
end
|
40
35
|
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
36
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
37
|
+
class CallImgFiles
|
38
|
+
attr_reader :dir
|
39
|
+
|
40
|
+
def initialize(dir)
|
41
|
+
@dir = dir
|
42
|
+
end
|
43
|
+
|
44
|
+
def full_path
|
45
|
+
"#{Dir.getwd}/src/#{@dir}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate
|
49
|
+
raise "Image Dir does not exist.#{full_path}" unless Dir.exist? full_path
|
50
|
+
end
|
51
|
+
|
52
|
+
def img_files
|
53
|
+
validate
|
54
|
+
Dir.glob("#{full_path}/**/*.{jpeg,jpg,png,bmp,pdf}").sort.map do |path|
|
55
|
+
img = CallImgFile.new path.sub(full_path + '/', '')
|
56
|
+
img.validate
|
57
|
+
img
|
58
|
+
end
|
59
|
+
end
|
59
60
|
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def img_files
|
63
|
-
validate
|
64
|
-
Dir.glob("#{full_path}/**/*.{jpeg,jpg,png,bmp,pdf}").sort.map { |path|
|
65
|
-
img = CallImgFile.new path.sub(full_path + "/", "")
|
66
|
-
img.validate
|
67
|
-
img
|
68
|
-
}
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
class CallMdFiles
|
73
|
-
attr_reader :dir
|
74
61
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
62
|
+
class CallMdFiles
|
63
|
+
attr_reader :dir
|
64
|
+
|
65
|
+
def initialize(dir)
|
66
|
+
@dir = dir
|
67
|
+
end
|
68
|
+
|
69
|
+
def full_path
|
70
|
+
"#{Dir.getwd}/src/#{@dir}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def validate
|
74
|
+
raise "Markdown Dir does not exist.#{full_path}" unless Dir.exist? full_path
|
75
|
+
end
|
76
|
+
|
77
|
+
def md_files
|
78
|
+
validate
|
79
|
+
Dir.glob("#{full_path}/**/*.md").sort.map do |path|
|
80
|
+
mf = CallMdFile.new path.sub("#{Dir.getwd}/src/", '')
|
81
|
+
mf.validate
|
82
|
+
mf
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def debug
|
87
|
+
p full_path
|
88
|
+
end
|
86
89
|
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def md_files
|
90
|
-
validate
|
91
|
-
Dir.glob("#{full_path}/**/*.md").sort.map { |path|
|
92
|
-
mf = CallMdFile.new path.sub("#{Dir::getwd}/src/", "")
|
93
|
-
mf.validate
|
94
|
-
mf
|
95
|
-
}
|
96
|
-
end
|
97
|
-
|
98
|
-
def debug
|
99
|
-
p full_path
|
100
|
-
end
|
101
|
-
end
|
102
90
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
@src_files << call
|
110
|
-
end
|
91
|
+
def md_file(file, &block)
|
92
|
+
call = CallMdFile.new file
|
93
|
+
call.instance_eval(&block) if block
|
94
|
+
call.validate
|
95
|
+
@src_files << call
|
96
|
+
end
|
111
97
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
@src_files.concat call.md_files
|
119
|
-
end
|
98
|
+
def md_files(dir, &block)
|
99
|
+
call = CallMdFiles.new dir
|
100
|
+
call.instance_eval(&block) if block
|
101
|
+
call.validate
|
102
|
+
@src_files.concat call.md_files
|
103
|
+
end
|
120
104
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
@resource_files << call
|
128
|
-
end
|
105
|
+
def img_file(file, &block)
|
106
|
+
call = CallImgFile.new file
|
107
|
+
call.instance_eval(&block) if block
|
108
|
+
call.validate
|
109
|
+
@resource_files << call
|
110
|
+
end
|
129
111
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
@resource_files.concat call.img_files
|
112
|
+
def img_files(dir, &block)
|
113
|
+
call = CallImgFiles.new dir
|
114
|
+
call.instance_eval(&block) if block
|
115
|
+
call.validate
|
116
|
+
@resource_files.concat call.img_files
|
117
|
+
end
|
137
118
|
end
|
138
|
-
end
|
139
119
|
end
|