my_help 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.gitignore +1 -0
  4. data/.rspec +2 -0
  5. data/Gemfile +1 -0
  6. data/README.md +1 -1
  7. data/Rakefile +35 -12
  8. data/exe/{todo_help → my_todo} +1 -1
  9. data/hikis/diff_against_org-mode.hiki +34 -0
  10. data/hikis/tmp.org +20 -0
  11. data/lib/.emacs_help.rb.swp +0 -0
  12. data/lib/daddygongon/my_todo.yml +31 -0
  13. data/lib/emacs_help.rb +15 -0
  14. data/lib/emacs_help.rb~ +137 -0
  15. data/lib/my_help/test.rb +3 -0
  16. data/lib/my_help/version.rb +1 -1
  17. data/lib/my_help.rb +1 -1
  18. data/lib/my_todo/my_todo.rb +7 -0
  19. data/lib/my_todo/my_todo.rb~ +7 -0
  20. data/lib/specific_help.rb +42 -11
  21. data/lib/specific_help.rb~ +193 -0
  22. data/lib/todo.rb +1 -0
  23. data/lib/todo.rb~ +1 -0
  24. data/lor +0 -0
  25. data/my_help.gemspec +4 -2
  26. data/my_help.wiki/Home.md +1 -1
  27. data/my_help.wiki/README_ja.md +1 -1
  28. data/my_help_nasu/.DS_Store +0 -0
  29. data/my_help_nasu/.gitignore +1 -0
  30. data/my_help_nasu/Rakefile +422 -0
  31. data/my_help_nasu/code.hiki +285 -0
  32. data/my_help_nasu/consideration.hiki +8 -0
  33. data/my_help_nasu/features.hiki +185 -0
  34. data/my_help_nasu/figs/my_help_nasu.001.jpeg +0 -0
  35. data/my_help_nasu/figs/my_help_nasu.001.jpg +0 -0
  36. data/my_help_nasu/figs/my_help_nasu1.001.jpg +0 -0
  37. data/my_help_nasu/head2.tex +9 -0
  38. data/my_help_nasu/hiki_help.yml +53 -0
  39. data/my_help_nasu/introduction.hiki +29 -0
  40. data/my_help_nasu/key_bind_mi +1 -0
  41. data/my_help_nasu/latex_dir/.gitignore +1 -0
  42. data/my_help_nasu/latex_dir/Rakefile +420 -0
  43. data/my_help_nasu/latex_dir/code.aux +25 -0
  44. data/my_help_nasu/latex_dir/code.tex +271 -0
  45. data/my_help_nasu/latex_dir/consideration.aux +22 -0
  46. data/my_help_nasu/latex_dir/consideration.tex +9 -0
  47. data/my_help_nasu/latex_dir/features.aux +31 -0
  48. data/my_help_nasu/latex_dir/features.tex +173 -0
  49. data/my_help_nasu/latex_dir/head.tex +9 -0
  50. data/my_help_nasu/latex_dir/hiki_help.yml +53 -0
  51. data/my_help_nasu/latex_dir/introduction.aux +22 -0
  52. data/my_help_nasu/latex_dir/introduction.tex +23 -0
  53. data/my_help_nasu/latex_dir/jlisting.sty +216 -0
  54. data/my_help_nasu/latex_dir/jlisting.tex +216 -0
  55. data/my_help_nasu/latex_dir/latex_dir/head.tex +9 -0
  56. data/my_help_nasu/latex_dir/latex_dir/jlisting.tex +216 -0
  57. data/my_help_nasu/latex_dir/latex_dir/pre.tex +36 -0
  58. data/my_help_nasu/latex_dir/method_bdd.aux +26 -0
  59. data/my_help_nasu/latex_dir/method_bdd.tex +28 -0
  60. data/my_help_nasu/latex_dir/method_cucumber.aux +28 -0
  61. data/my_help_nasu/latex_dir/method_cucumber.log +28 -0
  62. data/my_help_nasu/latex_dir/method_cucumber.tex +205 -0
  63. data/my_help_nasu/latex_dir/method_usage.aux +28 -0
  64. data/my_help_nasu/latex_dir/method_usage.tex +76 -0
  65. data/my_help_nasu/latex_dir/my_help_nasu.aux +12 -0
  66. data/my_help_nasu/latex_dir/my_help_nasu.log +328 -0
  67. data/my_help_nasu/latex_dir/my_help_nasu.pdf +0 -0
  68. data/my_help_nasu/latex_dir/my_help_nasu.synctex.gz +0 -0
  69. data/my_help_nasu/latex_dir/my_help_nasu.tex +74 -0
  70. data/my_help_nasu/latex_dir/my_help_nasu.toc +32 -0
  71. data/my_help_nasu/latex_dir/overview.aux +21 -0
  72. data/my_help_nasu/latex_dir/overview.tex +12 -0
  73. data/my_help_nasu/latex_dir/pre.tex +36 -0
  74. data/my_help_nasu/method_bdd.hiki +24 -0
  75. data/my_help_nasu/method_cucumber.hiki +184 -0
  76. data/my_help_nasu/method_usage.hiki +69 -0
  77. data/my_help_nasu/my_help_nasu/.DS_Store +0 -0
  78. data/my_help_nasu/my_help_nasu/my_help_nasu.001.jpeg +0 -0
  79. data/my_help_nasu/my_help_nasu.hiki +32 -0
  80. data/my_help_nasu/my_help_nasu.key +0 -0
  81. data/my_help_nasu/overview.hiki +11 -0
  82. data/tmp.txt +2 -0
  83. metadata +104 -10
  84. data/lib/daddygongon/git_help.yml +0 -30
  85. data/lib/daddygongon/todo_help.yml +0 -58
@@ -0,0 +1,193 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "optparse"
3
+ require "yaml"
4
+ require "my_help/version"
5
+ require 'fileutils'
6
+ require "coderay"
7
+
8
+ module SpecificHelp
9
+ class Command
10
+
11
+ def self.run(file,argv=[])
12
+ new(file, argv).execute
13
+ end
14
+
15
+ def initialize(file,argv=[])
16
+ @source_file = file
17
+ @help_cont = YAML.load(File.read(file))
18
+ @help_cont[:head].each{|line| print line.chomp+"\n" } if @help_cont[:head] != nil
19
+ @help_cont[:license].each{|line| print "#{line.chomp}\n" } if @help_cont[:license] != nil
20
+ @argv = argv
21
+ end
22
+
23
+ def execute
24
+ if @argv.size==0
25
+ if @source_file.include?('todo')
26
+ @argv << '--all'
27
+ else
28
+ @argv << '--help'
29
+ end
30
+ end
31
+ command_parser = OptionParser.new do |opt|
32
+ opt.on('-v', '--version','show program Version.') { |v|
33
+ opt.version = MyHelp::VERSION
34
+ puts opt.ver
35
+ }
36
+ @help_cont.each_pair{|key,val|
37
+ next if key==:head or key==:license
38
+ opts = val[:opts]
39
+ opt.on(opts[:short],opts[:long],opts[:desc]) {disp_help(key)}
40
+ }
41
+
42
+ opt.on('--edit','edit help contentsを開く'){edit_help}
43
+ opt.on('--to_hiki','hikiのformatに変更する'){to_hiki}
44
+ opt.on('--all','すべてのhelp画面を表示させる'){all_help}
45
+ opt.on('--store [item]','store [item] でback upをとる'){|item| store(item)}
46
+ opt.on('--remove [item]','remove [item] back upしてるlistを消去する'){|item| remove(item) }
47
+ opt.on('--add [item]','add new [item]で新しいhelpを作る'){|item| add(item) }
48
+ opt.on('--backup_list [val]','back upしているlistを表示させる'){|val| backup_list(val)}
49
+
50
+ # opt.on('--edit','edit help contents'){edit_help}
51
+ # opt.on('--to_hiki','convert to hikidoc format'){to_hiki}
52
+ # opt.on('--all','display all helps'){all_help}
53
+ # opt.on('--store [item]','store [item] in backfile'){|item| store(item)}
54
+ # opt.on('--remove [item]','remove [item] and store in backfile'){|item| remove(item) }
55
+ # opt.on('--add [item]','add new [item]'){|item| add(item) }
56
+ # opt.on('--backup_list [val]','show last [val] backup list'){|val| backup_list(val)}
57
+
58
+ end
59
+ begin
60
+ command_parser.parse!(@argv)
61
+ rescue=> eval
62
+ p eval
63
+ end
64
+ exit
65
+ end
66
+
67
+ def backup_list(val)
68
+ val = val || 10
69
+ print "\n ...showing last #{val} stored items in backup.\n"
70
+ backup=mk_backup_file(@source_file)
71
+ File.open(backup,'r'){|file|
72
+ backup_cont = YAML.load(File.read(backup))
73
+ backup_size = backup_cont.size
74
+ backup_size = backup_size>val.to_i ? val.to_i : backup_size
75
+ backup_keys = backup_cont.keys
76
+ backup_keys.reverse.each_with_index{|item,i|
77
+ break if i>=backup_size
78
+ line = item.to_s.split('_')
79
+ printf("%10s : %8s%8s\n",line[0],line[1],line[2])
80
+ }
81
+ }
82
+ end
83
+
84
+ def mk_backup_file(file)
85
+ path = File.dirname(file)
86
+ base = File.basename(file)
87
+ backup= File.join(path,"."+base)
88
+ FileUtils.touch(backup) unless File.exists?(backup)
89
+ return backup
90
+ end
91
+
92
+ def store(item)
93
+ if item==nil
94
+ print "spcify --store [item].\n"
95
+ exit
96
+ else
97
+ print "Trying to store #{item}\n"
98
+ end
99
+ backup=mk_backup_file(@source_file)
100
+ unless store_item = @help_cont[item.to_sym] then
101
+ print "No #{item} in this help. The items are following...\n"
102
+ keys = @help_cont.keys
103
+ keys.each{|key|
104
+ p key
105
+ }
106
+ exit
107
+ end
108
+ p store_name = item+"_"+Time.now.strftime("%Y%m%d_%H%M%S")
109
+ cont = {store_name.to_sym => store_item}
110
+ backup_cont=YAML.load(File.read(backup)) || {}
111
+ backup_cont[store_name.to_sym]=store_item
112
+ File.open(backup,'w'){|file| file.print(YAML.dump(backup_cont))}
113
+ end
114
+
115
+ def add(item='new_item')
116
+ print "Trying to add #{item}\n"
117
+ new_item={:opts=>{:short=>'-'+item[0], :long=>'--'+item, :desc=>item},
118
+ :title=>item, :cont=> [item]}
119
+ @help_cont[item.to_sym]=new_item
120
+ File.open(@source_file,'w'){|file| file.print YAML.dump(@help_cont)}
121
+ end
122
+
123
+ def remove(item)
124
+ print "Trying to remove #{item}\n"
125
+ store(item)
126
+ @help_cont.delete(item.to_sym)
127
+ File.open(@source_file,'w'){|file| file.print YAML.dump(@help_cont)}
128
+ end
129
+
130
+ def edit_help
131
+ p help_file =@source_file
132
+ begin
133
+ p command= "emacs #{help_file}"
134
+ exec command
135
+ rescue => e
136
+ print "\nOption edit is not executable on windows. \n"
137
+ print "Type the following shell command;\n\n"
138
+ print "emacs /home/#{ENV['USER']}/.my_help/#{File.basename(@source_file)}\n\n"
139
+ print "M-x ruby-mode should be good for edit.\n"
140
+ end
141
+ end
142
+
143
+ def to_hiki
144
+ @help_cont.each_pair{|key,val|
145
+ if key==:head or key==:license
146
+ hiki_disp(val)
147
+ else
148
+ hiki_help(key)
149
+ end
150
+ }
151
+ end
152
+
153
+ def all_help
154
+ @help_cont.each_pair{|key,val|
155
+ if key==:head or key==:license
156
+ val[0]+=":"
157
+ disp(val)
158
+ else
159
+ disp_help(key)
160
+ end
161
+ }
162
+ end
163
+
164
+ def hiki_help(key_word)
165
+ items =@help_cont[key_word]
166
+ puts "\n!!"+items[:title]+"\n"
167
+ hiki_disp(items[:cont])
168
+ end
169
+
170
+ def hiki_disp(lines)
171
+ lines.each{|line| puts "*#{line}"} if lines != nil
172
+ end
173
+
174
+ def disp_help(key_word)
175
+ print_separater
176
+ items =@help_cont[key_word]
177
+ # puts items[:title]
178
+ puts CodeRay.scan("-#{items[:title]}:", :Taskpaper).term
179
+ disp(items[:cont])
180
+ print_separater
181
+ end
182
+
183
+ def disp(lines)
184
+ # lines.each{|line| puts " +#{line}"} if lines != nil
185
+ # lines.each{|line| puts CodeRay.scan("*#{line}", :diff).term}
186
+ lines.each{|line| puts CodeRay.scan("+#{line}", :Taskpaper).term}
187
+ end
188
+
189
+ def print_separater
190
+ print "---\n"
191
+ end
192
+ end
193
+ end
data/lib/todo.rb ADDED
@@ -0,0 +1 @@
1
+ require 'my_todo/my_todo'
data/lib/todo.rb~ ADDED
@@ -0,0 +1 @@
1
+ require 'my_todo/todo'
data/lor ADDED
File without changes
data/my_help.gemspec CHANGED
@@ -32,7 +32,9 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "minitest", "~> 5.0"
33
33
  spec.add_development_dependency "yard"
34
34
  spec.add_development_dependency "hiki2md"
35
- spec.add_development_dependency "mathjax-yard"
36
- spec.add_development_dependency "hiki2latex"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "aruba"
37
37
  spec.add_dependency "systemu"
38
+ spec.add_dependency "coderay"
39
+ spec.add_dependency "colorize"
38
40
  end
data/my_help.wiki/Home.md CHANGED
@@ -327,4 +327,4 @@ add_yml, to_ymlは3.6から4.0へ移行する時に行ったhelpファイルの
327
327
  add_ymlは~/.my_help/*_helpファイルを全て~/.my_help/*_help.ymlに変える.
328
328
  to_ymlは~/.emacs.d/init.elに'.yml'の設定が書き込まれていない時,ruby-modeでemacsを起動するsciptを埋め込む.
329
329
 
330
- clean_exeは,githubへuploadする時に,開発者個人のhelpファイルをrmして整頓する.
330
+ clean_exeは,githubへuploadする時に,開発者個人のexeファイルをrmして整頓する.
@@ -327,4 +327,4 @@ add_yml, to_ymlは3.6から4.0へ移行する時に行ったhelpファイルの
327
327
  add_ymlは~/.my_help/*_helpファイルを全て~/.my_help/*_help.ymlに変える.
328
328
  to_ymlは~/.emacs.d/init.elに'.yml'の設定が書き込まれていない時,ruby-modeでemacsを起動するsciptを埋め込む.
329
329
 
330
- clean_exeは,githubへuploadする時に,開発者個人のhelpファイルをrmして整頓する.
330
+ clean_exeは,githubへuploadする時に,開発者個人のexeファイルをrmして整頓する.
Binary file
@@ -0,0 +1 @@
1
+ .hikirc
@@ -0,0 +1,422 @@
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
+ p 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]"
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'
84
+ 1
85
+ when 'subsection'
86
+ 2
87
+ when 'subsubsection'
88
+ 3
89
+ else
90
+ 4
91
+ end
92
+ layer = "!"*d
93
+ title.gsub!('\_','_')
94
+ cont << "#{layer}#{sec_no}:#{title}\n"
95
+ end
96
+ }
97
+ print cont
98
+ File.open("toc.hiki",'w'){|file| file.print cont}
99
+ end
100
+
101
+ desc "FILE.hikiあるいはhikiファイルすべてを最新状態に更新"
102
+ task :touch do
103
+ if file=ARGV[1]
104
+ p target = $basename+"_"+file.split('.')[0]
105
+ system "hiki -u #{target}"
106
+ else
107
+ p target = File.join($hiki_dir,'cache','attach',$basename)
108
+ system "touch #{target}/*"
109
+ Dir.entries('.').each{|file|
110
+ file_split=file.split(".")
111
+ if file_split[1]=='hiki'
112
+ next if file_split[0]==$basename
113
+ p target = $basename+"_"+file_split[0]
114
+ system "hiki -u #{target}"
115
+ end
116
+ }
117
+ end
118
+ end
119
+
120
+ desc "FILE.hikiあるいはhikiファイルをedtiorで開く"
121
+ task :open do
122
+ if file=ARGV[1]
123
+ system "open -a mi #{file}"
124
+ else
125
+ Dir.entries('.').each{|file|
126
+ file_split=file.split(".")
127
+ if file_split[1]=='hiki'
128
+ p target = file_split[0]
129
+ system "open -a mi #{target}"
130
+ end
131
+ }
132
+ end
133
+ end
134
+
135
+ desc "FILE1をlatexに変換"
136
+ task :latex => [:latex_base] do
137
+ exit
138
+ end
139
+
140
+ desc "FILE1をwrap formatでlatexに変換"
141
+ task :latex_wrap => [:latex_base, :change_wrap] do
142
+ exit
143
+ end
144
+
145
+ def latex_loop(entries,opts={})
146
+ main_file=""
147
+ entries.each{|file|
148
+ options={:latex_all=>true}
149
+ next unless file.split('.')[1]=='hiki'
150
+ next if file=='toc.hiki'
151
+ next if file.include?('.hikirc')
152
+ f_name =File.basename(file,'.hiki')
153
+ if opts[:main]
154
+ if f_name==$basename
155
+ options[:latex]="--listings --head latex_dir/head.tex -p "
156
+ options[:main]=true
157
+ main_file=f_name
158
+ convert_to_latex(file, options)
159
+ end
160
+ else
161
+ if f_name!=$basename
162
+ p level = $section_layer[f_name] || 1
163
+ options[:latex]="-l #{level} --listings -b "
164
+ convert_to_latex(file, options)
165
+ end
166
+ end
167
+ }
168
+ return main_file
169
+ end
170
+
171
+ def check_section_layers(lines)
172
+ p reg_exp = Regexp.new("#{$basename}_(.+)")
173
+ lines.each{|line|
174
+ p line
175
+ if m=line.match(/(!+)\[\[(.+)\]\]/)
176
+ p count = m[1].count('!')
177
+ p file_name=m[2].match(reg_exp)[1]
178
+ $section_layer[file_name]=count
179
+ end
180
+ }
181
+ p $section_layer
182
+ end
183
+
184
+ def check_bounding_box
185
+ # $bounding_box="0 0 442 432"
186
+ $bounding_box=" 0 0 737 453"
187
+ end
188
+
189
+ desc "すべてのhikiファイルをlatex変換"
190
+ task :latex_all do
191
+ p entries=Dir.entries('.')
192
+ check_bounding_box
193
+ main_file = latex_loop(entries,opts={:main=>true})
194
+ latex_loop(entries)
195
+ cont=""
196
+ p reg_exp = Regexp.new("#{$basename}_(.+)")
197
+ toc = false
198
+ File.readlines(File.join($latex_dir,"#{main_file}.tex")).each{|line|
199
+ line, toc = "", true if line.match(/\\tableofcontents/) and toc == true #only one
200
+ line ="\\usepackage{listings,jlisting}" if line.match(/\\usepackage{listings}/)
201
+ if line.match(/section{(.+)}/)
202
+ if m=line.match(/\\verb\|(.+)\((.+)\)\|/)
203
+ p m
204
+ p m_t=m[2].match(reg_exp)[1]
205
+ line = "\\include{#{m_t}}\n"
206
+ elsif m=line.match(/section{\\verb\|(.+)\|}/)
207
+ p m
208
+ p m_t=m[1].match(reg_exp)[1]
209
+ line = "\\include{#{m_t}}\n"
210
+ else
211
+ # line = ""
212
+ end
213
+ end
214
+ cont << line
215
+ }
216
+ File.open(File.join($latex_dir,"#{main_file}.tex"),'w'){|file| file.print cont}
217
+ system "open latex_dir/#{main_file}.tex"
218
+ exit
219
+ end
220
+
221
+ task :latex_base do
222
+ Dir.mkdir($latex_dir) unless Dir.exist?($latex_dir)
223
+ convert_to_latex(ARGV[1])
224
+ system("open #{$save_name}")
225
+ end
226
+
227
+ def convert_to_latex(file_name, options={})
228
+ p file_name = file_name.include?('.hiki')? file_name : file_name+'.hiki'
229
+ p tex_name = File.basename(file_name,'.hiki')+'.tex'
230
+ p $save_name = ARGV[2] || File.join($latex_dir,tex_name)
231
+ pre_name = File.join($latex_dir,'pre.tex')
232
+ p pre_command = File.exist?(pre_name) ? '--pre '+pre_name : nil
233
+ lines = File.readlines(file_name)
234
+ check_section_layers(lines) if options[:main]
235
+ cont = ""
236
+ lines.each_with_index{|line,i|
237
+ if m=line.match(/\{\{attach_view\((.*),(.*)\)\}\}/)
238
+ p line="\{\{attach_view\(#{m[1]}\)\}\}\n"
239
+ elsif options[:latex_all] and i<5
240
+ line="" if line.match(/^!title:|^!author:|^!date:/)
241
+ end
242
+ cont << line
243
+ }
244
+ tf1,tf2='tmp1.txt','tmp2.txt'
245
+ File.open(tf1,'w'){|file| file.print cont}
246
+ system "hiki2latex #{pre_command} #{options[:latex]} #{tf1} > #{tf2}"
247
+ lines = File.readlines(tf2)
248
+ system "rm #{tf1} #{tf2}"
249
+ cont = ""
250
+ lines.each{|line|
251
+ if m=line.match(/\\includegraphics\[width=6cm\]\{(.+)\}/)
252
+ p line="\\includegraphics\[width=10cm,bb=#{$bounding_box}\]\{../figs/#{m[1]}\}\n"
253
+ cont << line
254
+ else
255
+ cont << line
256
+ end
257
+ }
258
+ File.open($save_name,'w'){|file| file.print cont }
259
+ end
260
+
261
+ task :change_wrap do
262
+ lines = File.readlines($save_name)
263
+
264
+ cont = ""
265
+ lines.each{|line|
266
+ if line.include?('\begin{figure}[htbp]\begin{center}')
267
+ p line
268
+ cont << '\begin{wrapfigure}{r}{8cm}'+"\n"
269
+ cont << '\vspace{-2\baselineskip}'+"\n"
270
+ cont << '\begin{center}'+"\n"
271
+ elsif line.include?('\label{default}\end{center}\end{figure}')
272
+ p line
273
+ cont << '\end{center}'+"\n"
274
+ cont << '\vspace{2\baselineskip}'+"\n"
275
+ cont << '\end{wrapfigure}'+"\n"
276
+ else
277
+ cont << line
278
+ end
279
+ }
280
+ File.open($save_name,'w'){|file| file.print cont }
281
+
282
+ system("open #{$save_name}")
283
+ exit
284
+ end
285
+
286
+
287
+ desc "increment fig NUBERS in FILE"
288
+ task :increment do
289
+ number=ARGV[1]
290
+ file = ARGV[2]
291
+ dir = ARGV[3] || nil
292
+ lines = File.readlines(file)
293
+ cont = ""
294
+ lines.each{|line|
295
+ if m=line.match(/\{\{attach_view\((\w+|_).(\d+).jpeg\)\}\}/)
296
+ new_num=sprintf("%03d",m[2].to_i+number.to_i)
297
+ line="\{\{attach_view\(#{m[1]}.#{new_num}.jpeg,#{dir}\)\}\}\n"
298
+ cont << line
299
+ else
300
+ cont << line
301
+ end
302
+ }
303
+ print cont
304
+ exit
305
+ end
306
+
307
+ desc "numbering figs from the NUBER in FILE"
308
+ task :number do
309
+ number=ARGV[1].to_i
310
+ file = ARGV[2]
311
+ dir = ARGV[3] || nil
312
+ lines = File.readlines(file)
313
+ cont = ""
314
+ lines.each{|line|
315
+ if m=line.match(/\{\{attach_view\((\w+|_).(\d+).jpeg,(\w+)\)\}\}/)
316
+ new_num=sprintf("%03d",number)
317
+ line="\{\{attach_view\(#{m[1]}.#{new_num}.jpeg,#{m[3]}\)\}\}\n"
318
+ cont << line
319
+ number += 1
320
+ else
321
+ cont << line
322
+ end
323
+ }
324
+ print cont
325
+ exit
326
+ end
327
+
328
+ desc "convert fig size SCALE TARGET_DIR"
329
+ task :convert do
330
+ scale = ARGV[1]
331
+ target_dir=ARGV[2]
332
+ Dir.entries(target_dir)[2..-1].each{|file|
333
+ p file
334
+ source = File.join(target_dir,file)
335
+ target = File.join('figs',file)
336
+ p command = "convert #{source} -resize #{scale}\% #{target}"
337
+ system command
338
+ }
339
+ exit
340
+ end
341
+
342
+ desc "hikiの同期"
343
+ task :sync => [:check_previous,:sync0]
344
+
345
+
346
+ desc "hikiの強制同期"
347
+ task :force_sync => [:sync0]
348
+
349
+ task :sync0 do
350
+ entries=Dir.entries('.')
351
+ entries[2..-1].each{|source| #cp *.hiki
352
+ next unless source.split('.')[1]=='hiki'
353
+ next if source.include?('.hikirc')
354
+ p base = source.split('.')[0]
355
+ name = (base==$basename)? base : $basename+'_'+base
356
+ p target = File.join($hiki_dir,'text',name)
357
+ FileUtils.cp(source,target,:verbose=>true)
358
+ }
359
+ p entries=Dir.entries('./figs') #cp files in figs
360
+ p target = File.join($hiki_dir,'cache','attach',$basename)
361
+ FileUtils.mkdir_p(target,:verbose=>true) unless File.exists?(target)
362
+ entries[2..-1].each{|file|
363
+ p source = File.join('./figs',file)
364
+ FileUtils.cp(source,target,:verbose=>true)
365
+ }
366
+
367
+ File.open('./.hikirc','w'){|file|
368
+ status, stdout, stderr =systemu "hiki -l #{$basename}*"
369
+ file.print($hiki_dir+"\n")
370
+ stdout.split("\n")[3..-1].each{|line|
371
+ file.print line+"\n"
372
+ }
373
+ }
374
+ exit
375
+ end
376
+
377
+ desc "For hiki Errno::ENOENT, Errno::EACCES"
378
+ task :chenv do
379
+ p user = ENV['USER']
380
+ system("sudo chmod -R a+w #{$hiki_dir}")
381
+ # system("sudo chown -R #{user} #{$hiki_dir}")
382
+ end
383
+
384
+ desc "self copy to hikiutils template directory"
385
+ task :self_copy do
386
+ p cp_files=[[File.join(Dir.pwd,'Rakefile'),'Rakefile_hiki_sync'],
387
+ [File.join(ENV['HOME'],'.my_help','hiki_help.yml'),'hiki_help.yml']]
388
+ cp_files.each{|files|
389
+ p source = files[0]
390
+ p target = File.join('/Users/bob/Github/hikiutils/lib/templates/',files[1])
391
+ FileUtils.cp(source,target,:verbose=>true)
392
+ }
393
+ end
394
+
395
+ task :check_previous do
396
+ current={}
397
+ print "current hiki dir\n"
398
+ status, stdout, stderr = systemu("hiki -l #{$basename}*")
399
+ stdout.split("\n")[3..-1].each{|line|
400
+ p line
401
+ file= line.split(/\s+/)[-1]
402
+ current[file]=line
403
+ }
404
+ previous={}
405
+ print "previous sync\n"
406
+ File.readlines('.hikirc')[1..-1].each{|line|
407
+ p line.chomp
408
+ file= line.split(/\s+/)[-1]
409
+ previous[file]=line.chomp
410
+ }
411
+ changed = []
412
+ current.each_pair{|key,val|
413
+ if !previous.include?(key) or previous[key]!=val
414
+ changed << val+"\n"
415
+ end
416
+ }
417
+ if changed.size != 0
418
+ print("hiki dirで変更が発生しています.\n")
419
+ changed.each{|line| print line+"\n"}
420
+ exit
421
+ end
422
+ end