dyndoc-ruby-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/dyndoc/.DS_Store +0 -0
- data/dyndoc/Dyn/.postload +1 -0
- data/dyndoc/Dyn/.preload +1 -0
- data/dyndoc/Dyn/After.dyn +3 -0
- data/dyndoc/Dyn/Base.dyn +18 -0
- data/dyndoc/Dyn/Minimum.dyn +20 -0
- data/dyndoc/Model/Html/DefaultPost_html.dyn +5 -0
- data/dyndoc/Model/Html/DefaultPre_html.dyn +15 -0
- data/dyndoc/Model/Odt/DefaultPost_content.xml +3 -0
- data/dyndoc/Model/Odt/DefaultPost_tmpl_content.xml +3 -0
- data/dyndoc/Model/Odt/DefaultPre_content.xml +8 -0
- data/dyndoc/Model/Odt/DefaultPre_tmpl_content.xml +8 -0
- data/dyndoc/Model/Tex/ContentPost_tmpl.tex +1 -0
- data/dyndoc/Model/Tex/ContentPre_tmpl.tex +6 -0
- data/dyndoc/Model/Tex/DefaultPost_tmpl.tex +73 -0
- data/dyndoc/Model/Tex/DefaultPre_tmpl.tex +16 -0
- data/dyndoc/Model/Ttm/DefaultPost_tmpl.ttm +3 -0
- data/dyndoc/Model/Ttm/DefaultPre_tmpl.ttm +16 -0
- data/dyndoc/Std/Array.dyn +96 -0
- data/dyndoc/Std/Composer.dyn +38 -0
- data/dyndoc/Std/DevTag.dyn +101 -0
- data/dyndoc/Std/DynVar.dyn +23 -0
- data/dyndoc/Std/File.dyn +55 -0
- data/dyndoc/Std/Git.dyn +34 -0
- data/dyndoc/Std/List.dyn +46 -0
- data/dyndoc/Std/OOP.dyn +32 -0
- data/dyndoc/Std/Signal.dyn +18 -0
- data/dyndoc/Std/String.dyn +22 -0
- data/dyndoc/Std/Styles.dyn +1 -0
- data/dyndoc/Std/Test.dyn +282 -0
- data/dyndoc/Std/Utils.dyn +42 -0
- data/dyndoc/Std/Verb.dyn +5 -0
- data/dyndoc/Style/Notation/Math.dyn +7 -0
- data/dyndoc/Style/Notation/Stat/Classic.dyn +8 -0
- data/dyndoc/Style/Notation/Stat/Cqls.dyn +44 -0
- data/dyndoc/Style/Text/Std.dyn +5 -0
- data/dyndoc/Style/Text/StdAlias.dyn +3 -0
- data/dyndoc/Style/Text/StdTex.dyn +17 -0
- data/dyndoc/Style/Text/Txt.dyn +1 -0
- data/dyndoc/Tex/.postload +1 -0
- data/dyndoc/Tex/.preload +1 -0
- data/dyndoc/Tex/10pt_tmpl.tex +1 -0
- data/dyndoc/Tex/11pt_tmpl.tex +1 -0
- data/dyndoc/Tex/12pt_tmpl.tex +1 -0
- data/dyndoc/Tex/Article_tmpl.tex +1 -0
- data/dyndoc/Tex/Beamer.dyn_tex +35 -0
- data/dyndoc/Tex/BeamerHandout_tmpl.tex +2 -0
- data/dyndoc/Tex/Book_tmpl.tex +1 -0
- data/dyndoc/Tex/DefaultFirst_tmpl.tex +1 -0
- data/dyndoc/Tex/DefaultLast_tmpl.tex +8 -0
- data/dyndoc/Tex/Default_tmpl.tex +9 -0
- data/dyndoc/Tex/First_tmpl.tex +8 -0
- data/dyndoc/Tex/Fr_tmpl.tex +17 -0
- data/dyndoc/Tex/Header_tmpl.tex +3 -0
- data/dyndoc/Tex/InclGraph_tmpl.tex +19 -0
- data/dyndoc/Tex/InclSpatProc_tmpl.tex +70 -0
- data/dyndoc/Tex/InclSumMI_tmpl.tex +4 -0
- data/dyndoc/Tex/LargeA4_tmpl.tex +5 -0
- data/dyndoc/Tex/Last_tmpl.tex +1 -0
- data/dyndoc/Tex/Option_tmpl.tex +8 -0
- data/dyndoc/Tex/Png_tmpl.tex +1 -0
- data/dyndoc/Tex/RefCite2_tmpl.tex +16 -0
- data/dyndoc/Tex/RefCite_tmpl.tex +16 -0
- data/dyndoc/Tex/Report_tmpl.tex +1 -0
- data/dyndoc/Tex/Theorem_tmpl.tex +14 -0
- data/dyndoc/Tools/.DS_Store +0 -0
- data/dyndoc/Tools/Atom.dyn/index.dyn +42 -0
- data/dyndoc/Tools/AtomDyndocker.dyn/index.dyn +43 -0
- data/dyndoc/Tools/R/Fig.dyn +144 -0
- data/dyndoc/Tools/R/Tools.dyn +344 -0
- data/dyndoc/Tools/Tex/Beamer.dyn +204 -0
- data/dyndoc/Tools/Tex/BeamerSlide.dyn_tex +199 -0
- data/dyndoc/Tools/Tex/Pgf.dyn +115 -0
- data/dyndoc/Tools/Tex/Table.dyn +278 -0
- data/dyndoc/Tools/Tex/Tools.dyn +37 -0
- data/dyndoc/Tools/Tex/Verb.dyn +77 -0
- data/dyndoc/Tools/Web/.DS_Store +0 -0
- data/dyndoc/Tools/Web/Ace.dyn +54 -0
- data/dyndoc/Tools/Web/Code.dyn +129 -0
- data/dyndoc/Tools/Web/DHtmlX.dyn +39 -0
- data/dyndoc/Tools/Web/DataTable.dyn_html +354 -0
- data/dyndoc/Tools/Web/Html.dyn +286 -0
- data/dyndoc/Tools/Web/Html/JQuery.dyn +123 -0
- data/dyndoc/Tools/Web/Html/Styles.dyn +4 -0
- data/dyndoc/Tools/Web/JQueryTools.dyn +87 -0
- data/dyndoc/Tools/Web/Layout.dyn +86 -0
- data/dyndoc/Tools/Web/Layout/CQLS.dyn +6 -0
- data/dyndoc/Tools/Web/Layout/LJK.dyn +41 -0
- data/dyndoc/Tools/Web/TabBar.dyn +37 -0
- data/dyndoc/Tools/Web/Ttm.dyn +20 -0
- data/dyndoc/Tools/Web/Txtl.dyn +14 -0
- data/lib/dyndoc-core.rb +59 -0
- data/lib/dyndoc/base/envir.rb +541 -0
- data/lib/dyndoc/base/filter/call.rb +127 -0
- data/lib/dyndoc/base/filter/filter_mngr.rb +637 -0
- data/lib/dyndoc/base/filter/server.rb +882 -0
- data/lib/dyndoc/base/filters.rb +3 -0
- data/lib/dyndoc/base/helpers.rb +9 -0
- data/lib/dyndoc/base/helpers/core.rb +32 -0
- data/lib/dyndoc/base/helpers/parser.rb +188 -0
- data/lib/dyndoc/base/scanner.rb +886 -0
- data/lib/dyndoc/base/tags.rb +4 -0
- data/lib/dyndoc/base/tags/keys_mngr.rb +401 -0
- data/lib/dyndoc/base/tags/part_tag.rb +194 -0
- data/lib/dyndoc/base/tags/tag_mngr.rb +125 -0
- data/lib/dyndoc/base/tags/user_tag.rb +216 -0
- data/lib/dyndoc/base/tmpl.rb +6 -0
- data/lib/dyndoc/base/tmpl/eval.rb +581 -0
- data/lib/dyndoc/base/tmpl/extension.rb +337 -0
- data/lib/dyndoc/base/tmpl/manager.rb +450 -0
- data/lib/dyndoc/base/tmpl/oop.rb +57 -0
- data/lib/dyndoc/base/tmpl/parse_do.rb +2446 -0
- data/lib/dyndoc/base/tmpl/rbenvir.rb +54 -0
- data/lib/dyndoc/base/utils.rb +367 -0
- data/lib/dyndoc/common/dynArray.rb +234 -0
- data/lib/dyndoc/common/file.rb +52 -0
- data/lib/dyndoc/common/init.rb +2 -0
- data/lib/dyndoc/common/tilt.rb +149 -0
- data/lib/dyndoc/common/utils.rb +61 -0
- data/lib/dyndoc/common/uv.rb +163 -0
- data/lib/dyndoc/init/config.rb +296 -0
- data/lib/dyndoc/init/home.rb +9 -0
- data/lib/dyndoc/plugins/tex.rb +4 -0
- data/lib/dyndoc/plugins/tex/beamer.rb +208 -0
- data/lib/dyndoc/plugins/tex/tex_eval.rb +69 -0
- data/lib/dyndoc/plugins/tex/tex_parse_do.rb +25 -0
- data/lib/dyndoc/plugins/tex/tex_user_tag.rb +32 -0
- data/share/R/dyndocMsys2.R +5 -0
- data/share/R/dyndocTools.R +9 -0
- data/share/R/test.R +14 -0
- data/share/R/tools/dynArray.R +34 -0
- data/share/R/tools/dynCapture.R +84 -0
- data/share/R/tools/dynMsys2.R +54 -0
- data/share/julia/dynArray.jl +93 -0
- data/share/julia/dyndoc.jl +110 -0
- data/share/julia/ruby.jl +37 -0
- metadata +202 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Dyndoc
|
|
2
|
+
|
|
3
|
+
# allows to expand subpath of the form 'lib/<dyndoc/tutu/toto'
|
|
4
|
+
def Dyndoc.expand_path(filename)
|
|
5
|
+
filename=File.expand_path(filename).split(File::Separator)
|
|
6
|
+
to_find=filename.each_with_index.map{|pa,i| i if pa =~ /^\<[^\<\>]*/}.compact
|
|
7
|
+
return File.join(filename) if to_find.empty?
|
|
8
|
+
to_find=to_find[0]
|
|
9
|
+
path=Dyndoc.find_subpath_before(File.join(filename[to_find][1..-1],filename[(to_find+1)...-1]),filename[0...to_find])
|
|
10
|
+
return path ? Dyndoc.expand_path(File.join(path+filename[-1,1])) : nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def Dyndoc.find_subpath_before(subpath,before)
|
|
14
|
+
l=before.length+1
|
|
15
|
+
return [before[0..l],subpath] if File.exists? File.join(before[0..l],subpath) while (l-=1)>=0
|
|
16
|
+
return nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
## inspired from http://stackoverflow.com/questions/21511347/how-to-create-a-symlink-on-windows-via-ruby
|
|
22
|
+
require 'open3'
|
|
23
|
+
|
|
24
|
+
class << File
|
|
25
|
+
alias_method :old_symlink, :symlink
|
|
26
|
+
alias_method :old_symlink?, :symlink?
|
|
27
|
+
|
|
28
|
+
def symlink(target_name, link_name)
|
|
29
|
+
#if on windows, call mklink, else self.symlink
|
|
30
|
+
if RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/
|
|
31
|
+
#windows mklink syntax is reverse of unix ln -s
|
|
32
|
+
#windows mklink is built into cmd.exe
|
|
33
|
+
#vulnerable to command injection, but okay because this is a hack to make a cli tool work.
|
|
34
|
+
opt = (File.directory? target_name) ? "/D" : ""
|
|
35
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3('cmd.exe', "/c mklink " + opt + "#{link_name} #{target_name}")
|
|
36
|
+
wait_thr.value.exitstatus
|
|
37
|
+
else
|
|
38
|
+
self.old_symlink(target_name, link_name)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def symlink?(file_name)
|
|
43
|
+
#if on windows, call mklink, else self.symlink
|
|
44
|
+
if RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/
|
|
45
|
+
#vulnerable to command injection because calling with cmd.exe with /c?
|
|
46
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("cmd.exe /c dir #{file_name} | find \"SYMLINK\"")
|
|
47
|
+
wait_thr.value.exitstatus
|
|
48
|
+
else
|
|
49
|
+
self.old_symlink?(file_name)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
require 'tilt' #this allows the use of any other template
|
|
2
|
+
require 'tilt/template' #for creating the dyndoc one
|
|
3
|
+
require 'redcloth'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
module Tilt
|
|
7
|
+
|
|
8
|
+
class DynDocTemplate < Template
|
|
9
|
+
|
|
10
|
+
def DynDocTemplate.init(libs=nil)
|
|
11
|
+
unless $curDyn
|
|
12
|
+
require 'dyndoc/V3/init/dyn'
|
|
13
|
+
CqlsDoc.init_dyn
|
|
14
|
+
CqlsDoc.set_curDyn(:V3)
|
|
15
|
+
$curDyn.init(false)
|
|
16
|
+
$curDyn.tmpl_doc.init_doc
|
|
17
|
+
if libs
|
|
18
|
+
@@libs=libs
|
|
19
|
+
$curDyn.tmpl_doc.require_dyndoc_libs(libs)
|
|
20
|
+
end
|
|
21
|
+
"options(bitmapType='cairo')".to_R
|
|
22
|
+
$curDyn.tmpl.format_output="html"
|
|
23
|
+
$curDyn.tmpl.dyndoc_mode=:web # No command line
|
|
24
|
+
#p [$curDyn.tmpl.dyndocMode,$curDyn.tmpl.fmtOutput]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# def init_dyndoc
|
|
29
|
+
# unless @tmpl_mngr
|
|
30
|
+
# Dyndoc.cfg_dyn['dyndoc_session']=:interactive
|
|
31
|
+
# @tmpl_mngr = Dyndoc::Ruby::TemplateManager.new({})
|
|
32
|
+
# ##is it really well-suited for interactive mode???
|
|
33
|
+
# @tmpl_mngr.init_doc({:format_output=> "html"})
|
|
34
|
+
# puts "InteractiveServer initialized!\n"
|
|
35
|
+
# end
|
|
36
|
+
# end
|
|
37
|
+
|
|
38
|
+
def self.engine_initialized?
|
|
39
|
+
defined? ::DynDoc
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def initialize_engine
|
|
43
|
+
DynDocTemplate.init
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def prepare; end
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def prepare_output
|
|
50
|
+
return $curDyn.tmpl_doc.make_content(data)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def evaluate(scope, locals, &block)
|
|
54
|
+
|
|
55
|
+
#=begin
|
|
56
|
+
#puts "locals";p locals
|
|
57
|
+
## first!!!!
|
|
58
|
+
if locals.keys.include? :init_doc and locals[:init_doc]
|
|
59
|
+
$curDyn.tmpl_doc.init_doc
|
|
60
|
+
$curDyn.tmpl_doc.require_dyndoc_libs(@@libs) if @@libs
|
|
61
|
+
"options(bitmapType='cairo')".to_R
|
|
62
|
+
$curDyn.tmpl.format_output="html"
|
|
63
|
+
$curDyn.tmpl.dyndoc_mode=:web # No command line
|
|
64
|
+
#p [$curDyn.tmpl.dyndocMode,$curDyn.tmpl.fmtOutput]
|
|
65
|
+
locals.delete :init_doc
|
|
66
|
+
end
|
|
67
|
+
locals.each do |tag, value|
|
|
68
|
+
if tag==:path
|
|
69
|
+
CqlsDoc.setRootDoc($curDyn[:rootDoc],value)
|
|
70
|
+
elsif tag==:libs
|
|
71
|
+
@@libs=libs
|
|
72
|
+
else
|
|
73
|
+
$curDyn.tmpl.filterGlobal.envir[tag]=value
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
#=end
|
|
77
|
+
$curDyn.tmpl.filterGlobal.envir["yield"]=block.call if block
|
|
78
|
+
@output=prepare_output
|
|
79
|
+
#puts @output
|
|
80
|
+
#@output
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
class DynTtmTemplate < DynDocTemplate
|
|
86
|
+
|
|
87
|
+
def self.engine_initialized?
|
|
88
|
+
defined? ::DynTtm
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def prepare_output
|
|
92
|
+
=begin
|
|
93
|
+
ttm_preamble = <<-PREAMBLE
|
|
94
|
+
\def\hyperlink#1#2{\special{html:<a href="\##1">}#2\special{html:</a>}}
|
|
95
|
+
% Incorrect link name in \TeX\ because # can't be passed properly to a special.
|
|
96
|
+
\def\hypertarget#1#2{\special{html:<a name="#1">}#2\special{html:</a>}}
|
|
97
|
+
\long\def\ttmdump#1{#1} % Do nothing. The following are not done for TtM.
|
|
98
|
+
\ttmdump{%
|
|
99
|
+
\def\title#1{\bgroup\leftskip 0 pt plus1fill \rightskip 0 pt plus1fill
|
|
100
|
+
\pretolerance=100000 \lefthyphenmin=20 \righthyphenmin=20
|
|
101
|
+
\noindent #1 \par\egroup}% Centers a possibly multi-line title.
|
|
102
|
+
\let\author=\title % Actually smaller font than title in \LaTeX.
|
|
103
|
+
\input epsf % PD package defines \epsfbox for figure inclusion
|
|
104
|
+
% Macro for http reference inclusion, per hypertex.
|
|
105
|
+
\def\href#1#2{\special{html:<a href="#1">}#2\special{html:</a>}}
|
|
106
|
+
\def\urlend#1{#1\endgroup}
|
|
107
|
+
\def\url{\begingroup \tt
|
|
108
|
+
\catcode`\_=13 % Don't know why this works.
|
|
109
|
+
\catcode`\~=11 \catcode`\#=11 \catcode`\^=11
|
|
110
|
+
\catcode`\$=11 \catcode`\&=11 \catcode`\%=11
|
|
111
|
+
\urlend}% \url for plain \TeX.
|
|
112
|
+
PREAMBLE
|
|
113
|
+
=end
|
|
114
|
+
CqlsDoc::Converter.ttm($curDyn.tmpl_doc.make_content(data),"-e2 -r -y1 -L").gsub(/<mtable[^>]*>/,"<mtable>").gsub("\\ngtr","<mtext>≯</mtext>").gsub("\\nless","<mtext>≮</mtext>").gsub("è","<mtext>è</mtext>")
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class DynTxtlTemplate < DynDocTemplate
|
|
121
|
+
|
|
122
|
+
def self.engine_initialized?
|
|
123
|
+
defined? ::DynTxtl
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def prepare_output
|
|
127
|
+
RedCloth.new($curDyn.tmpl_doc.make_content(data)).to_html
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
class DynHtmlTemplate < DynDocTemplate
|
|
133
|
+
|
|
134
|
+
def self.engine_initialized?
|
|
135
|
+
defined? ::DynHtml
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
## register them!
|
|
145
|
+
Tilt.register Tilt::DynTxtlTemplate, '_txtl.dyn'
|
|
146
|
+
Tilt.register Tilt::DynTtmTemplate, '_ttm.dyn'
|
|
147
|
+
Tilt.register Tilt::DynHtmlTemplate, '_html.dyn'
|
|
148
|
+
Tilt.register Tilt::DynDocTemplate, '.dyn'
|
|
149
|
+
#puts "dyn registered in tilt!"
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module Dyndoc
|
|
2
|
+
|
|
3
|
+
def Dyndoc.stdout
|
|
4
|
+
old_stdout,$stdout=$stdout,STDOUT
|
|
5
|
+
yield
|
|
6
|
+
$stdout=old_stdout
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def Dyndoc.warn(*txt) # 1 component => puts, more components => puts + p + p + ....
|
|
10
|
+
Dyndoc.stdout do
|
|
11
|
+
if txt.length==1
|
|
12
|
+
puts txt[0]
|
|
13
|
+
else
|
|
14
|
+
puts txt[0]
|
|
15
|
+
txt[1..-1].each do |e| p e end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module Utils
|
|
21
|
+
def Utils.cfg_file_exists?(tmpl)
|
|
22
|
+
name=File.join(File.dirname(tmpl),File.basename(tmpl,".*"))
|
|
23
|
+
([".cfg_dyn",".dyn_cfg"].map{|ext| name+ext}.select{|f| File.exists? f})[0]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def Utils.lib_file_exists?(tmpl)
|
|
27
|
+
name=File.join(File.dirname(tmpl),File.basename(tmpl,".*"))
|
|
28
|
+
(["_lib.dyn",".dyn_lib"].map{|ext| name+ext}.select{|f| File.exists? f})[0]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def Utils.out_rsrc_exists?(tmpl)
|
|
32
|
+
name=File.join(File.dirname(tmpl),File.basename(tmpl,".*"))
|
|
33
|
+
## if not a directory it is the zipped version! TODO!
|
|
34
|
+
([".dyn_out",".dyn_rsrc"].map{|ext| name+ext}.select{|f| File.exists? f})[0]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def Utils.mkdir_out_rsrc(tmpl)
|
|
38
|
+
require 'fileutils'
|
|
39
|
+
#p File.join(File.dirname(tmpl),File.basename(tmpl,".*")+".dyn_out")
|
|
40
|
+
FileUtils.mkdir_p File.join(File.dirname(tmpl),File.basename(tmpl,".*")+".dyn_out")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def Utils.dyndoc_globvar(key,value=nil)
|
|
46
|
+
if value
|
|
47
|
+
if [:remove,:rm,:del,:delete].include? value
|
|
48
|
+
Dyndoc.tmpl_mngr.filterGlobal.envir.remove(key)
|
|
49
|
+
else
|
|
50
|
+
Dyndoc.tmpl_mngr.filterGlobal.envir[key]= value
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
Dyndoc.tmpl_mngr.filterGlobal.envir[key]
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def Utils.is_windows?
|
|
58
|
+
RUBY_PLATFORM =~ /(win|msys|mingw)/
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
require 'uv'
|
|
2
|
+
require 'textpow'
|
|
3
|
+
|
|
4
|
+
## fix Textpow::ScoreManager::START_VALUE class supposed to be a Bignum
|
|
5
|
+
unless Textpow::ScoreManager::START_VALUE.is_a? Bignum
|
|
6
|
+
require 'bigdecimal'
|
|
7
|
+
Textpow::ScoreManager.send(:remove_const,:START_VALUE)
|
|
8
|
+
Textpow::ScoreManager.const_set(:START_VALUE,(BigDecimal("2") ** ( Textpow::ScoreManager::POINT_DEPTH * Textpow::ScoreManager::NESTING_DEPTH )).to_i)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module Uv
|
|
12
|
+
|
|
13
|
+
self.syntax_path=File.join(Dyndoc.cfg_dir[:etc],"uv","syntax")
|
|
14
|
+
self.render_path=File.join(Dyndoc.cfg_dir[:etc],"uv","render")
|
|
15
|
+
|
|
16
|
+
def self.parse(text, output = "xhtml", syntax_name = nil, line_numbers = false, render_style = nil, headers = false)
|
|
17
|
+
Dyndoc::RenderProcessor.load(output, render_style, line_numbers, headers) do |processor|
|
|
18
|
+
syntax_node_for(syntax_name).parse(text, processor)
|
|
19
|
+
end.string
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
module Dyndoc
|
|
25
|
+
|
|
26
|
+
class RenderProcessor
|
|
27
|
+
@@score_manager = Textpow::ScoreManager.new
|
|
28
|
+
|
|
29
|
+
attr_reader :string
|
|
30
|
+
attr_accessor :escapeHTML
|
|
31
|
+
|
|
32
|
+
def self.load(output, style = nil, line_numbers = false, headers = false)
|
|
33
|
+
style ||= Uv.default_style
|
|
34
|
+
renderer = File.join( Uv.render_path, output,"#{style}.render")
|
|
35
|
+
raise( ArgumentError, "Output for #{output} in #{style} style is not yet implemented" ) unless File.exists?(renderer)
|
|
36
|
+
options = YAML.load_file(renderer)
|
|
37
|
+
processor = RenderProcessor.new(options, line_numbers, headers)
|
|
38
|
+
yield processor if block_given?
|
|
39
|
+
processor
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def initialize render_options, line_numbers = false, headers = true, score_manager = nil
|
|
43
|
+
@score_manager = score_manager || @@score_manager
|
|
44
|
+
@render_options = render_options
|
|
45
|
+
@options = {}
|
|
46
|
+
@headers = headers
|
|
47
|
+
@line_numbers = line_numbers
|
|
48
|
+
@escapeHTML = true
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def start_parsing name
|
|
52
|
+
@stack = [name]
|
|
53
|
+
@string = ""
|
|
54
|
+
@line = nil
|
|
55
|
+
@line_number = 0
|
|
56
|
+
## Dyndoc.warn "render_options",@render_options["listing"]
|
|
57
|
+
print @render_options["document"]["begin"] if @headers
|
|
58
|
+
## FIX (01/09/2014): "begin-line-numbers" undefined for xhtml and has to replaced by "begin"
|
|
59
|
+
print (@line_numbers ? @render_options["listing"]["begin"] : @render_options["listing"]["begin-line-numbers"] || @render_options["listing"]["begin"])
|
|
60
|
+
# opt = options @stack
|
|
61
|
+
# print opt["begin"] if opt
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def print string
|
|
65
|
+
@string << string
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def escape string
|
|
69
|
+
if @render_options["filter"]
|
|
70
|
+
@escaped = string
|
|
71
|
+
@escaped = self.instance_eval( @render_options["filter"] )
|
|
72
|
+
@escaped
|
|
73
|
+
else
|
|
74
|
+
string
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def open_tag name, position
|
|
79
|
+
@stack << name
|
|
80
|
+
print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
|
|
81
|
+
@position = position
|
|
82
|
+
opt = options @stack
|
|
83
|
+
print opt["begin"] if opt
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def close_tag name, position
|
|
87
|
+
print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
|
|
88
|
+
@position = position
|
|
89
|
+
opt = options @stack
|
|
90
|
+
print opt["end"] if opt
|
|
91
|
+
@stack.pop
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def close_line
|
|
95
|
+
stack = @stack[0..-1]
|
|
96
|
+
while stack.size > 1
|
|
97
|
+
opt = options stack
|
|
98
|
+
print opt["end"] if opt
|
|
99
|
+
stack.pop
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def open_line
|
|
104
|
+
stack = [@stack.first]
|
|
105
|
+
clone = @stack[1..-1]
|
|
106
|
+
while stack.size < @stack.size
|
|
107
|
+
stack << clone.shift
|
|
108
|
+
opt = options stack
|
|
109
|
+
print opt["begin"] if opt
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def new_line line
|
|
114
|
+
if @line
|
|
115
|
+
print escape(@line[@position..-1].gsub(/\n|\r/, ''))
|
|
116
|
+
close_line
|
|
117
|
+
print @render_options["line"]["end"]
|
|
118
|
+
print "\n"
|
|
119
|
+
end
|
|
120
|
+
@position = 0
|
|
121
|
+
@line_number += 1
|
|
122
|
+
@line = line
|
|
123
|
+
print @render_options["line"]["begin"]
|
|
124
|
+
if @line_numbers
|
|
125
|
+
print @render_options["line-numbers"]["begin"]
|
|
126
|
+
print @line_number.to_s.rjust(4).ljust(5)
|
|
127
|
+
print @render_options["line-numbers"]["end"]
|
|
128
|
+
print " "
|
|
129
|
+
end
|
|
130
|
+
open_line
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def end_parsing name
|
|
134
|
+
if @line
|
|
135
|
+
print escape(@line[@position..-1].gsub(/\n|\r/, ''))
|
|
136
|
+
while @stack.size > 1
|
|
137
|
+
opt = options @stack
|
|
138
|
+
print opt["end"] if opt
|
|
139
|
+
@stack.pop
|
|
140
|
+
end
|
|
141
|
+
print @render_options["line"]["end"]
|
|
142
|
+
print "\n"
|
|
143
|
+
end
|
|
144
|
+
# opt = options @stack
|
|
145
|
+
# print opt["end"] if opt
|
|
146
|
+
@stack.pop
|
|
147
|
+
print @render_options["listing"]["end"]
|
|
148
|
+
print @render_options["document"]["end"] if @headers
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def options stack
|
|
152
|
+
ref = stack.join ' '
|
|
153
|
+
return @options[ref] if @options.has_key? ref
|
|
154
|
+
|
|
155
|
+
result = @render_options['tags'].max do |a, b|
|
|
156
|
+
@score_manager.score( a['selector'], ref ) <=> @score_manager.score( b['selector'], ref )
|
|
157
|
+
end
|
|
158
|
+
result = nil if @score_manager.score( result['selector'], ref ) == 0
|
|
159
|
+
@options[ref] = result
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
|
|
3
|
+
module Dyndoc
|
|
4
|
+
|
|
5
|
+
FORMATS=["Tex","Txtl","Txt","Tm","Ttm","Html"]
|
|
6
|
+
|
|
7
|
+
# first declaration of the config directory
|
|
8
|
+
@@dyn_root_path=Settings['path.dyn_home']
|
|
9
|
+
@@dyn_gem_path=File.expand_path(File.join(__FILE__,[".."]*4))
|
|
10
|
+
@@cfg_dir={
|
|
11
|
+
:root_path=> @@dyn_root_path,
|
|
12
|
+
:gem_path=> @@dyn_gem_path,
|
|
13
|
+
:log_file => File.join(@@dyn_root_path,".dyn_log"),
|
|
14
|
+
:etc => File.join(@@dyn_root_path,"etc"),
|
|
15
|
+
:tmpl_path=>{:tex=>"Tex",:odt=>"Odt",:ttm=>"Ttm",:html => "Html"},
|
|
16
|
+
:model_default=>"Model",
|
|
17
|
+
:file => "", #to complete when dyndoc applied to a file
|
|
18
|
+
:current_doc_path => "" #completed each time a file is parsed in parse_do
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
require 'logger'
|
|
22
|
+
@@dyn_logger = Logger.new @@cfg_dir[:log_file], 7, 1048576
|
|
23
|
+
|
|
24
|
+
def Dyndoc.cfg_dir
|
|
25
|
+
@@cfg_dir
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def Dyndoc.cfg_dyn
|
|
29
|
+
Settings[:cfg_dyn]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def Dyndoc.logger
|
|
33
|
+
@@dyn_logger
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
@@dyn_block={}
|
|
37
|
+
|
|
38
|
+
def Dyndoc.dyn_block
|
|
39
|
+
@@dyn_block
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
## default mode and extension
|
|
43
|
+
@@mode=:txt
|
|
44
|
+
@@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"],
|
|
45
|
+
:tm=>["_tm.dyn",".dyn_tm","_tmpl.tm",".dyn"],
|
|
46
|
+
:tex=>["_tex.dyn",".dyn_tex","_tmpl.tex",".dyn",".rtex"],
|
|
47
|
+
: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!
|
|
48
|
+
:ttm=>["_ttm.dyn",".dyn_ttm","_tmpl.ttm",".dyn"],
|
|
49
|
+
:all=>[".dyn"]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@@docExt={:raw => "",:txt => ".txt",:rb => ".rb",:c=>".c",:html=>".html",:txtl=>".rhtml",:tm=>".tm",:tex=>".tex",:odt=>".odt",:ttm=>"_ttm.xml"}
|
|
53
|
+
|
|
54
|
+
@@dynExt=[".dyn"]
|
|
55
|
+
|
|
56
|
+
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"}
|
|
57
|
+
|
|
58
|
+
def Dyndoc.mode
|
|
59
|
+
@@mode
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def Dyndoc.mode=(mode)
|
|
63
|
+
@@mode=mode
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def Dyndoc.docExt(mode=@@mode)
|
|
67
|
+
@@docExt[mode]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def Dyndoc.tmplExt
|
|
71
|
+
@@tmplExt
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def Dyndoc.init_dyndoc_library_path
|
|
76
|
+
|
|
77
|
+
[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|
|
|
78
|
+
if File.exists? dyndoc_library_path
|
|
79
|
+
path=File.read(dyndoc_library_path).strip
|
|
80
|
+
path=path.split(Dyndoc::PATH_SEP).map{|pa| File.expand_path(pa)}.join(Dyndoc::PATH_SEP)
|
|
81
|
+
if !ENV["DYNDOC_LIBRARY_PATH"] or ENV["DYNDOC_LIBRARY_PATH"].empty?
|
|
82
|
+
ENV["DYNDOC_LIBRARY_PATH"]= path
|
|
83
|
+
else
|
|
84
|
+
ENV["DYNDOC_LIBRARY_PATH"] += Dyndoc::PATH_SEP + path
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def Dyndoc.setRootDoc(rootDoc,root,before=true)
|
|
93
|
+
if rootDoc
|
|
94
|
+
if before
|
|
95
|
+
rootDoc2 = "#{root}:"+rootDoc
|
|
96
|
+
else
|
|
97
|
+
rootDoc2 = rootDoc+":#{root}"
|
|
98
|
+
end
|
|
99
|
+
else
|
|
100
|
+
rootDoc2=root
|
|
101
|
+
end
|
|
102
|
+
#insure unique path and adress of rootDoc is unchanged!
|
|
103
|
+
rootDoc.replace(rootDoc2.split(":").uniq.join(":")) if rootDoc2
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def Dyndoc.guess_mode(filename)
|
|
107
|
+
@@tmplExt.keys.map{|k| k.to_s}.sort.each do |ext|
|
|
108
|
+
return ext.to_sym if filename =~ /(#{@@tmplExt[ext.to_sym].join("|")})$/
|
|
109
|
+
end
|
|
110
|
+
return nil
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def Dyndoc.init_rootDoc
|
|
114
|
+
rootDoc=""
|
|
115
|
+
if File.directory?(path=File.join(@@cfg_dir[:etc],Dyndoc.cfg_dyn['etc_path_subdir']))
|
|
116
|
+
Dir[File.join(path,"*")].sort.each do |pa|
|
|
117
|
+
rootDoc += (rootDoc.empty? ? "" : ":") + File.read(pa).chomp
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
Dyndoc.cfg_dyn['root_doc']=rootDoc
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# append or alias tricks ##########################
|
|
124
|
+
@@append=nil
|
|
125
|
+
|
|
126
|
+
def Dyndoc.appendVar
|
|
127
|
+
@@append
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def Dyndoc.make_append
|
|
131
|
+
## global aliases
|
|
132
|
+
@@append={}
|
|
133
|
+
tmp=[]
|
|
134
|
+
sys_append=File.join( @@cfg_dir[:etc],"alias")
|
|
135
|
+
tmp += File.readlines(sys_append) if File.exists? sys_append
|
|
136
|
+
home_append=File.join(@@cfg_dir[:etc],'alias')
|
|
137
|
+
tmp += File.readlines(home_append) if File.exists? home_append
|
|
138
|
+
file_append=File.join(@@cfg_dir[:file],'.dyn_alias')
|
|
139
|
+
tmp += File.readlines(file_append) if File.exists? file_append
|
|
140
|
+
tmp.map{|l|
|
|
141
|
+
if l.include? ">"
|
|
142
|
+
l2=l.strip
|
|
143
|
+
unless l2.empty?
|
|
144
|
+
l2=l2.split(/[=>,]/).map{|e| e.strip}
|
|
145
|
+
@@append[l2[0]]=l2[-1]
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
}
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
## more useable than this !!!
|
|
152
|
+
def Dyndoc.absolute_path(filename,pathenv)
|
|
153
|
+
#puts "ici";p filename
|
|
154
|
+
return filename if File.exists? filename
|
|
155
|
+
paths=pathenv##.split(":")
|
|
156
|
+
#puts "absolute_path:filname";p filename
|
|
157
|
+
name=nil
|
|
158
|
+
paths.each{|e|
|
|
159
|
+
f=File.expand_path(File.join([e,filename]))
|
|
160
|
+
#p f
|
|
161
|
+
if (File.exists? f)
|
|
162
|
+
name=f
|
|
163
|
+
break
|
|
164
|
+
end
|
|
165
|
+
}
|
|
166
|
+
#puts "->";p name
|
|
167
|
+
name
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def Dyndoc.directory_tmpl?(name,exts=@@tmplExt[@@mode])
|
|
171
|
+
if name and File.directory? name
|
|
172
|
+
#puts "directory_tmpl?:name";p name;p exts
|
|
173
|
+
#p File.join(name,"index")
|
|
174
|
+
resname=Dyndoc.doc_filename(File.join(name,"index"),exts,false)
|
|
175
|
+
resname=Dyndoc.doc_filename(File.join(name,File.basename(name,".*")),exts,false) unless resname
|
|
176
|
+
|
|
177
|
+
##IMPORTANT: this file could not depend on the format_doc because it is related to the template and not the document!!!
|
|
178
|
+
resname=Dyndoc.doc_filename(File.join(@@cfg_dir[:root_path],["root","Default","index"]),exts,false) unless resname
|
|
179
|
+
name=resname
|
|
180
|
+
end
|
|
181
|
+
#puts "directory_tmpl?:return resname";p resname;p name
|
|
182
|
+
return name
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
PATH_SEP=";"
|
|
186
|
+
|
|
187
|
+
def Dyndoc.init_pathenv
|
|
188
|
+
#p Dyndoc.cfg_dyn
|
|
189
|
+
if Dyndoc.cfg_dyn[:dyndoc_mode]==:normal #normal mode
|
|
190
|
+
pathenv="."
|
|
191
|
+
else #client server mode
|
|
192
|
+
#puts "working directory";p Dyndoc.cfg_dyn[:working_dir]
|
|
193
|
+
pathenv = Dyndoc.cfg_dyn[:working_dir] + PATH_SEP + "."
|
|
194
|
+
end
|
|
195
|
+
return pathenv
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def Dyndoc.ordered_pathenv(pathenv)
|
|
200
|
+
path_ary=[]
|
|
201
|
+
pathenv.split(PATH_SEP).each{|e|
|
|
202
|
+
if e=~/(?:\((\-?\d*)\))(.*)/
|
|
203
|
+
path_ary.insert($1.to_i-1,$2.strip)
|
|
204
|
+
else
|
|
205
|
+
path_ary << e.strip
|
|
206
|
+
end
|
|
207
|
+
}
|
|
208
|
+
#puts "path_ary";p path_ary
|
|
209
|
+
path_ary.compact.uniq #.join(":")
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
## dynamically get pathenv!!!!
|
|
213
|
+
def Dyndoc.get_pathenv(rootDoc=nil,with_currentRoot=true)
|
|
214
|
+
pathenv = Dyndoc.init_pathenv
|
|
215
|
+
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")
|
|
216
|
+
# high level of priority since provided by user
|
|
217
|
+
pathenv += PATH_SEP + ENV["DYNDOC_LIBRARY_PATH"] if ENV["DYNDOC_LIBRARY_PATH"] and !ENV["DYNDOC_LIBRARY_PATH"].empty?
|
|
218
|
+
pathenv += PATH_SEP + File.join(Dyndoc.cfg_dir[:root_path],"library") if File.exists? File.join(@@cfg_dir[:root_path],"library")
|
|
219
|
+
pathenv += PATH_SEP + @@cfg_dir[:current_doc_path] if with_currentRoot and !@@cfg_dir[:current_doc_path].empty?
|
|
220
|
+
pathenv += PATH_SEP + rootDoc if rootDoc and !rootDoc.empty?
|
|
221
|
+
pathenv += PATH_SEP + Dyndoc.cfg_dyn[:root_doc] unless Dyndoc.cfg_dyn[:root_doc].empty?
|
|
222
|
+
pathenv += PATH_SEP + ENV["TEXINPUTS"].split(RUBY_PLATFORM =~ /mingw/ ? ";" : ":" ).join(";") if ENV["TEXINPUTS"] and @@mode==:tex
|
|
223
|
+
|
|
224
|
+
##Dyndoc.warn "pathenv",pathenv
|
|
225
|
+
return Dyndoc.ordered_pathenv(pathenv)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# if exts is a Symbol then it is the new @@mode!
|
|
229
|
+
def Dyndoc.doc_filename(filename,exts=@@tmplExt[@@mode],warn=true,pathenv=".",rootDoc=nil)
|
|
230
|
+
rootDoc=Dyndoc.cfg_dyn[:root_doc] unless Dyndoc.cfg_dyn[:root_doc].empty?
|
|
231
|
+
filename=filename.strip
|
|
232
|
+
if exts.is_a? Symbol
|
|
233
|
+
@@mode=exts
|
|
234
|
+
exts=@@tmplExt[@@mode]
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
pathenv = Dyndoc.get_pathenv(rootDoc)
|
|
238
|
+
exts = exts + @@tmplExt.values.flatten #if @cfg[:output]
|
|
239
|
+
exts << "" #with extension
|
|
240
|
+
#puts "before finding paths";p filename;p @@mode;p exts
|
|
241
|
+
exts.uniq!
|
|
242
|
+
names=exts.map{|ext| Dyndoc.absolute_path(filename+ext,pathenv)}.compact
|
|
243
|
+
name=(names.length>0 ? names[0] : nil)
|
|
244
|
+
if warn
|
|
245
|
+
print "WARNING: #{filename} with extension #{exts.join(',')} not reachable in:\n #{pathenv.join(':')}\n" unless name
|
|
246
|
+
#puts "tmpl:";p name
|
|
247
|
+
end
|
|
248
|
+
return name
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def Dyndoc.input_from_file(filename)
|
|
253
|
+
return Dyndoc.read_content_file(Dyndoc.doc_filename(filename))
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# the filename path has to be complete
|
|
257
|
+
def Dyndoc.read_content_file(filename,aux={})
|
|
258
|
+
#p filename
|
|
259
|
+
case File.extname(filename)
|
|
260
|
+
when ".odt"
|
|
261
|
+
odt=Dyndoc::Odt.new(filename)
|
|
262
|
+
aux[:doc].inputs={} unless aux[:doc].inputs
|
|
263
|
+
aux[:doc].inputs[filename]= odt unless aux[:doc].inputs[filename]
|
|
264
|
+
odt.body_from_content
|
|
265
|
+
else
|
|
266
|
+
File.read(filename)
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
#find the name of the template when mode is given
|
|
271
|
+
def Dyndoc.name_tmpl(name,mode=:all)
|
|
272
|
+
#clean dtag
|
|
273
|
+
dtags=[:dtag] #update if necessary
|
|
274
|
+
dtag=name.scan(/(?:#{dtags.map{|e| "_#{e}_" }.join("|")})/)[0]
|
|
275
|
+
if dtag
|
|
276
|
+
name=name.gsub(/(?:#{dtags.map{|e| "_#{e}_" }.join("|")})/,"")
|
|
277
|
+
end
|
|
278
|
+
#puts "name";p name
|
|
279
|
+
#file exists?
|
|
280
|
+
if File.exists? name
|
|
281
|
+
return name
|
|
282
|
+
elsif name.scan(/([^\.]*)(#{@@tmplExt.map{|e| e[1]}.flatten.uniq.map{|e| Regexp.escape(e)}.join("|")})+$/)[0]
|
|
283
|
+
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!!!)
|
|
284
|
+
#puts "pathenv";p pathenv; p Dyndoc.absolute_path(name,pathenv)
|
|
285
|
+
return Dyndoc.absolute_path(name,pathenv)
|
|
286
|
+
else
|
|
287
|
+
return Dyndoc.doc_filename(name,@@tmplExt[mode],true)
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def Dyndoc.make_dir(dir)
|
|
292
|
+
tmp=File.expand_path(dir)
|
|
293
|
+
FileUtils.mkdir_p(tmp) unless File.exists? tmp
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
end
|