Module: Dyndoc

Defined in:
lib/dyndoc/common/dynArray.rb,
lib/dyndoc/common/uv.rb,
lib/dyndoc/init/home.rb,
lib/dyndoc/base/envir.rb,
lib/dyndoc/base/utils.rb,
lib/dyndoc/common/file.rb,
lib/dyndoc/init/config.rb,
lib/dyndoc/base/scanner.rb,
lib/dyndoc/common/utils.rb,
lib/dyndoc/base/tmpl/oop.rb,
lib/dyndoc/base/tmpl/eval.rb,
lib/dyndoc/base/filter/call.rb,
lib/dyndoc/base/helpers/core.rb,
lib/dyndoc/base/tmpl/manager.rb,
lib/dyndoc/base/tmpl/rbenvir.rb,
lib/dyndoc/base/filter/server.rb,
lib/dyndoc/base/tags/part_tag.rb,
lib/dyndoc/base/tags/tag_mngr.rb,
lib/dyndoc/base/tags/user_tag.rb,
lib/dyndoc/base/tmpl/parse_do.rb,
lib/dyndoc/base/helpers/parser.rb,
lib/dyndoc/base/tags/keys_mngr.rb,
lib/dyndoc/base/tmpl/extension.rb,
lib/dyndoc/plugins/tex/tex_eval.rb,
lib/dyndoc/base/filter/filter_mngr.rb,
lib/dyndoc/plugins/tex/tex_parse_do.rb,
lib/dyndoc/plugins/tex/tex_user_tag.rb

Overview

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

Defined Under Namespace

Modules: Ruby, Utils Classes: CallFilter, CallScanner, DevTagScanner, Envir, FilterManager, JLServer, KeysManager, PartTag, RServer, RbServer, RenderProcessor, Scanner, TagManager, UserTag, VarsScanner, Vector

Constant Summary collapse

CHARS_SET_FIRST =
[["_{_","__OPEN__"],["_}_","__CLOSE__"]]
CHARS_SET_LAST =
[["__OPEN__","{"],["__CLOSE__","}"]]
PROTECT_FORMAT_BLOCKTEXT =
"<protect-format-blocktext>"
FORMATS =
["Tex","Txtl","Txt","Tm","Ttm","Html"]
EXTS =
{:txt => ".txt",:rb => ".rb",:c=>".c",:html=>".html",:txtl=>".rhtml",:tm=>".tm",:tex=>".tex",:odt_content=>"_content.xml",:odt_styles=>"_styles.xml",:dyn=>".dynout",:ttm=>"_ttm.xml"}
PATH_SEP =
";"
VERB =
{:tex=>{
    :begin=>"\\begin{Verbatim}[frame=leftline,fontfamily=tt,fontshape=n,numbers=left]",
    :end=>"\\end{Verbatim}"
  },
	  		:ttm=>{
    :begin=>"\\begin{verbatim}",
    :end=>"\\end{verbatim}"
  },
  :txtl=>{
    :begin=>"<pre><code style=\"color:yellow;background-color:black\">",
    :end=>"</code></pre>"
  },
  :tm=>{
    :begin=>"<\\verbatim>__TM__",
    :end=>"__TM__</verbatim>"
  },
  :raw=>{
  	:begin=>"",
    	:end=>""
  }
}
AS_IS =

strange unmeaning term to protect in a filter.apply block!

'UnfltrdAsIsBlck'
@@dyn_root_path =

first declaration of the config directory

@@dyn_gem_path =
File.expand_path(File.join(__FILE__,[".."]*4))
@@cfg_dir =
{
  :root_path=> @@dyn_root_path,
  :gem_path=> @@dyn_gem_path,
  :log_file => File.join(@@dyn_root_path,".dyn_log"),
  :etc => File.join(@@dyn_root_path,"etc"),
  :tmpl_path=>{:tex=>"Tex",:odt=>"Odt",:ttm=>"Ttm",:html => "Html"},
  :model_default=>"Model",
  :file => "", #to complete when dyndoc applied to a file
  :current_doc_path => "" #completed each time a file is parsed in parse_do
}
@@dyn_logger =
nil
@@dyn_block =
{}
@@mode =

default mode and extension

:tex
@@tmplExt =
{:txt => ["_txt.dyn","_raw.dyn",".dyn_txt","_tmpl.txt",".dyn"], :rb =>["_rb.dyn",".dyn_rb","_tmpl.rb",".dyn"], :c=>["_c.dyn",".dyn_c","_tmpl.c",".dyn"], :html => ["_html.dyn",".dyn_html","_tmpl.html","_tmpl.rhtml",".dyn"],:txtl=>["_txtl.dyn",".dyn_txtl","_tmpl.txtl","_tmpl.rhtml",".dyn"],
:tm=>["_tm.dyn",".dyn_tm","_tmpl.tm",".dyn"],
:tex=>["_tex.dyn",".dyn_tex","_tmpl.tex",".dyn",".rtex"],
:odt=>[".dyn_odt_content","_tmpl_content.xml",".dyn_odt_styles","_tmpl_styles.xml",".dyn_odt","_tmpl.odt",".dyn"], #_tmpl.odt is an odt file with content body to extract!
:ttm=>["_ttm.dyn",".dyn_ttm","_tmpl.ttm",".dyn"],
:all=>[".dyn"]
}
@@docExt =
{:raw => "",:txt => ".txt",:rb => ".rb",:c=>".c",:html=>".html",:txtl=>".rhtml",:tm=>".tm",:tex=>".tex",:odt=>".odt",:ttm=>"_ttm.xml"}
@@dynExt =
[".dyn"]
@@append =

append or alias tricks ##########################

nil
@@tmpl_mngr =
nil
@@user_root_doc =
nil

Class Method Summary collapse

Class Method Details

.absolute_path(filename, pathenv) ⇒ Object

more useable than this !!!



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/dyndoc/init/config.rb', line 160

def Dyndoc.absolute_path(filename,pathenv)
#puts "ici";p filename
  return filename if File.exists? 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.exists? f)
    	name=f
    	break
    end
  }
#puts "->";p name
  name
end

.add_loggerObject



32
33
34
# File 'lib/dyndoc/init/config.rb', line 32

def Dyndoc.add_logger
  @@dyn_logger = Logger.new(@@cfg_dir[:log_file], 7, 1048576)
end

.appendVarObject



134
135
136
# File 'lib/dyndoc/init/config.rb', line 134

def Dyndoc.appendVar
  @@append
end

.cache(cache_ = {}) ⇒ Object

Make more readable the creation of newBlck



17
18
19
20
# 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_dirObject



24
25
26
# File 'lib/dyndoc/init/config.rb', line 24

def Dyndoc.cfg_dir
  @@cfg_dir
end

.cfg_dynObject



28
29
30
# File 'lib/dyndoc/init/config.rb', line 28

def Dyndoc.cfg_dyn
  Settings[:cfg_dyn]
end

.directory_tmpl?(name, exts = ) ⇒ Boolean

Returns:

  • (Boolean)


178
179
180
181
182
183
184
185
186
187
188
189
190
191
# 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

.doc_filename(filename, exts = , warn = true, pathenv = ".", rootDoc = nil) ⇒ Object

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



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# 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

.docExt(mode = @@mode) ⇒ Object



74
75
76
# File 'lib/dyndoc/init/config.rb', line 74

def Dyndoc.docExt(mode=@@mode)
  @@docExt[mode]
end

.dyn_blockObject



46
47
48
# File 'lib/dyndoc/init/config.rb', line 46

def Dyndoc.dyn_block
  @@dyn_block
end

.expand_path(filename) ⇒ Object

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



4
5
6
7
8
9
10
11
# 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) ⇒ Object



22
23
24
# 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) ⇒ Object



13
14
15
16
17
# 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.exists? File.join(before[0..l],subpath) while (l-=1)>=0
	return nil
end

.get_pathenv(rootDoc = nil, with_currentRoot = true) ⇒ Object

dynamically get pathenv!!!!



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# 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.exists? 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.exists? 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) ⇒ Object



114
115
116
117
118
119
# 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

.homeObject



2
3
4
5
6
7
8
# 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.exists? File.join(ENV['HOME'],'.dyndoc_home')
	dyndoc_home = File.expand_path(dyndoc_home)
	#puts "dyndoc_home: "+ dyndoc_home
	dyndoc_home
end

.home=(value) ⇒ Object



10
11
12
13
14
# 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_pathObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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.exists? 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_pathenvObject



195
196
197
198
199
200
201
202
203
204
# 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_rootDocObject



121
122
123
124
125
126
127
128
129
# 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) ⇒ Object



261
262
263
# File 'lib/dyndoc/init/config.rb', line 261

def Dyndoc.input_from_file(filename)
  return Dyndoc.read_content_file(Dyndoc.doc_filename(filename))
end

.loggerObject



36
37
38
# File 'lib/dyndoc/init/config.rb', line 36

def Dyndoc.logger
  @@dyn_logger
end

.logger_info(txt) ⇒ Object



40
41
42
# File 'lib/dyndoc/init/config.rb', line 40

def Dyndoc.logger_info(txt)
  @@dyn_logger.info(txt)
end

.make_appendObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# 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.exists? sys_append
  home_append=File.join(@@cfg_dir[:etc],'alias')
  tmp += File.readlines(home_append)  if File.exists? home_append
  file_append=File.join(@@cfg_dir[:file],'.dyn_alias')
  tmp += File.readlines(file_append)  if File.exists? 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) ⇒ Object



300
301
302
303
# File 'lib/dyndoc/init/config.rb', line 300

def Dyndoc.make_dir(dir)
  tmp=File.expand_path(dir)
  FileUtils.mkdir_p(tmp) unless File.exists? tmp
end

.modeObject



66
67
68
# File 'lib/dyndoc/init/config.rb', line 66

def Dyndoc.mode
  @@mode
end

.mode=(mode) ⇒ Object



70
71
72
# File 'lib/dyndoc/init/config.rb', line 70

def Dyndoc.mode=(mode)
  @@mode=mode
end

.name_tmpl(name, mode = :all) ⇒ Object

find the name of the template when mode is given



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# 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 exists?
  if File.exists? 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) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
# 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 = {}) ⇒ Object

the filename path has to be complete



266
267
268
269
270
271
272
273
274
275
276
277
# 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) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
# 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

.stdoutObject



3
4
5
6
7
# File 'lib/dyndoc/common/utils.rb', line 3

def Dyndoc.stdout
	old_stdout,$stdout=$stdout,STDOUT
	yield
	$stdout=old_stdout
end

.tmpl_mngrObject

need to point to the current TemplateManager



8
9
10
# File 'lib/dyndoc/base/tmpl/manager.rb', line 8

def Dyndoc.tmpl_mngr
  @@tmpl_mngr
end

.tmpl_mngr=(tmpl_mngr) ⇒ Object



12
13
14
# File 'lib/dyndoc/base/tmpl/manager.rb', line 12

def Dyndoc.tmpl_mngr=(tmpl_mngr)
  @@tmpl_mngr = tmpl_mngr
end

.tmplExtObject



78
79
80
# File 'lib/dyndoc/init/config.rb', line 78

def Dyndoc.tmplExt
  @@tmplExt
end

.user_root_docObject



20
21
22
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 20

def Dyndoc.user_root_doc
  @@user_root_doc
end

.user_root_doc=(user_root_doc) ⇒ Object



16
17
18
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 16

def Dyndoc.user_root_doc=(user_root_doc)
  @@user_root_doc=user_root_doc
end

.varsObject



10
11
12
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 10

def Dyndoc.vars
  @@vars
end

.vars=(vars) ⇒ Object



6
7
8
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 6

def Dyndoc.vars=(vars)
  @@vars=vars
end

.VecObject

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



80
81
82
# File 'lib/dyndoc/common/dynArray.rb', line 80

def Dyndoc.Vec 
	Dyndoc::Vector
end

.warn(*txt) ⇒ Object

1 component => puts, more components => puts + p + p + .…



9
10
11
12
13
14
15
16
17
18
# 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