#!/usr/bin/env ruby require 'dyndoc/document' puts "bin" ;p $0 ## p Dyndoc.cfg_dir ## To be used for remote at the end args_saved=ARGV.dup 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('-r','--rb_only','ruby only mode') do Settings['cfg_dyn.ruby_only']=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] # Example remote call # dyn dyn:///[.dyn] if doc=~ /^dyn\:\/\/([^\/]*)\/(.*)(?:\.dyn)?$/ room_id,dyn_file=$1,$2 room_sync=File.join(ENV["HOME"],"dyndoc","etc",".room_sync") if File.exists? room_sync room_dirs=eval(File.read(room_sync)) room_dir=room_dirs[room_id] if room_dir dyn_file=File.expand_path(dyn_file) dyn_dir=File.dirname dyn_file dyn_base=File.basename dyn_file,".dyn" ## Copy files first [".dyn",".dyn_lib"].each do |ext| file=dyn_base+ext if File.exists? (file_to_copy=File.join(dyn_dir,file)) require 'fileutils' FileUtils.cp file_to_copy,File.join(room_dir[:local],file) end end ## create task after ##TODO cheksum: to check that required files are present task=[{cmd: "dyn", workdir: File.join("..","rooms",room_dir[:remote]), source: dyn_base+".dyn", options: args[0...-1].join(" ")}] File.open(File.join(room_dir[:local],"..",".run",dyn_base+".task_dyn"),"w") do |f| f << task.inspect end end end else d=Dyndoc::TemplateDocument.new(doc) d.make_all end