#!/usr/bin/env ruby require 'dyndoc/document' args=ARGV.select{|name| if (name[0,2]!="--" and name.include? "=") key,*val=name.split("=") val=val.join("=") Settings["cfg_dyn.user_input"] << [key,val] false else true end } args=["-h"] if args.empty? # Default for dyn-yml is without :R and :jl and :exec_mode activated since it is tailor-made for managing task # use option -R to activate :R (and :jl if declared in ~/.dyndoc.yml) Settings['cfg_dyn.ruby_only']=true # use option -w (like write) to deactivate exec_mode Settings["cfg_dyn.model_doc"] = "Content" Settings["cfg_dyn.exec_mode"] = "yes" require 'optparse' OptionParser.new do |opts| opts.banner = "Usage: dyndoc-compile.rb [options]" opts.on("-d", "--docs one,two,three", Array, "list of documents to compile") do |list| Settings["cfg_dyn.doc_list"] = list end opts.on("-f", "--format ", "format of the dyndoc document") do |format| Settings["cfg_dyn.format_doc"] = format.to_sym end opts.on('-t','--tags TAGS',Array,'filter tags') {|t| Settings["cfg_dyn.tag_tmpl"] = t} opts.on('-C',"--content_only", "content only mode (no header!)") do Settings["cfg_dyn.model_doc"] = "Content" end opts.on('-w',"--no_exec_only", "exec only mode (no document!)") do Settings["cfg_dyn.model_doc"] = "default" Settings["cfg_dyn.exec_mode"] = "no" end opts.on('-c', '--cmd COMMAND','[a(rchive old)][r(emove old)][s(ave)][pdf(latex)]') {|c| cmd =[:make_content] cmd << :save_old if c.include? "a" cmd << :rm_old if c.include? "r" cmd << :save if c.include? "s" ## cmd << :cat if c.include? "c" cmd << :pdf if c =~ /(E)?pdf([1-3])?/ #if c.include? "pdf" Settings["cfg_dyn.options.pdflatex_echo"]=true if $1 # useable for log sytem (to introduce possibly later) Settings["cfg_dyn.options.pdflatex_nb_pass"]=$2.to_i if $2 ## cmd << :png if c.include? "png" ## cmd << :view if c.include? "v" ## cmd << :save << :view if c.include? "x" ## cmd =[:cat] if cmd.empty? #and cfg_dyn[:model_doc]=="content" ## cmd = [:pdf] if c=="pdf" #only pdflatex Settings["cfg_dyn.cmd_doc"] = cmd } opts.on("-l", "--list", "list of documents available") do Settings["cfg_dyn.cmd_doc"] = [:list] end opts.on("-j", "--jl", "import julia") do Settings["cfg_dyn.langs"] << :jl end # opts.on("-r", "--remote", "pandoc or pdflatex (dyn)task performed remotely") do # Settings["cfg_dyn.remote_dyntask"] = true # end opts.on('-D','--debug','debug mode') do Settings['cfg_dyn.debug']=true end opts.on('-R','--no_rb_only','no ruby only mode') do Settings['cfg_dyn.ruby_only']=false end opts.on("-p", "--pandoc ", "filter for pandoc (tex2docx,...)") do |f| #p [:pandoc,f] Settings["cfg_dyn.pandoc_filter"] = f end # opts.on('--docker',"docker mode") do # Settings["cfg_dyn.docker_mode"]=true # end end.parse!(args) ## ARGV is consumed before except doc=args[0] doc += "_dyn.yml" unless doc =~ /_dyn.yml$/ require 'yaml' require 'fileutils' cfg_yml=YAML::load_file(doc) doc =~ /^(.*)_dyn\.yml$/ docname=$1 unless cfg_yml["dyntask"] #attempt to know if format is the simplified one for workflow ks=cfg_yml.keys cfg2={"dyntask" => "workflow", "params" => {"id" => ks[0], "workdir" => cfg_yml[ks[0]]}} tasks={} ks[1..-1].each do |t| kt,*pt=cfg_yml[t].strip.split("\n") wt,tn=kt.strip.split("->").map{|e| e.strip if e} if tn tasks[t]={"dyntask" => tn} wt="init" if wt.empty? tasks[t]["wait"]=wt pt=YAML::load(pt.join("\n")) tasks[t]["params"]=pt else puts "Warning: task "+ t + " not considered because malformed" end end cfg2["params"]["tasks"]=tasks cfg_yml=cfg2 end dyntaskname=cfg_yml["dyntask"] if dyntaskname puts dyntaskname dyntaskname += "_task.dyn" unless dyntaskname=~/_task.dyn$/ dyntaskpath=dyntaskname is_dyntask=File.exists? dyntaskpath unless is_dyntask dyntaskpath=File.join(ENV["HOME"],"dyndoc","tasks",dyntaskname) is_dyntask=File.exists? dyntaskpath end unless is_dyntask share_path=File.expand_path("../../share", __FILE__) dyntaskpath=File.join(share_path,"dyntasks",dyntaskname) is_dyntask=File.exists? dyntaskpath end if is_dyntask dynfile=docname+".dyn" FileUtils.cp dyntaskpath, dynfile $params=cfg_yml["params"] $dyntask=dyntaskname cfg_yml["params"].each do |key,val| Settings["cfg_dyn.user_input"] << [key,val] end d=Dyndoc::TemplateDocument.new(dynfile) d.make_all end end