dyndoc-ruby 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/bin/dpm.rb +63 -0
  3. data/bin/dyn-cli.rb +199 -0
  4. data/bin/dyn-srv.rb +101 -0
  5. data/bin/dyn.rb +77 -0
  6. metadata +110 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d7eeb3e8011928ea05a217fc5fb86739d3e1f850
4
+ data.tar.gz: 0d159d16d786d226a0fb702b8757a21dbb275c22
5
+ SHA512:
6
+ metadata.gz: 767b79488cf97184e55be93be8a65f6b496aec8ad6cc93fa388cc3d047efc9ba7ae1df06f3bf4910921c9b98e6ca82e119b4bdc8fb70fdd3bdf83e6550d000f1
7
+ data.tar.gz: 84fdb41d1bf4ab542a432f55558e7dd3ca08fd1b9c5b515ebce208df87cb374502846fdc5c5bbb139d41f62b032f4e2276910b8fd6fbeeba4d39ed5b7ffb8b05
data/bin/dpm.rb ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ require 'dyndoc/init/home'
5
+ dyndoc_home = Dyndoc.home
6
+ #p Dyndoc.home
7
+
8
+ lib_dir = ENV["DYNDOC_LIBRARY"] || File.join(dyndoc_home,"library")
9
+ repo_dir = File.join(lib_dir,".repository")
10
+
11
+ old_pwd = Dir.pwd
12
+
13
+ cmd = ARGV[0].to_sym
14
+ case cmd
15
+
16
+ # dyndoc-package install rcqls/dyndoc-share
17
+ when :install #default is github from now!
18
+ owner,package=File.split(ARGV[1])
19
+ package = package[0...-4] if package =~ /\.git$/
20
+ package_dir = File.join(repo_dir,owner)
21
+ FileUtils.mkdir_p package_dir
22
+ FileUtils.cd package_dir
23
+ `git clone https://github.com/#{owner}/#{package}.git`
24
+
25
+ # dyndoc-package update rcqls/dyndoc-share
26
+ when :update
27
+ FileUtils.cd File.join(repo_dir,ARGV[1])
28
+ `git pull`
29
+
30
+ # dyndoc-package link rcqls/dyndoc-share/library/RCqls (default to RCqls)
31
+ # dyndoc-package link rcqls/dyndoc-share/library/RCqls RCqls
32
+ # dyndoc-package link <real local path to expand>
33
+ when :link
34
+ path = File.expand_path(ARGV[1])
35
+ unless (local = (File.directory? path) )
36
+ path = ARGV[1] # not expanded
37
+ end
38
+ path,package = File.split(path)
39
+ target = ARGV[2] || package
40
+ target = File.join(lib_dir,target)
41
+ FileUtils.rm target if File.symlink? target #unlink first
42
+ source = local ? path : File.join(repo_dir,path,package)
43
+ FileUtils.ln_sf source,target
44
+
45
+ # dyndoc-package unlink RCqls
46
+ when :unlink
47
+ package = ARGV[1]
48
+ if RUBY_PLATFORM =~ /(?:msys|mingw)/
49
+ FileUtils.rm_rf File.join(lib_dir,package)
50
+ else
51
+ FileUtils.rm File.join(lib_dir,package)
52
+ end
53
+ when :ls
54
+ FileUtils.cd lib_dir
55
+ Dir["*"].each_with_index{|e,i| puts "#{i+1}) #{e}"}
56
+
57
+ when :repo
58
+ FileUtils.cd repo_dir
59
+ Dir[File.join("*","*")].each_with_index{|e,i| puts "#{i+1}) #{e}"}
60
+
61
+ end
62
+
63
+ FileUtils.cd old_pwd
data/bin/dyn-cli.rb ADDED
@@ -0,0 +1,199 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "socket"
4
+
5
+ module Dyndoc
6
+
7
+ class Client
8
+
9
+ attr_reader :content
10
+
11
+ @@end_token="__[[END_TOKEN]]__"
12
+
13
+ ## reinit is an array
14
+ def initialize(cmd,tmpl_filename,addr="127.0.0.1",reinit=[],port=7777)
15
+
16
+ @addr,@port,@cmd,@tmpl_filename=addr,port,cmd,tmpl_filename
17
+ ##p [:tmpl_filename,@tmpl_filename,@cmd]
18
+ ## The layout needs to be reintailized for new dyndoc file but not for the layout (of course)!
19
+ dyndoc_cmd="dyndoc"
20
+ dyndoc_cmd += "_with_tag_tmpl" if reinit.include? :dyndoc_tag_tmpl
21
+ dyndoc_cmd += "_with_libs_reinit" if reinit.include? :dyndoc_libs
22
+ dyndoc_cmd += "_with_layout_reinit" if reinit.include? :dyndoc_layout
23
+
24
+ Socket.tcp(addr, 7777) {|sock|
25
+ sock.print '__send_cmd__[['+dyndoc_cmd+'|'+@tmpl_filename+']]__' + @cmd + @@end_token
26
+ sock.close_write
27
+ @result=sock.read
28
+ }
29
+
30
+ data=@result.split(@@end_token,-1)
31
+ last=data.pop
32
+ resCmd=decode_cmd(data.join(""))
33
+ ##p [:resCmd,resCmd]
34
+ if resCmd and resCmd[:cmd] != "windows_platform"
35
+ @content=resCmd[:content]
36
+ end
37
+ end
38
+
39
+ def decode_cmd(res)
40
+ if res =~ /^__send_cmd__\[\[([a-zA-Z0-9_]*)\]\]__([\s\S]*)/m
41
+ return {cmd: $1, content: $2}
42
+ end
43
+ end
44
+
45
+ # def listen
46
+ # ##@response = Thread.new do
47
+ # result=""
48
+ # @content=nil
49
+ # msg=""
50
+ # loop {
51
+ # msg=@server.recv(1024)
52
+ # ##p msg
53
+ # if msg
54
+ # msg.chomp!
55
+ # ##puts "#{msg}"
56
+ # data=msg.split(@@end_token,-1)
57
+ # ##p data
58
+ # last=data.pop
59
+ # result += data.join("")
60
+ # #p "last:<<"+last+">>"
61
+ # if last == ""
62
+ # #console.log("<<"+result+">>")
63
+ # resCmd = decode_cmd(result)
64
+ # ##p resCmd
65
+ # if resCmd[:cmd] != "windows_platform"
66
+ # #console.log("data: "+resCmd["content"])
67
+ # @content=resCmd[:content]
68
+ # @server.close
69
+ # break
70
+ # end
71
+ # else
72
+ # result += last if last
73
+ # end
74
+ # end
75
+ # }
76
+ # #end
77
+ # end
78
+ end
79
+ end
80
+
81
+ # USAGE:
82
+ # dyndoc-ruby-client.rb|dyn-cli test.dyn[@127.0.0.1] [output_filename.html]
83
+ # dyndoc-ruby-client.rb|dyn-cli test.dyn,layout.dyn[@127.0.0.1] [output_filename.html]
84
+
85
+ next_i=0
86
+ dyn_tag_tmpl=nil
87
+ ## very limited tags system
88
+ if ARGV[0] =~ /\-t\=/
89
+ next_i=1
90
+ dyn_tag_tmpl="[#<]{#opt]"+ARGV[0][3..-1].strip+"[#opt}"
91
+ end
92
+
93
+ arg=ARGV[next_i]
94
+ dyn_output=ARGV[next_i + 1]
95
+
96
+
97
+
98
+ if arg.include? "@"
99
+ arg,addr=arg.split("@")
100
+ else
101
+ addr="127.0.0.1"
102
+ end
103
+
104
+ dyn_file,dyn_layout,dyn_libs,dyn_pre_code,dyn_post_code=nil,nil,nil,nil,nil
105
+
106
+ if arg.include? ","
107
+ dyn_file,dyn_layout=arg.split(",")
108
+ else
109
+ dyn_file=arg
110
+ if i=(dyn_file =~ /\_?(?:html|tex)?\.dyn$/)
111
+ dyn_layout=dyn_file[0...i]+"_layout.dyn" if File.exist? dyn_file[0...i]+"_layout.dyn"
112
+ end
113
+ end
114
+
115
+ if !dyn_layout and File.exist? ".dyn_layout"
116
+ dyn_layout=File.read(".dyn_layout").strip
117
+ end
118
+
119
+ if !dyn_layout and File.exist?(etc_dyn_layout=File.join(ENV["HOME"],".dyndocker","etc","dyn_cli_layout"))
120
+ dyn_layout=File.read(etc_dyn_layout).strip
121
+ end
122
+
123
+ # dyn library to require automatically
124
+ if !dyn_libs and File.exist? ".dynlibs"
125
+ dyn_libs=File.read(".dynlibs").strip
126
+ end
127
+
128
+ if !dyn_libs and File.exist?(etc_dyn_libs=File.join(ENV["HOME"],".dyndocker","etc","dyn-cli","dyn_libs"))
129
+ dyn_libs=File.read(etc_dyn_libs).strip
130
+ end
131
+
132
+ # very similar to dyn_libs but can preload any dyndoc
133
+ if i=(dyn_file =~ /\_?(?:html|tex)?\.dyn$/)
134
+ dyn_pre_code=File.read(dyn_file[0...i]+"_pre.dyn") if File.exist? dyn_file[0...i]+"_pre.dyn"
135
+ dyn_post_code=File.read(dyn_file[0...i]+"_post.dyn") if File.exist? dyn_file[0...i]+"_post.dyn"
136
+ end
137
+
138
+ if !dyn_pre_code and File.exist?(etc_dyn_pre_code=".dyn_pre_code")
139
+ etc_dyn_pre_code=File.read(etc_dyn_pre_code).strip
140
+ dyn_pre_code=File.read(etc_dyn_pre_code) if File.exist? etc_dyn_pre_code
141
+ end
142
+
143
+ if !dyn_libs and File.exist?(etc_dyn_pre_code=File.join(ENV["HOME"],".dyndocker","etc","dyn-cli","dyn_pre_code"))
144
+ etc_dyn_pre_code=File.read(etc_dyn_pre_code).strip
145
+ dyn_pre_code=File.read(etc_dyn_pre_code) if File.exist? etc_dyn_pre_code
146
+ end
147
+
148
+ # very similar to dyn_libs but can preload any dyndoc
149
+ if i=(dyn_file =~ /\_?(?:html|tex)?\.dyn$/)
150
+ dyn_pre_code=File.read(dyn_file[0...i]+"_pre.dyn") if File.exist? dyn_file[0...i]+"_pre.dyn"
151
+ dyn_post_code=File.read(dyn_file[0...i]+"_post.dyn") if File.exist? dyn_file[0...i]+"_post.dyn"
152
+ end
153
+
154
+ # similar to pre_code but for post_code
155
+ if !dyn_post_code and File.exist?(etc_dyn_post_code=".dyn_post_code")
156
+ etc_dyn_post_code=File.read(etc_dyn_post_code).strip
157
+ dyn_post_code=File.read(etc_dyn_post_code) if File.exist? etc_dyn_post_code
158
+ end
159
+
160
+ if !dyn_post_code and File.exist?(etc_dyn_post_code=File.join(ENV["HOME"],".dyndocker","etc","dyn-cli","dyn_post_code"))
161
+ etc_dyn_post_code=File.read(etc_dyn_post_code).strip
162
+ dyn_post_code=File.read(etc_dyn_post_code) if File.exist? etc_dyn_post_code
163
+ end
164
+
165
+
166
+ dyn_file=nil unless File.exist? dyn_file
167
+ dyn_layout=nil if dyn_layout and !File.exist? dyn_layout
168
+
169
+ if dyn_file
170
+ code=File.read(dyn_file)
171
+ if dyn_libs or dyn_pre_code
172
+ code_pre = ""
173
+ code_pre += dyn_pre_code + '\n' if dyn_pre_code
174
+ code_pre += '[#require]\n'+dyn_libs if dyn_libs
175
+ code = code_pre + '[#main][#>]' + code
176
+ end
177
+ code += '\n' + dyn_post_code if dyn_post_code
178
+ code = dyn_tag_tmpl+code if dyn_tag_tmpl
179
+ dyndoc_start=[:dyndoc_libs,:dyndoc_layout]
180
+ ## tag tmpl attempt to communicate to the server
181
+ if dyn_tag_tmpl
182
+ ##TODO: :dyndoc_tag_tmpl to add to dyndoc_start
183
+ ## but also to dyndoc-server-simple.rb
184
+ end
185
+
186
+ cli=Dyndoc::Client.new(code,File.expand_path(dyn_file),addr,dyndoc_start)
187
+
188
+ if dyn_layout
189
+ cli=Dyndoc::Client.new(File.read(dyn_layout),"",addr) #File.expand_path(dyn_layout),addr)
190
+ end
191
+
192
+ if dyn_output and Dir.exist? File.dirname(dyn_output)
193
+ File.open(dyn_output,"w") do |f|
194
+ f << cli.content
195
+ end
196
+ else
197
+ puts cli.content
198
+ end
199
+ end
data/bin/dyn-srv.rb ADDED
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'socket' # Get sockets from stdlib
4
+ require "dyndoc-core"
5
+
6
+
7
+ module Dyndoc
8
+
9
+ class InteractiveServer
10
+
11
+ def initialize
12
+ @tmpl_mngr=nil
13
+ @tmpl_filename=nil
14
+ init_dyndoc
15
+ init_server
16
+ end
17
+
18
+ def init_dyndoc
19
+ unless @tmpl_mngr
20
+ Dyndoc.cfg_dyn['dyndoc_session']=:interactive
21
+ @tmpl_mngr = Dyndoc::Ruby::TemplateManager.new({})
22
+ ##is it really well-suited for interactive mode???
23
+ end
24
+ reinit_dyndoc
25
+ end
26
+
27
+ def reinit_dyndoc
28
+ if @tmpl_mngr
29
+ @tmpl_mngr.init_doc({:format_output=> "html"})
30
+ @tmpl_mngr.require_dyndoc_libs("DyndocWebTools")
31
+ puts "InteractiveServer (re)initialized!\n"
32
+ @tmpl_mngr.as_default_tmpl_mngr! #=> Dyndoc.tmpl_mngr activated!
33
+ end
34
+ end
35
+
36
+
37
+ def process_dyndoc(content)
38
+ ##p [:process_dyndoc_content,content]
39
+ @content=@tmpl_mngr.parse(content)
40
+ ##Dyndoc.warn :content, @content
41
+ @tmpl_mngr.filterGlobal.envir["body.content"]=@content
42
+ if @tmpl_filename
43
+ @tmpl_mngr.filterGlobal.envir["_FILENAME_CURRENT_"]=@tmpl_filename.dup
44
+ @tmpl_mngr.filterGlobal.envir["_FILENAME_"]=@tmpl_filename.dup #register name of template!!!
45
+ @tmpl_mngr.filterGlobal.envir["_FILENAME_ORIG_"]=@tmpl_filename.dup #register name of template!!!
46
+ @tmpl_mngr.filterGlobal.envir["_PWD_"]=File.dirname(@tmpl_filename)
47
+ end
48
+ return @content
49
+ end
50
+
51
+ def init_server
52
+ @server = TCPServer.new('0.0.0.0',7777)
53
+ end
54
+
55
+ def run
56
+ trap("SIGINT") { @server.close;exit! }
57
+ loop {
58
+ socket = @server.accept
59
+
60
+ b=socket.recv(100000)
61
+ ##p [:b,b]
62
+ data=b.to_s.strip
63
+ ##p [:data,data]
64
+ if data =~ /^__send_cmd__\[\[([a-z,_]*)\|?([^\]]*)?\]\]__(.*)__\[\[END_TOKEN\]\]__$/m
65
+ cmd,@tmpl_filename,content = $1,$2,$3
66
+ ##p [:cmd,cmd,:content,content,:filename,@tmpl_filename]
67
+ #p [:tmpl_mngr,@tmpl_filename]
68
+ unless @tmpl_filename.empty?
69
+ Question.session_dir(File.dirname(@tmpl_filename))
70
+ end
71
+ if content.strip == "__EXIT__"
72
+ socket.close
73
+ @server.close
74
+ break
75
+ end
76
+
77
+ if cmd =~ /(.*)_with_layout_reinit$/
78
+ LayoutMngr.reinit
79
+ cmd=$1
80
+ end
81
+
82
+ if cmd =~ /(.*)_with_libs_reinit$/
83
+ reinit_dyndoc
84
+ cmd=$1
85
+ end
86
+
87
+ if cmd == "dyndoc"
88
+ res = process_dyndoc(content)
89
+ ##p [:dyndoc_server,content,res]
90
+ socket.write "__send_cmd__[[dyndoc]]__"+res+"__[[END_TOKEN]]__"
91
+ end
92
+ end
93
+ socket.close
94
+ }
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ Dyndoc::InteractiveServer.new.run
data/bin/dyn.rb ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+ require 'dyndoc/document'
3
+
4
+ ## p Dyndoc.cfg_dir
5
+
6
+ args=ARGV.select{|name|
7
+ if (name[0,2]!="--" and name.include? "=")
8
+ key,*val=name.split("=")
9
+ val=val.join("=")
10
+ Settings["cfg_dyn.user_input"] << [key,val]
11
+ false
12
+ else
13
+ true
14
+ end
15
+ }
16
+
17
+ require 'optparse'
18
+
19
+ OptionParser.new do |opts|
20
+ opts.banner = "Usage: dyndoc-compile.rb [options]"
21
+
22
+ opts.on("-d", "--docs one,two,three", Array, "list of documents to compile") do |list|
23
+ Settings["cfg_dyn.doc_list"] = list
24
+ end
25
+
26
+ opts.on("-f", "--format ", "format of the dyndoc document") do |format|
27
+ Settings["cfg_dyn.format_doc"] = format.to_sym
28
+ end
29
+
30
+ opts.on('-t','--tags TAGS',Array,'filter tags') {|t| Settings["cfg_dyn.tag_tmpl"] = t}
31
+
32
+ opts.on('-C',"--content-only", "content only mode (no header!)") do
33
+ Settings["cfg_dyn.model_doc"] = "Content"
34
+ end
35
+
36
+ opts.on('-c', '--cmd COMMAND','[a(rchive old)][r(emove old)][s(ave)][pdf(latex)]') {|c|
37
+ cmd =[:make_content]
38
+ cmd << :save_old if c.include? "a"
39
+ cmd << :rm_old if c.include? "r"
40
+ cmd << :save if c.include? "s"
41
+ ## cmd << :cat if c.include? "c"
42
+ cmd << :pdf if c =~ /(E)?pdf([1-3])?/ #if c.include? "pdf"
43
+ Settings["cfg_dyn.options.pdflatex_echo"]=true if $1 # useable for log sytem (to introduce possibly later)
44
+ Settings["cfg_dyn.options.pdflatex_nb_pass"]=$2.to_i if $2
45
+ ## cmd << :png if c.include? "png"
46
+ ## cmd << :view if c.include? "v"
47
+ ## cmd << :save << :view if c.include? "x"
48
+ ## cmd =[:cat] if cmd.empty? #and cfg_dyn[:model_doc]=="content"
49
+ ## cmd = [:pdf] if c=="pdf" #only pdflatex
50
+ Settings["cfg_dyn.cmd_doc"] = cmd
51
+ }
52
+
53
+ opts.on("-l", "--list", "list of documents available") do
54
+ Settings["cfg_dyn.cmd_doc"] = [:list]
55
+ end
56
+
57
+ opts.on('-D','--debug','debug mode') do
58
+ Settings['cfg_dyn.debug']=true
59
+ end
60
+
61
+ opts.on("-p", "--pandoc ", "filter for pandoc (tex2docx,...)") do |f|
62
+ #p [:pandoc,f]
63
+ Settings["cfg_dyn.pandoc_filter"] = f
64
+ end
65
+
66
+ # opts.on('--docker',"docker mode") do
67
+ # Settings["cfg_dyn.docker_mode"]=true
68
+ # end
69
+
70
+ end.parse!(args)
71
+
72
+ ## ARGV is consumed before except
73
+ doc=args[0]
74
+
75
+ d=Dyndoc::TemplateDocument.new(doc)
76
+
77
+ d.make_all
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dyndoc-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - CQLS
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: R4rb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: dyndoc-ruby-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: dyndoc-ruby-doc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: dyndoc-ruby-exec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.0
69
+ description: |2
70
+ Provide templating in text document.
71
+ email: rdrouilh@gmail.com
72
+ executables:
73
+ - dyn.rb
74
+ - dyn-cli.rb
75
+ - dyn-srv.rb
76
+ - dpm.rb
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - bin/dpm.rb
81
+ - bin/dyn-cli.rb
82
+ - bin/dyn-srv.rb
83
+ - bin/dyn.rb
84
+ homepage: http://cqls.upmf-grenoble.fr
85
+ licenses:
86
+ - MIT
87
+ - GPL-2
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements:
104
+ - none
105
+ rubyforge_project:
106
+ rubygems_version: 2.0.14
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: R and Ruby in text document
110
+ test_files: []