module Dyndoc

The main difference between this kind of helpers and a simple file containing definition of functions is that these functions are executed in the Object module as a normal ruby function does.

TODO: .force_encoding(“utf-8”) needs to be added (see server.rb)

Dyndoc Array : ruby Array synchronized to Julia or R Vector

when change occurs from any language

Constants

AS_IS
CHARS_SET_FIRST
CHARS_SET_LAST
EXTS
FORMATS
PATH_SEP
PROTECT_FORMAT_BLOCKTEXT
VERB

Public Class Methods

Vec() click to toggle source

Just a fancy funcion to access Dyndoc::Vector in the way as Julia and R

# File lib/dyndoc/common/dynArray.rb, line 80
def Dyndoc.Vec 
        Dyndoc::Vector
end
absolute_path(filename,pathenv) click to toggle source

more useable than this !!!

# File lib/dyndoc/init/config.rb, line 160
  def Dyndoc.absolute_path(filename,pathenv)
#puts "ici";p filename
    return filename if File.exist? filename
    paths=pathenv##.split(":")
#puts "absolute_path:filname";p filename
    name=nil
    paths.each{|e|
      f=File.expand_path(File.join([e,filename]))
#p f
      if (File.exist? f)
        name=f
        break
      end
    }
#puts "->";p name
    name
  end
add_logger() click to toggle source
# File lib/dyndoc/init/config.rb, line 32
def Dyndoc.add_logger
  @@dyn_logger = Logger.new(@@cfg_dir[:log_file], 7, 1048576)
end
appendVar() click to toggle source
# File lib/dyndoc/init/config.rb, line 134
def Dyndoc.appendVar
  @@append
end
cache(cache_={}) click to toggle source

Make more readable the creation of newBlck

# File lib/dyndoc/base/tmpl/manager.rb, line 17
def Dyndoc.cache(cache_={})
  return Dyndoc.tmpl_mngr.vars[Dyndoc.tmpl_mngr.blckName[-1]] if cache_.empty?
  Dyndoc.tmpl_mngr.vars[Dyndoc.tmpl_mngr.blckName[-1]]=cache_
end
cfg_dir() click to toggle source
# File lib/dyndoc/init/config.rb, line 24
def Dyndoc.cfg_dir
  @@cfg_dir
end
cfg_dyn() click to toggle source
# File lib/dyndoc/init/config.rb, line 28
def Dyndoc.cfg_dyn
  Settings[:cfg_dyn]
end
directory_tmpl?(name,exts=@@tmplExt[@@mode]) click to toggle source
# File lib/dyndoc/init/config.rb, line 178
  def Dyndoc.directory_tmpl?(name,exts=@@tmplExt[@@mode])
    if name and File.directory? name
#puts "directory_tmpl?:name";p name;p exts
#p File.join(name,"index")
      resname=Dyndoc.doc_filename(File.join(name,"index"),exts,false)
      resname=Dyndoc.doc_filename(File.join(name,File.basename(name,".*")),exts,false) unless resname

##IMPORTANT: this file could not depend on the format_doc because it is related to the template and not the document!!!
      resname=Dyndoc.doc_filename(File.join(@@cfg_dir[:root_path],["root","Default","index"]),exts,false) unless resname
      name=resname
    end
#puts "directory_tmpl?:return resname";p resname;p name
    return name
  end
docExt(mode=@@mode) click to toggle source
# File lib/dyndoc/init/config.rb, line 74
def Dyndoc.docExt(mode=@@mode)
  @@docExt[mode]
end
doc_filename(filename,exts=@@tmplExt[@@mode],warn=true,pathenv=".",rootDoc=nil) click to toggle source

if exts is a Symbol then it is the new @@mode!

# File lib/dyndoc/init/config.rb, line 238
  def Dyndoc.doc_filename(filename,exts=@@tmplExt[@@mode],warn=true,pathenv=".",rootDoc=nil)
    rootDoc=Dyndoc.cfg_dyn[:root_doc] unless Dyndoc.cfg_dyn[:root_doc].empty?
    filename=filename.strip
    if exts.is_a? Symbol
      @@mode=exts
      exts=@@tmplExt[@@mode]
    end

    pathenv = Dyndoc.get_pathenv(rootDoc)
    exts = exts + @@tmplExt.values.flatten  #if @cfg[:output]
    exts << "" #with extension
#puts "before finding paths";p filename;p @@mode;p exts
    exts.uniq!
    names=exts.map{|ext| Dyndoc.absolute_path(filename+ext,pathenv)}.compact
    name=(names.length>0 ? names[0] : nil)
    if warn
      print "WARNING: #{filename}  with extension #{exts.join(',')} not reachable in:\n #{pathenv.join(Dyndoc::PATH_SEP)}\n" unless name
      #puts "tmpl:";p name
    end
    return name
  end
dyn_block() click to toggle source
# File lib/dyndoc/init/config.rb, line 46
def Dyndoc.dyn_block
  @@dyn_block
end
expand_path(filename) click to toggle source

allows to expand subpath of the form ‘lib/<dyndoc/tutu/toto’

# File lib/dyndoc/common/file.rb, line 4
def Dyndoc.expand_path(filename)
        filename=File.expand_path(filename).split(File::Separator)
        to_find=filename.each_with_index.map{|pa,i| i if pa =~ /^\<[^\<\>]*/}.compact
        return File.join(filename) if to_find.empty?
        to_find=to_find[0]
        path=Dyndoc.find_subpath_before(File.join(filename[to_find][1..-1],filename[(to_find+1)...-1]),filename[0...to_find])
        return path ? Dyndoc.expand_path(File.join(path+filename[-1,1])) : nil
end
extract_var(id) click to toggle source
# File lib/dyndoc/base/tmpl/manager.rb, line 22
def Dyndoc.extract_var(id)
  Dyndoc.tmpl_mngr.vars.extract(id)
end
find_subpath_before(subpath,before) click to toggle source
# File lib/dyndoc/common/file.rb, line 13
def Dyndoc.find_subpath_before(subpath,before)
        l=before.length+1
        return [before[0..l],subpath] if File.exist? File.join(before[0..l],subpath) while (l-=1)>=0
        return nil
end
get_pathenv(rootDoc=nil,with_currentRoot=true) click to toggle source

dynamically get pathenv!!!!

# File lib/dyndoc/init/config.rb, line 221
def Dyndoc.get_pathenv(rootDoc=nil,with_currentRoot=true)
  pathenv =  Dyndoc.init_pathenv
  pathenv += PATH_SEP + File.join(@@dyn_gem_path,"dyndoc") + PATH_SEP + File.join(@@dyn_gem_path,"dyndoc","Std") if File.exist? File.join(@@dyn_gem_path,"dyndoc")
  # high level of priority since provided by user
  pathenv += PATH_SEP + Dyndoc.user_root_doc  if Dyndoc.user_root_doc
  pathenv += PATH_SEP + ENV["DYNDOC_LIBRARY_PATH"] if ENV["DYNDOC_LIBRARY_PATH"] and !ENV["DYNDOC_LIBRARY_PATH"].empty?
  pathenv += PATH_SEP + File.join(Dyndoc.cfg_dir[:root_path],"library") if File.exist? File.join(@@cfg_dir[:root_path],"library")
  pathenv += PATH_SEP + @@cfg_dir[:current_doc_path] if with_currentRoot and !@@cfg_dir[:current_doc_path].empty?
  pathenv += PATH_SEP + rootDoc  if rootDoc and !rootDoc.empty?
  pathenv += PATH_SEP + Dyndoc.cfg_dyn[:root_doc]  unless Dyndoc.cfg_dyn[:root_doc].empty?
  pathenv += PATH_SEP + ENV["TEXINPUTS"].split(RUBY_PLATFORM =~ /mingw/ ? ";" : ":" ).join(";") if ENV["TEXINPUTS"] and @@mode==:tex

  ##Dyndoc.warn "pathenv",pathenv
  return Dyndoc.ordered_pathenv(pathenv)
end
guess_mode(filename) click to toggle source
# File lib/dyndoc/init/config.rb, line 114
def Dyndoc.guess_mode(filename)
  @@tmplExt.keys.map{|k| k.to_s}.sort.each do |ext|
    return ext.to_sym if filename =~ /(#{@@tmplExt[ext.to_sym].join("|")})$/
  end
  return nil
end
home() click to toggle source
# File lib/dyndoc/init/home.rb, line 2
def Dyndoc.home
        dyndoc_home = File.join(ENV['HOME'],'dyndoc')
        dyndoc_home =  File.read(File.join(ENV['HOME'],'.dyndoc_home')).strip if File.exist? File.join(ENV['HOME'],'.dyndoc_home')
        dyndoc_home = File.expand_path(dyndoc_home)
        #puts "dyndoc_home: "+ dyndoc_home
        dyndoc_home
end
home=(value) click to toggle source
# File lib/dyndoc/init/home.rb, line 10
def Dyndoc.home=(value)
        File.open(File.join(ENV['HOME'],'.dyndoc_home'),"w") do |f|
                f << value.strip
        end
end
init_dyndoc_library_path() click to toggle source
# File lib/dyndoc/init/config.rb, line 83
def Dyndoc.init_dyndoc_library_path

  [File.join(FileUtils.pwd,".dyndoc_library_path"),File.join(FileUtils.pwd,"dyndoc_library_path.txt"),File.join(@@cfg_dir[:etc],"dyndoc_library_path")].each do |dyndoc_library_path|
    if File.exist? dyndoc_library_path
      path=File.read(dyndoc_library_path).strip
      path=path.split(Dyndoc::PATH_SEP).map{|pa| File.expand_path(pa)}.join(Dyndoc::PATH_SEP)
      if !ENV["DYNDOC_LIBRARY_PATH"] or ENV["DYNDOC_LIBRARY_PATH"].empty?
        ENV["DYNDOC_LIBRARY_PATH"]= path
      else
        ENV["DYNDOC_LIBRARY_PATH"] += Dyndoc::PATH_SEP + path
      end
    end

  end

end
init_pathenv() click to toggle source
# File lib/dyndoc/init/config.rb, line 195
def Dyndoc.init_pathenv
  #p Dyndoc.cfg_dyn
    if Dyndoc.cfg_dyn[:dyndoc_mode]==:normal #normal mode
       pathenv="."
    else #client server mode
      #puts "working directory";p Dyndoc.cfg_dyn[:working_dir]
      pathenv = Dyndoc.cfg_dyn[:working_dir] + PATH_SEP + "."
    end
    return pathenv
end
init_rootDoc() click to toggle source
# File lib/dyndoc/init/config.rb, line 121
def Dyndoc.init_rootDoc
  rootDoc=""
  if File.directory?(path=File.join(@@cfg_dir[:etc],Dyndoc.cfg_dyn['etc_path_subdir']))
    Dir[File.join(path,"*")].sort.each do |pa|
      rootDoc += (rootDoc.empty? ? "" : ":") + File.read(pa).chomp
    end
  end
  Dyndoc.cfg_dyn['root_doc']=rootDoc
end
input_from_file(filename) click to toggle source
# File lib/dyndoc/init/config.rb, line 261
def Dyndoc.input_from_file(filename)
  return Dyndoc.read_content_file(Dyndoc.doc_filename(filename))
end
logger() click to toggle source
# File lib/dyndoc/init/config.rb, line 36
def Dyndoc.logger
  @@dyn_logger
end
logger_info(txt) click to toggle source
# File lib/dyndoc/init/config.rb, line 40
def Dyndoc.logger_info(txt)
  @@dyn_logger.info(txt)
end
make_append() click to toggle source
# File lib/dyndoc/init/config.rb, line 138
def Dyndoc.make_append
  ## global aliases
  @@append={}
  tmp=[]
  sys_append=File.join( @@cfg_dir[:etc],"alias")
  tmp += File.readlines(sys_append) if File.exist? sys_append
  home_append=File.join(@@cfg_dir[:etc],'alias')
  tmp += File.readlines(home_append)  if File.exist? home_append
  file_append=File.join(@@cfg_dir[:file],'.dyn_alias')
  tmp += File.readlines(file_append)  if File.exist? file_append
  tmp.map{|l|
    if l.include? ">"
      l2=l.strip
      unless l2.empty?
        l2=l2.split(/[=>,]/).map{|e| e.strip}
        @@append[l2[0]]=l2[-1]
      end
    end
  }
end
make_dir(dir) click to toggle source
# File lib/dyndoc/init/config.rb, line 300
def Dyndoc.make_dir(dir)
  tmp=File.expand_path(dir)
  FileUtils.mkdir_p(tmp) unless File.exist? tmp
end
mode() click to toggle source
# File lib/dyndoc/init/config.rb, line 66
def Dyndoc.mode
  @@mode
end
mode=(mode) click to toggle source
# File lib/dyndoc/init/config.rb, line 70
def Dyndoc.mode=(mode)
  @@mode=mode
end
name_tmpl(name,mode=:all) click to toggle source

find the name of the template when mode is given

# File lib/dyndoc/init/config.rb, line 280
  def Dyndoc.name_tmpl(name,mode=:all)
    #clean dtag
    dtags=[:dtag] #update if necessary
    dtag=name.scan(/(?:#{dtags.map{|e| "_#{e}_" }.join("|")})/)[0]
    if dtag
      name=name.gsub(/(?:#{dtags.map{|e| "_#{e}_" }.join("|")})/,"")
    end
#puts "name";p name
    #file exist?
    if File.exist? name
      return name
    elsif name.scan(/([^\.]*)(#{@@tmplExt.map{|e| e[1]}.flatten.uniq.map{|e| Regexp.escape(e)}.join("|")})+$/)[0]
      pathenv=Dyndoc.get_pathenv(Dyndoc.cfg_dyn[:root_doc],false) #RMK: do not know if false really matters here (introduced just in case in get_pathenv!!!)
#puts "pathenv";p pathenv; p Dyndoc.absolute_path(name,pathenv)
      return Dyndoc.absolute_path(name,pathenv)
    else
      return Dyndoc.doc_filename(name,@@tmplExt[mode],true)
    end
  end
ordered_pathenv(pathenv) click to toggle source
# File lib/dyndoc/init/config.rb, line 207
def Dyndoc.ordered_pathenv(pathenv)
  path_ary=[]
  pathenv.split(PATH_SEP).each{|e|
    if e=~/(?:\((\-?\d*)\))(.*)/
      path_ary.insert($1.to_i-1,$2.strip)
    else
      path_ary << e.strip
    end
  }
  #puts "path_ary";p path_ary
  path_ary.compact.uniq #.join(":")
end
read_content_file(filename,aux={}) click to toggle source

the filename path has to be complete

# File lib/dyndoc/init/config.rb, line 266
  def Dyndoc.read_content_file(filename,aux={})
#p filename
    case File.extname(filename)
    when ".odt"
      odt=Dyndoc::Odt.new(filename)
      aux[:doc].inputs={} unless aux[:doc].inputs
      aux[:doc].inputs[filename]= odt unless aux[:doc].inputs[filename]
      odt.body_from_content
    else
      File.read(filename)
    end
  end
setRootDoc(rootDoc,root,before=true) click to toggle source
# File lib/dyndoc/init/config.rb, line 100
def Dyndoc.setRootDoc(rootDoc,root,before=true)
  if rootDoc
    if before
      rootDoc2 = "#{root}:"+rootDoc
   else
      rootDoc2 = rootDoc+":#{root}"
    end
  else
    rootDoc2=root
  end
  #insure unique path and adress of rootDoc is unchanged!
  rootDoc.replace(rootDoc2.split(":").uniq.join(":")) if rootDoc2
end
stdout() { || ... } click to toggle source
# File lib/dyndoc/common/utils.rb, line 3
def Dyndoc.stdout
        old_stdout,$stdout=$stdout,STDOUT
        yield
        $stdout=old_stdout
end
tmplExt() click to toggle source
# File lib/dyndoc/init/config.rb, line 78
def Dyndoc.tmplExt
  @@tmplExt
end
tmpl_mngr() click to toggle source

need to point to the current TemplateManager

# File lib/dyndoc/base/tmpl/manager.rb, line 8
def Dyndoc.tmpl_mngr
  @@tmpl_mngr
end
tmpl_mngr=(tmpl_mngr) click to toggle source
# File lib/dyndoc/base/tmpl/manager.rb, line 12
def Dyndoc.tmpl_mngr=(tmpl_mngr)
  @@tmpl_mngr = tmpl_mngr
end
user_root_doc() click to toggle source
# File lib/dyndoc/base/tmpl/parse_do.rb, line 22
def Dyndoc.user_root_doc
  @@user_root_doc
end
user_root_doc=(user_root_doc) click to toggle source
# File lib/dyndoc/base/tmpl/parse_do.rb, line 18
def Dyndoc.user_root_doc=(user_root_doc)
  @@user_root_doc=user_root_doc
end
vars() click to toggle source
# File lib/dyndoc/base/tmpl/parse_do.rb, line 12
def Dyndoc.vars
  @@vars
end
vars=(vars) click to toggle source
# File lib/dyndoc/base/tmpl/parse_do.rb, line 8
def Dyndoc.vars=(vars)
  @@vars=vars
end
warn(*txt) click to toggle source
# File lib/dyndoc/common/utils.rb, line 9
def Dyndoc.warn(*txt) # 1 component => puts, more components => puts + p + p + ....
        Dyndoc.stdout  do
                if txt.length==1
                        puts txt[0]
                else
                        puts txt[0]
                        txt[1..-1].each do |e| p e end
                end
        end
end