#!/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? 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('-x',"--exec_only", "exec only mode (no document!)") do Settings["cfg_dyn.model_doc"] = "Content" Settings["cfg_dyn.exec_mode"] = "yes" 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("-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 if dyntaskname=cfg_yml["dyntask"] puts dyntaskname if File.exists? dyntaskname dynfile=docname+".dyn" FileUtils.cp dyntaskname, dynfile 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