hikiutils 0.2.3.12 → 0.2.3.13
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.
- checksums.yaml +4 -4
- data/hikiutils_bob/Rakefile +3 -2
- data/hikiutils_yamane/Rakefile +148 -30
- data/hikiutils_yamane/Rakefile~ +477 -0
- data/hikiutils_yamane/command.hiki +13 -13
- data/hikiutils_yamane/compare.hiki +96 -5
- data/hikiutils_yamane/figs/hikiutils_yamane.001.jpg +0 -0
- data/hikiutils_yamane/figs/hikiutils_yamane.002.jpg +0 -0
- data/hikiutils_yamane/figs/hikiutils_yamane.003.jpg +0 -0
- data/hikiutils_yamane/figs/hikiutils_yamane.004.jpg +0 -0
- data/hikiutils_yamane/figs/hikiutils_yamane.005.jpg +0 -0
- data/hikiutils_yamane/figs/hikiutils_yamane.006.jpg +0 -0
- data/hikiutils_yamane/figs/hikiutils_yamane.007.jpg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.001.jpeg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.002.jpeg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.003.jpeg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.004.jpeg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.005.jpeg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.006.jpeg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.007.jpeg +0 -0
- data/hikiutils_yamane/hikiutils_yamane.hiki +6 -10
- data/hikiutils_yamane/introduction.hiki +5 -5
- data/hikiutils_yamane/latex_dir/%CA%FD/313/241.aux +21 -0
- data/hikiutils_yamane/latex_dir/abstract.aux +2 -2
- data/hikiutils_yamane/latex_dir/command.aux +15 -14
- data/hikiutils_yamane/latex_dir/command.log +0 -0
- data/hikiutils_yamane/latex_dir/command.tex +15 -14
- data/hikiutils_yamane/latex_dir/compare.aux +11 -5
- data/hikiutils_yamane/latex_dir/compare.tex +97 -5
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.aux +6 -3
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.log +113 -162
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.pdf +0 -0
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.synctex.gz +0 -0
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.tex +15 -18
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.toc +31 -26
- data/hikiutils_yamane/latex_dir/introduction.aux +6 -4
- data/hikiutils_yamane/latex_dir/introduction.tex +5 -4
- data/hikiutils_yamane/latex_dir/jlisting.sty +216 -0
- data/hikiutils_yamane/latex_dir/optparse.aux +11 -9
- data/hikiutils_yamane/latex_dir/optparse.tex +11 -8
- data/hikiutils_yamane/latex_dir/pre.tex +36 -0
- data/hikiutils_yamane/latex_dir/thor.aux +13 -13
- data/hikiutils_yamane/latex_dir/thor.tex +9 -11
- data/hikiutils_yamane/optparse.hiki +7 -6
- data/hikiutils_yamane/test.rb +10 -0
- data/hikiutils_yamane/thor.hiki +4 -5
- data/lib/hikiutils/version.rb +1 -1
- data/lib/hikiutils_thor.rb +39 -39
- data/lib/hikiutils_thor.rb~ +3 -4
- data/lib/templates/Rakefile_hiki_sync +3 -2
- metadata +15 -9
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.001.jpg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.002.jpg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.003.jpg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.004.jpg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.005.jpg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.006.jpg +0 -0
- data/hikiutils_yamane/hikiutils_yamane/hikiutils_yamane.007.jpg +0 -0
@@ -0,0 +1,477 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'systemu'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'colorize'
|
5
|
+
# -*- coding: utf-8 -*-
|
6
|
+
begin
|
7
|
+
$hiki_dir = File.readlines('./.hikirc')[0].chomp
|
8
|
+
rescue => e
|
9
|
+
puts e
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
dirnames=Dir.pwd.split('/')
|
13
|
+
$basename = (dirnames[-1]=='hikis')? dirnames[-2] : dirnames[-1]
|
14
|
+
$latex_dir= 'latex_dir'
|
15
|
+
$section_layer = {}
|
16
|
+
|
17
|
+
task :default do
|
18
|
+
system 'rake -T'
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Githubのdirをsafariでopen"
|
22
|
+
task :github do
|
23
|
+
status, stdout, stderr = systemu %q( git remote -v |grep origin )
|
24
|
+
github_dir=stdout.match(/(.+):(.+) \(push\)/)[2]
|
25
|
+
puts github_dir.blue
|
26
|
+
system "open https://github.com/#{github_dir}"
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "hikiシステムにあるゴミファイルを掃除する"
|
30
|
+
task :reset_hiki do
|
31
|
+
status, stdout, stderr = systemu "hiki -l #{$basename}"
|
32
|
+
print stdout
|
33
|
+
files=[]
|
34
|
+
stdout.split("\n").each{|line|
|
35
|
+
files << line.split(/\s+/)[-1]
|
36
|
+
}
|
37
|
+
r_files = files.reverse[0..-4]
|
38
|
+
r_files.each{|file|
|
39
|
+
print "remove #{file}[ynqlA]? ".red
|
40
|
+
input=STDIN.gets.chomp
|
41
|
+
case input
|
42
|
+
when 'y'
|
43
|
+
p command="hiki --remove #{file}"
|
44
|
+
system command
|
45
|
+
when 'n'
|
46
|
+
when 'l'
|
47
|
+
p command="hiki -l #{$basename}"
|
48
|
+
system command
|
49
|
+
when 'q'
|
50
|
+
exit
|
51
|
+
when 'A'
|
52
|
+
print "\nAre you sure[Yn]? ".magenta
|
53
|
+
input2 = STDIN.gets.chomp
|
54
|
+
case input2
|
55
|
+
when 'Y'
|
56
|
+
r_files.each{|file| system "hiki --remove #{file}"}
|
57
|
+
p target = File.join($hiki_dir,'cache','attach',$basename)
|
58
|
+
exit
|
59
|
+
when 'n'
|
60
|
+
exit
|
61
|
+
end
|
62
|
+
end
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "latex_dirのゴミを掃除"
|
67
|
+
task :reset_latex_dir do
|
68
|
+
system "mv latex_dir/head.tex ."
|
69
|
+
system "rm -rf latex_dir"
|
70
|
+
system "mkdir latex_dir"
|
71
|
+
system "mv head.tex latex_dir/"
|
72
|
+
system "rake latex_all"
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "toc.hikiの作成"
|
76
|
+
task :mk_toc do
|
77
|
+
p target = $basename+'.toc'
|
78
|
+
cont=""
|
79
|
+
File.readlines(File.join('latex_dir',target)).each{|line|
|
80
|
+
if m=line.match(/\\contentsline \{(.+)\}\{\\numberline \{([\d|\.]+)\}(.+)\}\{\d+\}/)
|
81
|
+
layer,sec_no,title=m[1],m[2],m[3]
|
82
|
+
d = case m[1]
|
83
|
+
when 'section'; 1
|
84
|
+
when 'subsection'; 2
|
85
|
+
when 'subsubsection'; 3
|
86
|
+
else; 4
|
87
|
+
end
|
88
|
+
layer = "!"*d
|
89
|
+
title.gsub!('\_','_')
|
90
|
+
cont << "#{layer}#{sec_no}:#{title}\n"
|
91
|
+
end
|
92
|
+
}
|
93
|
+
print cont
|
94
|
+
File.open("toc.hiki",'w'){|file| file.print cont}
|
95
|
+
end
|
96
|
+
|
97
|
+
desc "FILE.hikiあるいはhikiファイルすべてを最新状態に更新"
|
98
|
+
task :touch do
|
99
|
+
if file=ARGV[1]
|
100
|
+
file_split=file.split(".")
|
101
|
+
p target = $basename==file_split[0] ? $basename : $basename+"_"+file_split[0]
|
102
|
+
system "hiki -u #{target}"
|
103
|
+
else
|
104
|
+
p target = File.join($hiki_dir,'cache','attach',$basename)
|
105
|
+
system "touch #{target}/*"
|
106
|
+
Dir.entries('.').each{|file|
|
107
|
+
file_split=file.split(".")
|
108
|
+
if file_split[1]=='hiki'
|
109
|
+
p target = $basename==file_split[0] ? $basename : $basename+"_"+file_split[0]
|
110
|
+
system "hiki -u #{target}"
|
111
|
+
end
|
112
|
+
}
|
113
|
+
end
|
114
|
+
exit
|
115
|
+
end
|
116
|
+
|
117
|
+
desc "FILE.hikiあるいはhikiファイルをedtiorで開く"
|
118
|
+
task :open do
|
119
|
+
if file=ARGV[1]
|
120
|
+
system "open -a mi #{file}"
|
121
|
+
else
|
122
|
+
Dir.entries('.').each{|file|
|
123
|
+
file_split=file.split(".")
|
124
|
+
if file_split[1]=='hiki'
|
125
|
+
p target = file_split[0]
|
126
|
+
system "open -a mi #{target}"
|
127
|
+
end
|
128
|
+
}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
desc "FILE1をlatexに変換"
|
133
|
+
task :latex => [:latex_base] do
|
134
|
+
exit
|
135
|
+
end
|
136
|
+
|
137
|
+
desc "FILE1をwrap formatでlatexに変換"
|
138
|
+
task :latex_wrap => [:latex_base, :change_wrap] do
|
139
|
+
exit
|
140
|
+
end
|
141
|
+
|
142
|
+
def latex_loop(entries,opts={})
|
143
|
+
check_bounding_box
|
144
|
+
main_file=""
|
145
|
+
entries.each{|file|
|
146
|
+
options={:latex_all=>true}
|
147
|
+
next unless file.split('.')[1]=='hiki'
|
148
|
+
next if file=='toc.hiki'
|
149
|
+
next if file.include?('.hikirc')
|
150
|
+
f_name =File.basename(file,'.hiki')
|
151
|
+
if opts[:main]
|
152
|
+
if f_name==$basename
|
153
|
+
options[:latex]="--listings --head latex_dir/head.tex -p "
|
154
|
+
options[:main]=true
|
155
|
+
main_file=f_name
|
156
|
+
convert_to_latex(file, options)
|
157
|
+
end
|
158
|
+
else
|
159
|
+
if f_name!=$basename
|
160
|
+
p level = $section_layer[f_name] || 1
|
161
|
+
options[:latex]="-l #{level} --listings -b "
|
162
|
+
convert_to_latex(file, options)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
}
|
166
|
+
return main_file
|
167
|
+
end
|
168
|
+
|
169
|
+
def check_section_layers(lines)
|
170
|
+
p reg_exp = Regexp.new("#{$basename}_(.+)")
|
171
|
+
lines.each{|line|
|
172
|
+
p line
|
173
|
+
if m=line.match(/(!+)\[\[(.+)\]\]/)
|
174
|
+
p count = m[1].count('!')
|
175
|
+
p file_name=m[2].match(reg_exp)[1]
|
176
|
+
$section_layer[file_name]=count
|
177
|
+
end
|
178
|
+
}
|
179
|
+
p $section_layer
|
180
|
+
end
|
181
|
+
|
182
|
+
def check_bounding_box
|
183
|
+
# $bounding_box="0 0 442 432"
|
184
|
+
$bounding_box=" 0 0 737 553"
|
185
|
+
end
|
186
|
+
|
187
|
+
desc "すべてのhikiファイルをlatex変換"
|
188
|
+
task :latex_all do
|
189
|
+
p entries=Dir.entries('.')
|
190
|
+
main_file = latex_loop(entries,opts={:main=>true})
|
191
|
+
latex_loop(entries)
|
192
|
+
cont=""
|
193
|
+
p reg_exp = Regexp.new("#{$basename}_(.+)")
|
194
|
+
toc = false
|
195
|
+
File.readlines(File.join($latex_dir,"#{main_file}.tex")).each{|line|
|
196
|
+
# line, toc = "", true if line.match(/\\tableofcontents/) and toc == true #only one
|
197
|
+
if line.match(/\\tableofcontents/)
|
198
|
+
if toc == false #only one
|
199
|
+
toc = true
|
200
|
+
else
|
201
|
+
line = ''
|
202
|
+
end
|
203
|
+
end
|
204
|
+
line ="\\usepackage{listings,jlisting}" if line.match(/\\usepackage{listings}/)
|
205
|
+
if line.match(/section{(.+)}/)
|
206
|
+
if m=line.match(/\\verb\|(.+)\((.+)\)\|/)
|
207
|
+
p m
|
208
|
+
p m_t=m[2].match(reg_exp)[1]
|
209
|
+
line = "\\include{#{m_t}}\n"
|
210
|
+
elsif m=line.match(/section{\\verb\|(.+)\|}/)
|
211
|
+
p m
|
212
|
+
p m_t=m[1].match(reg_exp)[1]
|
213
|
+
line = "\\include{#{m_t}}\n"
|
214
|
+
else
|
215
|
+
# line = ""
|
216
|
+
end
|
217
|
+
end
|
218
|
+
cont << line
|
219
|
+
}
|
220
|
+
File.open(File.join($latex_dir,"#{main_file}.tex"),'w'){|file| file.print cont}
|
221
|
+
system "open latex_dir/#{main_file}.tex"
|
222
|
+
exit
|
223
|
+
end
|
224
|
+
|
225
|
+
task :latex_base do
|
226
|
+
check_bounding_box
|
227
|
+
Dir.mkdir($latex_dir) unless Dir.exist?($latex_dir)
|
228
|
+
convert_to_latex(ARGV[1])
|
229
|
+
system("open #{$save_name}")
|
230
|
+
end
|
231
|
+
|
232
|
+
def convert_to_latex(file_name, options={})
|
233
|
+
p file_name = file_name.include?('.hiki')? file_name : file_name+'.hiki'
|
234
|
+
p tex_name = File.basename(file_name,'.hiki')+'.tex'
|
235
|
+
p $save_name = ARGV[2] || File.join($latex_dir,tex_name)
|
236
|
+
pre_name = File.join($latex_dir,'pre.tex')
|
237
|
+
p pre_command = File.exist?(pre_name) ? '--pre '+pre_name : nil
|
238
|
+
lines = File.readlines(file_name)
|
239
|
+
check_section_layers(lines) if options[:main]
|
240
|
+
cont = ""
|
241
|
+
lines.each_with_index{|line,i|
|
242
|
+
if m=line.match(/\{\{attach_view\((.*),(.*)\)\}\}/)
|
243
|
+
p line="\{\{attach_view\(#{m[1]}\)\}\}\n"
|
244
|
+
elsif options[:latex_all] and i<5
|
245
|
+
line="" if line.match(/^!title:|^!author:|^!date:/)
|
246
|
+
end
|
247
|
+
cont << line
|
248
|
+
}
|
249
|
+
tf1,tf2='tmp1.txt','tmp2.txt'
|
250
|
+
File.open(tf1,'w'){|file| file.print cont}
|
251
|
+
system "hiki2latex #{pre_command} #{options[:latex]} #{tf1} > #{tf2}"
|
252
|
+
lines = File.readlines(tf2)
|
253
|
+
system "rm #{tf1} #{tf2}"
|
254
|
+
in_bib,cont=false,""
|
255
|
+
lines.each{|line|
|
256
|
+
line=latex_cite_ref(line)
|
257
|
+
if m=line.match(/\\caption{\s*\((.+?)\)(.+)}/)
|
258
|
+
p m
|
259
|
+
puts line = "\\caption{#{m[2]}}\n\\label{#{m[1]}}\n"
|
260
|
+
end
|
261
|
+
if m=line.match(/\\section{reference:}(.+)/) and in_bib==false
|
262
|
+
in_bib=true
|
263
|
+
line = "\\begin{thebibliography}{99}\n"
|
264
|
+
puts line.blue
|
265
|
+
end
|
266
|
+
if m=line.match(/\\end{description}/) and in_bib==true
|
267
|
+
in_bib=false
|
268
|
+
line = "\\end{thebibliography}\n"
|
269
|
+
end
|
270
|
+
if m=line.match(/\\item\[(.+)\](.+)/) and in_bib==true
|
271
|
+
line ="\\bibitem{#{m[1]}} #{m[2]}"
|
272
|
+
end
|
273
|
+
if m=line.match(/\\includegraphics\[width=6cm\]\{(.+)\}/)
|
274
|
+
p line="\\includegraphics\[width=10cm,bb=#{$bounding_box}\]\{../figs/#{m[1]}\}\n"
|
275
|
+
cont << line
|
276
|
+
else
|
277
|
+
cont << line
|
278
|
+
end
|
279
|
+
}
|
280
|
+
File.open($save_name,'w'){|file| file.print cont }
|
281
|
+
end
|
282
|
+
|
283
|
+
def latex_cite_ref(line)
|
284
|
+
r_pair=[/\\verb\|{{cite\((.+?)\)}}\|/,/\\verb\|{{ref\((.+?)\)}}\|/]
|
285
|
+
while m=line.match(r_pair[0])
|
286
|
+
line.sub!(r_pair[0],"\\cite\{#{m[1]}\}")
|
287
|
+
end
|
288
|
+
while m=line.match(r_pair[1])
|
289
|
+
line.sub!(r_pair[1],"\\ref\{#{m[1]}\}")
|
290
|
+
end
|
291
|
+
# puts line.chomp.blue
|
292
|
+
return line
|
293
|
+
end
|
294
|
+
|
295
|
+
task :change_wrap do
|
296
|
+
lines = File.readlines($save_name)
|
297
|
+
|
298
|
+
cont = ""
|
299
|
+
lines.each{|line|
|
300
|
+
if line.include?('\begin{figure}[htbp]\begin{center}')
|
301
|
+
p line
|
302
|
+
cont << '\begin{wrapfigure}{r}{8cm}'+"\n"
|
303
|
+
cont << '\vspace{-2\baselineskip}'+"\n"
|
304
|
+
cont << '\begin{center}'+"\n"
|
305
|
+
elsif line.include?('\label{default}\end{center}\end{figure}')
|
306
|
+
p line
|
307
|
+
cont << '\end{center}'+"\n"
|
308
|
+
cont << '\vspace{2\baselineskip}'+"\n"
|
309
|
+
cont << '\end{wrapfigure}'+"\n"
|
310
|
+
else
|
311
|
+
cont << line
|
312
|
+
end
|
313
|
+
}
|
314
|
+
File.open($save_name,'w'){|file| file.print cont }
|
315
|
+
|
316
|
+
system("open #{$save_name}")
|
317
|
+
exit
|
318
|
+
end
|
319
|
+
|
320
|
+
|
321
|
+
desc "increment fig NUBERS in FILE"
|
322
|
+
task :increment do
|
323
|
+
number=ARGV[1]
|
324
|
+
file = ARGV[2]
|
325
|
+
dir = ARGV[3] || nil
|
326
|
+
lines = File.readlines(file)
|
327
|
+
cont = ""
|
328
|
+
lines.each{|line|
|
329
|
+
if m=line.match(/\{\{attach_view\((\w+|_).(\d+).jpeg\)\}\}/)
|
330
|
+
new_num=sprintf("%03d",m[2].to_i+number.to_i)
|
331
|
+
line="\{\{attach_view\(#{m[1]}.#{new_num}.jpeg,#{dir}\)\}\}\n"
|
332
|
+
cont << line
|
333
|
+
else
|
334
|
+
cont << line
|
335
|
+
end
|
336
|
+
}
|
337
|
+
print cont
|
338
|
+
exit
|
339
|
+
end
|
340
|
+
|
341
|
+
desc "numbering figs from the NUBER in FILE"
|
342
|
+
task :number do
|
343
|
+
number=ARGV[1].to_i
|
344
|
+
file = ARGV[2]
|
345
|
+
dir = ARGV[3] || nil
|
346
|
+
lines = File.readlines(file)
|
347
|
+
cont = ""
|
348
|
+
lines.each{|line|
|
349
|
+
if m=line.match(/\{\{attach_view\((\w+|_).(\d+).jpeg,(\w+)\)\}\}/)
|
350
|
+
new_num=sprintf("%03d",number)
|
351
|
+
line="\{\{attach_view\(#{m[1]}.#{new_num}.jpeg,#{m[3]}\)\}\}\n"
|
352
|
+
cont << line
|
353
|
+
number += 1
|
354
|
+
else
|
355
|
+
cont << line
|
356
|
+
end
|
357
|
+
}
|
358
|
+
print cont
|
359
|
+
exit
|
360
|
+
end
|
361
|
+
|
362
|
+
desc "convert fig size SCALE TARGET_DIR"
|
363
|
+
task :convert do
|
364
|
+
scale = ARGV[1]
|
365
|
+
target_dir=ARGV[2]
|
366
|
+
Dir.entries(target_dir)[2..-1].each{|file|
|
367
|
+
p file
|
368
|
+
source = File.join(target_dir,file)
|
369
|
+
target = File.join('figs',file)
|
370
|
+
p command = "convert #{source} -resize #{scale}\% #{target}"
|
371
|
+
system command
|
372
|
+
}
|
373
|
+
exit
|
374
|
+
end
|
375
|
+
|
376
|
+
desc "hikiの同期"
|
377
|
+
task :sync => [:check_previous,:sync0]
|
378
|
+
|
379
|
+
|
380
|
+
desc "hikiの強制同期"
|
381
|
+
task :force_sync => [:sync0]
|
382
|
+
|
383
|
+
def hiki_cite_ref(file)
|
384
|
+
tf1 = 'tmp1.txt'
|
385
|
+
lines = File.readlines(file)
|
386
|
+
inside_pre_form,cont = false,""
|
387
|
+
lines.each{|line|
|
388
|
+
inside_pre_form=true if line.match(/^<<</) and !inside_pre_form
|
389
|
+
inside_pre_form=false if line.match(/^>>>/) and inside_pre_form
|
390
|
+
tr_pair=[/\{\{cite\((.+?)\)\}\}/,/\{\{ref\((.+)\)\}\}/]
|
391
|
+
while m=line.match(tr_pair[0]) and !inside_pre_form
|
392
|
+
puts line.sub!(tr_pair[0], "\[[[#{m[1]}|#{$basename}_references]]\]").chomp.green
|
393
|
+
end
|
394
|
+
while m=line.match(tr_pair[1]) and !inside_pre_form
|
395
|
+
puts line.sub!(tr_pair[1],"#{m[1]}").chomp.green
|
396
|
+
end
|
397
|
+
cont << line
|
398
|
+
}
|
399
|
+
File.open(tf1,'w'){|file| file.print cont }
|
400
|
+
return tf1
|
401
|
+
end
|
402
|
+
|
403
|
+
task :sync0 do
|
404
|
+
entries=Dir.entries('.')
|
405
|
+
entries[2..-1].each{|source| #cp *.hiki
|
406
|
+
next unless source.split('.')[1]=='hiki'
|
407
|
+
next if source.include?('.hikirc')
|
408
|
+
p base = source.split('.')[0]
|
409
|
+
name = (base==$basename)? base : $basename+'_'+base
|
410
|
+
p target = File.join($hiki_dir,'text',name)
|
411
|
+
source = hiki_cite_ref(source)
|
412
|
+
FileUtils.cp(source,target,:verbose=>true)
|
413
|
+
}
|
414
|
+
p entries=Dir.entries('./figs') #cp files in figs
|
415
|
+
p target = File.join($hiki_dir,'cache','attach',$basename)
|
416
|
+
FileUtils.mkdir_p(target,:verbose=>true) unless File.exists?(target)
|
417
|
+
entries[2..-1].each{|file|
|
418
|
+
p source = File.join('./figs',file)
|
419
|
+
FileUtils.cp(source,target,:verbose=>true)
|
420
|
+
}
|
421
|
+
|
422
|
+
File.open('./.hikirc','w'){|file|
|
423
|
+
status, stdout, stderr =systemu "hiki -l #{$basename}*"
|
424
|
+
file.print($hiki_dir+"\n")
|
425
|
+
stdout.split("\n")[3..-1].each{|line|
|
426
|
+
file.print line+"\n"
|
427
|
+
}
|
428
|
+
}
|
429
|
+
exit
|
430
|
+
end
|
431
|
+
|
432
|
+
desc "For hiki Errno::ENOENT, Errno::EACCES"
|
433
|
+
task :chenv do
|
434
|
+
p user = ENV['USER']
|
435
|
+
system("sudo chmod -R a+w #{$hiki_dir}")
|
436
|
+
# system("sudo chown -R #{user} #{$hiki_dir}")
|
437
|
+
end
|
438
|
+
|
439
|
+
desc "self copy to hikiutils template directory"
|
440
|
+
task :self_copy do
|
441
|
+
p cp_files=[[File.join(Dir.pwd,'Rakefile'),'Rakefile_hiki_sync'],
|
442
|
+
[File.join(ENV['HOME'],'.my_help','hiki_help.yml'),'hiki_help.yml']]
|
443
|
+
cp_files.each{|files|
|
444
|
+
p source = files[0]
|
445
|
+
p target = File.join('/Users/bob/Github/hikiutils/lib/templates/',files[1])
|
446
|
+
FileUtils.cp(source,target,:verbose=>true)
|
447
|
+
}
|
448
|
+
end
|
449
|
+
|
450
|
+
task :check_previous do
|
451
|
+
current={}
|
452
|
+
print "current hiki dir\n"
|
453
|
+
status, stdout, stderr = systemu("hiki -l #{$basename}*")
|
454
|
+
stdout.split("\n")[3..-1].each{|line|
|
455
|
+
p line
|
456
|
+
file= line.split(/\s+/)[-1]
|
457
|
+
current[file]=line
|
458
|
+
}
|
459
|
+
previous={}
|
460
|
+
print "previous sync\n"
|
461
|
+
File.readlines('.hikirc')[1..-1].each{|line|
|
462
|
+
p line.chomp
|
463
|
+
file= line.split(/\s+/)[-1]
|
464
|
+
previous[file]=line.chomp
|
465
|
+
}
|
466
|
+
changed = []
|
467
|
+
current.each_pair{|key,val|
|
468
|
+
if !previous.include?(key) or previous[key]!=val
|
469
|
+
changed << val+"\n"
|
470
|
+
end
|
471
|
+
}
|
472
|
+
if changed.size != 0
|
473
|
+
print("hiki dirで変更が発生しています.\n")
|
474
|
+
changed.each{|line| print line+"\n"}
|
475
|
+
exit
|
476
|
+
end
|
477
|
+
end
|
@@ -14,8 +14,8 @@ hikiutilsの振る舞いを予測できるシェルコマンドと同じ名前
|
|
14
14
|
!!hikiutilsの想定利用形態
|
15
15
|
ここでhikiutilsがあらかじめ想定している利用形態を解説しておきます.
|
16
16
|
|
17
|
-
!!!caption:hikiutilsがあらかじめ想定している利用形態.
|
18
|
-
{{attach_view(
|
17
|
+
!!!caption:(fig:002)hikiutilsがあらかじめ想定している利用形態.
|
18
|
+
{{attach_view(hikiutils_yamane.002.jpg,hikiutils_yamane)}}
|
19
19
|
|
20
20
|
hikiutilsは,
|
21
21
|
*local PCとglobal serverとが用意されており,
|
@@ -47,12 +47,12 @@ hikiutils: provide utilities for helping hiki editing.
|
|
47
47
|
"open -a mi"
|
48
48
|
target_no:1
|
49
49
|
editor_command:open -a mi
|
50
|
-
id | name | local directory
|
51
|
-
|
52
|
-
0 | new_ist | /Users/bob/Sites/new_ist_data/ist_data
|
53
|
-
*1 | dmz0 | /Users/bob/Sites/nishitani0/Internal/data
|
54
|
-
2 | ist | /Users/bob/Sites/hiki-data/data
|
55
|
-
3 | new_maple | /Users/bob/Sites/new_ist_data/
|
50
|
+
id | name | local directory | global uri
|
51
|
+
-----------------------------------------------------------------------------
|
52
|
+
0 | new_ist | /Users/bob/Sites/new_ist_data/ist_data | http://ist.ksc.k
|
53
|
+
*1 | dmz0 | /Users/bob/Sites/nishitani0/Internal/data | http://nishitani
|
54
|
+
2 | ist | /Users/bob/Sites/hiki-data/data | http://ist.ksc.k
|
55
|
+
3 | new_maple | /Users/bob/Sites/new_ist_data/maple_hiki_d| http://ist.ksc.k
|
56
56
|
>>>
|
57
57
|
とすると,それらの一覧と,いまtargetにしているnick_nameディレクリが表示されます.
|
58
58
|
|
@@ -67,17 +67,17 @@ editor_command:open -a mi
|
|
67
67
|
||rsync ||rsync|| rsync files
|
68
68
|
||update FILE ||touch|| update file
|
69
69
|
||show ||pwd|| show nick_names
|
70
|
-
||target VAL ||cd|| targetを変える,
|
70
|
+
||target VAL ||cd|| targetを変える,cdとのメタファ
|
71
71
|
|| || ||
|
72
72
|
||move [FILE] ||mv|| move file
|
73
73
|
||remove [FILE] ||rm|| remove files
|
74
74
|
||add || || add sources info
|
75
75
|
||checkdb || || check database file
|
76
|
-
||datebase FILE ||
|
77
|
-
||display FILE
|
76
|
+
||datebase FILE ||db|| read datebase file
|
77
|
+
||display FILE ||show|| display converted hikifile
|
78
78
|
||euc FILE || || translate file to euc
|
79
|
-
||help [COMMAND] ||
|
80
|
-
||version ||
|
79
|
+
||help [COMMAND] ||-h|| Describe available commands
|
80
|
+
||version ||-v|| show program version
|
81
81
|
|
82
82
|
それぞれの意図を動作の解説として記述しています.
|
83
83
|
|
@@ -1,9 +1,11 @@
|
|
1
1
|
{{toc}}
|
2
2
|
!optparseとthorの比較
|
3
|
-
|
3
|
+
今回の既存システムであるhikiutilsはoptparseというコマンドライン解析ライブラリが用いられている.
|
4
|
+
本研究ではこの代替ライブラリとしてThorの採用を検討した.
|
5
|
+
本章の最初では,FizzBuzzという簡単なコードを例にoptparseとThorにより作成するコマンドライン解析コードの比較を行う.
|
4
6
|
|
5
7
|
!!optparse
|
6
|
-
optparseとは,getoptよりも簡便で,柔軟性に富み,かつ強力なコマンドライン解析ライブラリである.optparseでは,より宣言的なスタイルのコマンドライン解析手法,すなわちOptionParserのインスタンスでコマンドラインを解析するという手法をとっている.これを使うと,GNU/POSIX構文でオプションを指定できるだけでなく,使用法やヘルプメッセージの生成も行える[
|
8
|
+
optparseとは,getoptよりも簡便で,柔軟性に富み,かつ強力なコマンドライン解析ライブラリである.optparseでは,より宣言的なスタイルのコマンドライン解析手法,すなわちOptionParserのインスタンスでコマンドラインを解析するという手法をとっている.これを使うと,GNU/POSIX構文でオプションを指定できるだけでなく,使用法やヘルプメッセージの生成も行える[2].利用頻度はあまり高くないが古くから開発され,使用例が広く紹介されている.
|
7
9
|
|
8
10
|
optparseの基本的な流れとしては
|
9
11
|
#OptionParserオブジェクトoptを生成する
|
@@ -11,15 +13,104 @@ optparseの基本的な流れとしては
|
|
11
13
|
#opt.parse(ARGV)でコマンドラインを実際にparseする
|
12
14
|
である.
|
13
15
|
|
14
|
-
OptionParserはコマンドラインのオプション取り扱うためのクラスであるためオブジェクトoptを生成されopt.onにコマンドを登録することができる.しかし,OptionParser\#onにはコマンドが登録されているだけであるため,OptionParser\#parseが呼ばれた時,コマンドラインにオプションが指定されていれば実行される.optparseにはデフォルトとして--helpと--versionオプションを認識する[
|
16
|
+
OptionParserはコマンドラインのオプション取り扱うためのクラスであるためオブジェクトoptを生成されopt.onにコマンドを登録することができる.しかし,OptionParser\#onにはコマンドが登録されているだけであるため,OptionParser\#parseが呼ばれた時,コマンドラインにオプションが指定されていれば実行される.optparseにはデフォルトとして--helpと--versionオプションを認識する[3].
|
17
|
+
|
18
|
+
以下に示したコードがoptparseで記述されたfizzbuzzである.
|
19
|
+
|
20
|
+
<<< ruby
|
21
|
+
module Fizzbuzz
|
22
|
+
class Command
|
23
|
+
|
24
|
+
def self.run(argv)
|
25
|
+
new(argv).execute
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(argv)
|
29
|
+
@argv = argv
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute
|
33
|
+
options = Options.parse!(@argv)
|
34
|
+
sub_command = options.delete(:command)
|
35
|
+
case sub_command
|
36
|
+
when 'fizzbuzz'
|
37
|
+
fizzbuzz(options[:id])
|
38
|
+
when 'version'
|
39
|
+
version
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def fizzbuzz(limit_number)
|
44
|
+
(0..limit_number).map do |num|
|
45
|
+
if (num % 15).zero? then print 'FizzBuzz'
|
46
|
+
elsif (num % 5).zero? then print 'Buzz'
|
47
|
+
elsif (num % 3).zero? then print 'Fizz'
|
48
|
+
else print num.to_s
|
49
|
+
end
|
50
|
+
print ' '
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def version
|
55
|
+
puts Fizzbuzz::VERSION
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
>>>
|
61
|
+
|
62
|
+
このコードはfizzbuzzとversionのコマンドを実行させる.
|
63
|
+
!!!runメソッド
|
64
|
+
コマンド実行を行うためのメソッドであり,argv配列を代入することでexecuteメソッドを実行する.
|
65
|
+
!!!initializeメソッド
|
66
|
+
初期化を行うメソッドである.
|
67
|
+
<<<
|
68
|
+
@argv = argv
|
69
|
+
>>>
|
70
|
+
こうすることでargvをクラス内で利用できるようにする.
|
71
|
+
!!!executeメソッド
|
72
|
+
上記でoptparseではopt.onにコマンドを登録する必要があると説明したが,opt.onで登録できるものはハイフンがついたコマンドだけであり,ハイフンなしのコマンドの登録はこのようになる.
|
73
|
+
|
74
|
+
argv配列の解析を行うOptions.parse!(@argv)をoptionsに代入して解析を行いsub_commandに代入する.sub_commandがfizzbuzzであればfizzbuzz(options[:id])メソッドを実行,versionであればversionメソッドを実行する.
|
75
|
+
!!!fizzbuzzメソッド
|
76
|
+
引数としてlimit_numberを受け取り,0〜limit_numberまでの数字を繰り返す.numが15であればFizzbuzzを表示,5であればBuzzを表示,3であればFizzを表示,それ以外は数字を表示し,その後に空白を表示する.
|
77
|
+
!!!versionメソッド
|
78
|
+
fizzbuzzのバージョンを表示する.
|
15
79
|
|
16
80
|
!!Thor
|
17
|
-
Thorとは,コマンドラインツールの作成を支援するライブラリのことである.gitやbundlerのようにサブコマンドを含むコマンドラインツールを簡単に作成することができる[
|
81
|
+
Thorとは,コマンドラインツールの作成を支援するライブラリのことである.gitやbundlerのようにサブコマンドを含むコマンドラインツールを簡単に作成することができる[4].
|
18
82
|
|
19
83
|
Thorの基本的な流れとしては
|
20
84
|
#Thorを継承したクラスのパブリックメソッドがコマンドになる
|
21
85
|
#クラス.start(ARGV)でコマンドラインの処理をスタートする
|
22
|
-
である[
|
86
|
+
である[4].
|
23
87
|
|
24
88
|
startに渡す引数が空の場合,Thorはクラスのヘルプリストを出力する.また,Thorはサブコマンドやサブサブコマンドも容易に作ることができる.
|
25
89
|
|
90
|
+
以下に示したコードがThorで記述されたfizzbuzzである.
|
91
|
+
|
92
|
+
<<< ruby
|
93
|
+
module Fizzbuzz
|
94
|
+
class CLI < Thor
|
95
|
+
|
96
|
+
desc 'fizzbuzz', 'Get fizzbuzz result from limit number'
|
97
|
+
def fizzbuzz(limit)
|
98
|
+
print Fizzbuzz.fizzbuzz(limit).join(',')
|
99
|
+
exit
|
100
|
+
end
|
101
|
+
|
102
|
+
desc 'version', 'version'
|
103
|
+
def version
|
104
|
+
puts Fizzbuzz::VERSION
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
>>>
|
109
|
+
|
110
|
+
このコードもoptparseのfizzbuzzと同様fizzbuzzとversionのコマンドを実行させる.
|
111
|
+
!!!fizzbuzzメソッド,versionメソッド
|
112
|
+
descでコマンド一覧で表示させるコマンド名と説明を書く.
|
113
|
+
|
114
|
+
メソッド内ではそれぞれのコマンドの処理内容が書かれている.
|
115
|
+
|
116
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|