lib/templates/Rakefile_hiki_sync in hikiutils-0.2.3.13 vs lib/templates/Rakefile_hiki_sync in hikiutils-0.2.3.14

- old
+ new

@@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- require 'systemu' require 'tempfile' require 'colorize' +require 'coderay' + # -*- coding: utf-8 -*- begin $hiki_dir = File.readlines('./.hikirc')[0].chomp rescue => e puts e @@ -34,11 +36,11 @@ stdout.split("\n").each{|line| files << line.split(/\s+/)[-1] } r_files = files.reverse[0..-4] r_files.each{|file| - print "remove #{file}? [ynqlA] ".red + print "remove #{file}[ynqlA]? ".red input=STDIN.gets.chomp case input when 'y' p command="hiki --remove #{file}" system command @@ -47,11 +49,11 @@ p command="hiki -l #{$basename}" system command when 'q' exit when 'A' - print "\nAre you sure? [Yn] ".magenta + print "\nAre you sure[Yn]? ".magenta input2 = STDIN.gets.chomp case input2 when 'Y' r_files.each{|file| system "hiki --remove #{file}"} p target = File.join($hiki_dir,'cache','attach',$basename) @@ -64,13 +66,15 @@ end desc "latex_dirのゴミを掃除" task :reset_latex_dir do system "mv latex_dir/head.tex ." + system "mv latex_dir/jlisting.sty ." system "rm -rf latex_dir" system "mkdir latex_dir" system "mv head.tex latex_dir/" + system "mv jlisting.sty latex_dir/" system "rake latex_all" end desc "toc.hikiの作成" task :mk_toc do @@ -78,18 +82,14 @@ cont="" File.readlines(File.join('latex_dir',target)).each{|line| if m=line.match(/\\contentsline \{(.+)\}\{\\numberline \{([\d|\.]+)\}(.+)\}\{\d+\}/) layer,sec_no,title=m[1],m[2],m[3] d = case m[1] - when 'section' - 1 - when 'subsection' - 2 - when 'subsubsection' - 3 - else - 4 + when 'section'; 1 + when 'subsection'; 2 + when 'subsubsection'; 3 + else; 4 end layer = "!"*d title.gsub!('\_','_') cont << "#{layer}#{sec_no}:#{title}\n" end @@ -99,30 +99,31 @@ end desc "FILE.hikiあるいはhikiファイルすべてを最新状態に更新" task :touch do if file=ARGV[1] - p target = $basename+"_"+file.split('.')[0] + file_split=file.split(".") + p target = $basename==file_split[0] ? $basename : $basename+"_"+file_split[0] system "hiki -u #{target}" else p target = File.join($hiki_dir,'cache','attach',$basename) system "touch #{target}/*" Dir.entries('.').each{|file| file_split=file.split(".") if file_split[1]=='hiki' - next if file_split[0]==$basename p target = $basename==file_split[0] ? $basename : $basename+"_"+file_split[0] system "hiki -u #{target}" end } end exit end desc "FILE.hikiあるいはhikiファイルをedtiorで開く" task :open do - if file=ARGV[1] + if file=ARGV[1] + file += '.hiki' if file.split(".")[1]==nil system "open -a mi #{file}" else Dir.entries('.').each{|file| file_split=file.split(".") if file_split[1]=='hiki' @@ -142,10 +143,11 @@ task :latex_wrap => [:latex_base, :change_wrap] do exit end def latex_loop(entries,opts={}) + check_bounding_box main_file="" entries.each{|file| options={:latex_all=>true} next unless file.split('.')[1]=='hiki' next if file=='toc.hiki' @@ -187,19 +189,25 @@ $bounding_box=" 0 0 737 553" end desc "すべてのhikiファイルをlatex変換" task :latex_all do - check_bounding_box p entries=Dir.entries('.') main_file = latex_loop(entries,opts={:main=>true}) latex_loop(entries) cont="" p reg_exp = Regexp.new("#{$basename}_(.+)") toc = false File.readlines(File.join($latex_dir,"#{main_file}.tex")).each{|line| - line, toc = "", true if line.match(/\\tableofcontents/) and toc == true #only one +# line, toc = "", true if line.match(/\\tableofcontents/) and toc == true #only one + if line.match(/\\tableofcontents/) + if toc == false #only one + toc = true + else + line = '' + end + end line ="\\usepackage{listings,jlisting}" if line.match(/\\usepackage{listings}/) if line.match(/section{(.+)}/) if m=line.match(/\\verb\|(.+)\((.+)\)\|/) p m p m_t=m[2].match(reg_exp)[1] @@ -283,11 +291,11 @@ line.sub!(r_pair[0],"\\cite\{#{m[1]}\}") end while m=line.match(r_pair[1]) line.sub!(r_pair[1],"\\ref\{#{m[1]}\}") end - puts line.chomp.blue +# puts line.chomp.blue return line end task :change_wrap do lines = File.readlines($save_name) @@ -438,10 +446,17 @@ p cp_files=[[File.join(Dir.pwd,'Rakefile'),'Rakefile_hiki_sync'], [File.join(ENV['HOME'],'.my_help','hiki_help.yml'),'hiki_help.yml']] cp_files.each{|files| p source = files[0] p target = File.join('/Users/bob/Github/hikiutils/lib/templates/',files[1]) - FileUtils.cp(source,target,:verbose=>true) + command = "diff #{source} #{target}" + status, stdout, stderr=systemu command + if stdout!='' + puts command.red + puts CodeRay.scan(stdout, :Diff).term + print " Are you sure to save #{source}? [Yn] ".red + FileUtils.cp(source,target,:verbose=>true) if STDIN.gets.chomp=='Y' + end } end task :check_previous do current={}