class Dyndoc::TemplateDocument
Attributes
basename[RW]
basename_orig[RW]
cfg[RW]
content[RW]
dirname[RW]
dirname_orig[RW]
docs[RW]
tmpl_mngr[RW]
Public Class Methods
new(name)
click to toggle source
# File lib/dyndoc/document.rb, line 142 def initialize(name) #docs is a hash containing all the files ## complete with default extension if not provided name += ".dyn" if File.basename(name) == File.basename(name,".*") @name=name ## read config from name @cfg=@@cfg.dup read_cfg(@name) ## the template manager Dyndoc.tmpl_mngr=@tmpl_mngr = Dyndoc::Ruby::TemplateManager.new(@cfg) ## the documents @docs={} make_doc_list if @cfg[:content] #a non file based document is a Hash cfg with :content inside (give a basename used for generated files) @content=@cfg[:content] else # find the basename of the template @basename=basename_tmpl @dirname=File.dirname(@basename) @basename=File.basename(@basename) #p @basename @basename_orig=basename_tmpl_orig @dirname_orig=File.dirname(@basename_orig) @basename_orig=File.basename(@basename_orig) #p @basename_orig # read content of the template @content=File.read(@cfg[:filename_tmpl]) end # list of Document objects #puts "@doc_list (init)";p @doc_list @doc_list.each do |kdoc| @docs[kdoc]=Document.new(kdoc,self) end end
Public Instance Methods
basename_tmpl()
click to toggle source
document basename from template filename
# File lib/dyndoc/document.rb, line 281 def basename_tmpl ##p @cfg[:filename_tmpl] mode=Dyndoc.guess_mode(@cfg[:filename_tmpl]) ##p ["mode",mode,Dyndoc.tmplExt[mode]] if mode name,ext=@cfg[:filename_tmpl].scan(/^(.*)(?:#{Dyndoc.tmplExt[mode].join("|")})$/).flatten.compact else name,ext=@cfg[:filename_tmpl].scan(/^(.*)(?:_tmpl(\..*)|(\.dyn))$/).flatten.compact end #p [:name,@cfg[:filename_tmpl],name] name end
basename_tmpl_orig()
click to toggle source
# File lib/dyndoc/document.rb, line 294 def basename_tmpl_orig mode=Dyndoc.guess_mode(@cfg[:filename_tmpl_orig]) if mode name,ext=@cfg[:filename_tmpl_orig].scan(/^(.*)(?:#{Dyndoc.tmplExt[mode].join("|")})$/).flatten.compact else name,ext=@cfg[:filename_tmpl_orig].scan(/^(.*)(?:_tmpl(\..*)|(\.dyn))$/).flatten.compact end name end
cfg_dyn_from(tmpl)
click to toggle source
# File lib/dyndoc/document.rb, line 236 def cfg_dyn_from(tmpl) code,cfg_file=nil,nil code=File.read(cfg_file) if (cfg_file=(Dyndoc::Utils.cfg_file_exist? tmpl)) ##puts "code";p code;p cfg_file Utils.clean_bom_utf8!(code) if code code="Dyndoc::TexDoc" unless code return cfg_dyn_from_code(code) end
cfg_dyn_from_code(code)
click to toggle source
# File lib/dyndoc/document.rb, line 217 def cfg_dyn_from_code(code) if code and code.is_a? String code="{\n"+code+"\n}" if code=~/\A\s*\:/m #to avoid at the beginning { and at the end }! ##p [code,Object.class_eval(code)] return Object.class_eval(code) end return nil end
cfg_dyn_from_lib(content)
click to toggle source
# File lib/dyndoc/document.rb, line 226 def cfg_dyn_from_lib(content) return {:cfg=> nil, :lib_dyn_content => content} if content.empty? tmp=content.force_encoding("utf-8").split(/\[\#/) if tmp[0].empty? and tmp[1][0...4]=="cfg]" return {:cfg=> tmp[1][4..-1], :lib_dyn_content => (tmp[0,1]+tmp[2..-1]).join('[#')} else return {:cfg=> nil, :lib_dyn_content => content} end end
lib_dyn_content_from(tmpl=nil)
click to toggle source
# File lib/dyndoc/document.rb, line 211 def lib_dyn_content_from(tmpl=nil) code,lib_file = "",nil code=File.read(lib_file) if (lib_file=(Dyndoc::Utils.lib_file_exist? tmpl)) return code end
make_all()
click to toggle source
# File lib/dyndoc/document.rb, line 304 def make_all if @cfg[:cmd].include? :list puts "document list: "+@cfg[:docs].keys.join(", ") return end # Added for docker mode ##OBSOLETE## Docker.init_task_file if Dyndoc.cfg_dyn[:docker_mode] ##puts "@doc_list"; p @doc_list @doc_list.each do |kdoc| @docs[kdoc].make_all end ##OBSOLETE## Docker.save_task_file if Dyndoc.cfg_dyn[:docker_mode] end
make_doc_list()
click to toggle source
# File lib/dyndoc/document.rb, line 264 def make_doc_list doc_list=@cfg[:docs].keys #puts "@cfg[doc_list]";p @cfg[:doc_list] doc_list &= @cfg[:doc_list] unless @cfg[:doc_list].empty? #p doc_list #deal with aliases doc_alias={} @cfg[:docs].each_pair{|key,doc| doc_alias[key]=doc if doc.is_a? Array } #puts "doc_alias";p doc_alias doc_list=doc_list.map{|key| (doc_alias[key] ? doc_alias[key] : key )}.flatten until (doc_list & doc_alias.keys).empty? @doc_list=doc_list #puts "doc_list";p @doc_list end
read_cfg(name,mode=:all)
click to toggle source
# File lib/dyndoc/document.rb, line 176 def read_cfg(name,mode=:all) # cfg_dyn is the options given inside the master template cfg_dyn=nil name_tmpl=Dyndoc.name_tmpl(name,mode) #Dyndoc.warn "read_cfg:name_tmpl",[name,name_tmpl] if name_tmpl name_tmpl2=Dyndoc.directory_tmpl? name_tmpl if name_tmpl2 # test if [#cfg] block exists inside _lib.dyn file lib_dyn_content=lib_dyn_content_from(name_tmpl2) tmp=cfg_dyn_from_lib(lib_dyn_content) if tmp[:cfg] #p :cfg_from_lib cfg_dyn=cfg_dyn_from_code(tmp[:cfg]) lib_dyn_content=tmp[:lib_dyn_content] else cfg_dyn=cfg_dyn_from(name_tmpl2) end cfg_dyn[:filename_tmpl]=name_tmpl2 cfg_dyn[:lib_dyn_content]=lib_dyn_content else cfg_dyn=Dyndoc::TexDoc end cfg_dyn[:filename_tmpl_orig] = name_tmpl end #Dyndoc.warn "read_cfg:cfg_dyn",cfg_dyn #otherwise it is the default version! append_cfg(cfg_dyn) if cfg_dyn #read the optional cfg read_cmdline end
read_cmdline()
click to toggle source
# File lib/dyndoc/document.rb, line 245 def read_cmdline ##p [:read_cmdline,Dyndoc.cfg_dyn] cfg_cmdline={} cfg_cmdline[:doc_list]=Dyndoc.cfg_dyn[:doc_list] unless Dyndoc.cfg_dyn[:doc_list].empty? cfg_cmdline[:cmd]=Dyndoc.cfg_dyn[:cmd_doc] unless Dyndoc.cfg_dyn[:cmd_doc].empty? cfg_cmdline[:model_doc]=Dyndoc.cfg_dyn[:model_doc] unless Dyndoc.cfg_dyn[:model_doc].empty? cfg_cmdline[:exec_mode]=Dyndoc.cfg_dyn[:exec_mode] if Dyndoc.cfg_dyn[:exec_mode] and !Dyndoc.cfg_dyn[:exec_mode].empty? cfg_cmdline[:tag_tmpl]=Dyndoc.cfg_dyn[:tag_tmpl] unless Dyndoc.cfg_dyn[:tag_tmpl].empty? cfg_cmdline[:options]=Dyndoc.cfg_dyn[:options] unless Dyndoc.cfg_dyn[:options].empty? ## select doc_list by reading "[#default]" useful in atom if !@cfg[:content] and Dyndoc.cfg_dyn[:doc_list].empty? and Dyndoc.cfg_dyn[:tag_tmpl].empty? if File.read(@cfg[:filename_tmpl]).force_encoding("utf-8") =~ /^\[\#default\]([^\[]*)\[\#/ cfg_cmdline[:doc_list]=$1.strip.split(",").map{|e| e.strip} puts "Default document: "+cfg_cmdline[:doc_list].join(",") end end append_cfg(cfg_cmdline) end