bin/dyn-yml in dyndoc-ruby-1.2.0 vs bin/dyn-yml in dyndoc-ruby-1.2.1

- old
+ new

@@ -13,10 +13,17 @@ 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]" @@ -32,13 +39,13 @@ opts.on('-C',"--content_only", "content only mode (no header!)") do Settings["cfg_dyn.model_doc"] = "Content" end - opts.on('-x',"--exec_only", "exec only mode (no document!)") do - Settings["cfg_dyn.model_doc"] = "Content" - Settings["cfg_dyn.exec_mode"] = "yes" + 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" @@ -70,10 +77,14 @@ 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 @@ -90,17 +101,55 @@ require 'yaml' require 'fileutils' cfg_yml=YAML::load_file(doc) -doc =~ /^(.*)_dyn.yml$/ +doc =~ /^(.*)_dyn\.yml$/ docname=$1 -if dyntaskname=cfg_yml["dyntask"] - puts dyntaskname - if File.exists? dyntaskname +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 dyntaskname, dynfile + 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) \ No newline at end of file