dyndoc-ruby-exec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e946bdd35eca8289b6d304c0847135a243502ff5
4
+ data.tar.gz: 39ae2ef809a94dc7d625405bcc7dae4b7997f29b
5
+ SHA512:
6
+ metadata.gz: 4b244989faa2a372cb6ce230862dadb5650625bf6392e04ec6612a2eefc56e1568db4babb8d1760f1509d0a69d0fd7757c9c98694e32b2a82e8eb4bd543fc2ce
7
+ data.tar.gz: 8cf21028075c7f342cf762a234f9bf42977878d436022d89d0dff1b22fdb804e63a2a5255f6c77cf1a3ddd6a718dc1319bd5984f47b3da8557f1bdb54cc594c1
@@ -0,0 +1,178 @@
1
+ # encoding: UTF-8
2
+
3
+ require "open3"
4
+ # begin
5
+ # require 'redcloth'
6
+ # rescue LoadError
7
+ # Dyndoc.warn "Warning: RedCloth not installed or supported!"
8
+ # end
9
+ #require 'pandoc-ruby'
10
+
11
+ module Dyndoc
12
+
13
+ def Dyndoc.which_path(bin)
14
+ cmd=`which #{bin}`.strip
15
+ cmd=DyndocMsys2.global_path_msys2mingw(cmd) if RUBY_PLATFORM =~ /mingw/
16
+ return cmd
17
+ end
18
+
19
+ module Converter
20
+
21
+ SOFTWARE={}
22
+
23
+ def Converter.mathlink(input)
24
+ unless SOFTWARE[:mathlink]
25
+ cmd=`type "math"`
26
+ unless cmd.empty?
27
+ require 'mathematica'
28
+ SOFTWARE[:mathlink]=Mathematica::Mathematica.new.start #cmd.strip.split(" ")[2] unless cmd.empty?
29
+ end
30
+ end
31
+ SOFTWARE[:mathlink] ? SOFTWARE[:mathlink].eval_foreground(input) : ""
32
+ end
33
+
34
+ def Converter.pdflatex(input,opt='')
35
+ output = ''
36
+ unless SOFTWARE[:pdflatex]
37
+ cmd=`type "pdflatex"`
38
+ SOFTWARE[:pdflatex]=cmd.strip.split(" ")[2] unless cmd.empty?
39
+ end
40
+ if SOFTWARE[:pdflatex]
41
+ Open3.popen3("#{SOFTWARE[:pdflatex]} #{opt}") {|stdin,stdout,stderr|
42
+ stdin.print input
43
+ stdin.close
44
+ output=stdout.read
45
+ }
46
+ return nil
47
+ else
48
+ $dyn_logger.write("ERROR pdflatex: software not installed!\n")
49
+ return nil
50
+ end
51
+ end
52
+
53
+ def Converter.pandoc(input,opt='')
54
+ output = ''
55
+ unless SOFTWARE[:pandoc]
56
+ if File.exist? File.join(ENV["HOME"],".cabal","bin","pandoc")
57
+ SOFTWARE[:pandoc]=File.join(ENV["HOME"],".cabal","bin","pandoc")
58
+ else
59
+ cmd = Dyndoc.which_path("pandoc")
60
+ SOFTWARE[:pandoc]=cmd unless cmd.empty?
61
+ #cmd=`type "pandoc"`
62
+ #SOFTWARE[:pandoc]=cmd.strip.split(" ")[2] unless cmd.empty?
63
+ end
64
+ end
65
+ if SOFTWARE[:pandoc]
66
+ ##DEBUG: p [:pandoc_soft, SOFTWARE[:pandoc]+" #{opt}"]
67
+ if input
68
+ ##DEBUG: p [:pandoc_iput,input]
69
+ ##DEBUG: p [:pandoc_options, opt]
70
+ Open3::popen3(SOFTWARE[:pandoc]+" #{opt}") do |stdin, stdout, stderr|
71
+ stdin.puts input
72
+ stdin.close
73
+ output = stdout.read.strip
74
+ end
75
+ ##DEBUG: p [:pandoc_output,output]
76
+ output
77
+ else
78
+ ##DEBUG: p SOFTWARE[:pandoc]+" #{opt}"
79
+ system(SOFTWARE[:pandoc]+" #{opt}")
80
+ end
81
+ else
82
+ if $dyn_logger
83
+ $dyn_logger.write("ERROR pandoc: software not installed!\n")
84
+ else
85
+ Dyndoc.warn "ERROR pandoc: software not installed!\n"
86
+ end
87
+ ""
88
+ end
89
+ end
90
+
91
+ # ttm converter
92
+ def Converter.ttm(input,opt='-e2')
93
+ #puts "ttm:begin"
94
+ output=nil
95
+ unless SOFTWARE[:ttm]
96
+ cmd=`type "ttm"`
97
+ SOFTWARE[:ttm]=cmd.strip.split(" ")[2] unless cmd.empty?
98
+ end
99
+ if SOFTWARE[:ttm]
100
+ Open3.popen3("#{SOFTWARE[:ttm]} #{opt}") {|stdin,stdout,stderr|
101
+ stdin.print input
102
+ stdin.close
103
+ output=stdout.read
104
+ #puts "ttm:wait"
105
+ }
106
+ #puts "ttm:end"
107
+ output.gsub("__VERBATIM__","verbatim").sub(/\A\n*/,"") #the last is because ttm adds 6 \n for nothing!
108
+ else
109
+ $dyn_logger.write("ERROR ttm: software not installed!\n")
110
+ ""
111
+ end
112
+ end
113
+
114
+ def Converter.asciidoctor(code)
115
+ require 'asciidoctor'
116
+ Asciidoctor.convert(code,:attributes => {"icons" => "font"})
117
+ end
118
+
119
+ def Converter.convert(input,format,outputFormat,to_protect=nil)
120
+ ##
121
+ format=format.to_s unless format.is_a? String
122
+ ## Dyndoc.warn "convert input",[input,format]
123
+ outputFormat=outputFormat.to_s unless outputFormat.is_a? String
124
+ res=""
125
+ input.split("__PROTECTED__FORMAT__").each_with_index do |code,i|
126
+ ## Dyndoc.warn "code",[i,code,format,outputFormat]
127
+ if i%2==0
128
+ res << case format+outputFormat
129
+ when "adoc>html"
130
+ Dyndoc::Converter.asciidoctor(code)
131
+ when "md>html"
132
+ ##PandocRuby.new(code, :from => :markdown, :to => :html).convert
133
+ Dyndoc::Converter.pandoc(code)
134
+ when "md>tex"
135
+ #puts "latex documentclass";p Dyndoc::Utils.dyndoc_globvar("_DOCUMENTCLASS_")
136
+ if Dyndoc::Utils.dyndoc_globvar("_DOCUMENTCLASS_")=="beamer"
137
+ Dyndoc::Converter.pandoc(code,"-t beamer")
138
+ else
139
+ Dyndoc::Converter.pandoc(code,"-t latex")
140
+ end
141
+ when "md>odt"
142
+ ##PandocRuby.new(code, :from => :markdown, :to => :opendocument).convert
143
+ Dyndoc::Converter.pandoc(code,"-t opendocument")
144
+ when "txtl>html"
145
+ # (rc=RedCloth.new(code))
146
+ # rc.hard_breaks=false
147
+ # rc.to_html
148
+ Dyndoc::Converter.pandoc(code,"-f textile -t html")
149
+ when "txtl>tex"
150
+ # RedCloth.new(code).to_latex
151
+ Dyndoc::Converter.pandoc(code,"-f textile -t latex")
152
+ when "ttm>html"
153
+ Dyndoc::Converter.ttm(code,"-e2 -r -y1 -L").gsub(/<mtable[^>]*>/,"<mtable>").gsub("\\ngtr","<mtext>&ngtr;</mtext>").gsub("\\nless","<mtext>&nless;</mtext>").gsub("&#232;","<mtext>&egrave;</mtext>")
154
+ when "tex>odt"
155
+ puts "tex => odt"
156
+ tmp="<text:p><draw:frame draw:name=\""+`uuidgen`.strip+"\" draw:style-name=\"mml-inline\" text:anchor-type=\"as-char\" draw:z-index=\"0\" ><draw:object>"+Dyndoc::Converter.pandoc(code,"--mathml -f latex -t html").gsub(/<\/?p>/,"").gsub(/<(\/?)([^\<]*)>/) {|e| "<"+($1 ? $1 : "")+"math:"+$2+">"}+"</draw:object></draw:frame></text:p>"
157
+ ##p tmp
158
+ tmp
159
+ when "tex>html"
160
+ ##PandocRuby.new(code, :from => :markdown, :to => :html).convert
161
+ Dyndoc::Converter.pandoc(code,"--mathjax -f latex -t html")
162
+ when "ttm>tex", "html>html",'tex>tex'
163
+ code
164
+ else
165
+ ## the rest returns nothing!
166
+ Dyndoc.warn "Warning: unknown conversion!"
167
+ ""
168
+ end
169
+ else
170
+ res << code
171
+ end
172
+ #puts "res";p res
173
+ end
174
+ return (to_protect ? "__PROTECTED__FORMAT__"+res+"__PROTECTED__FORMAT__": res)
175
+ end
176
+
177
+ end
178
+ end
@@ -0,0 +1,82 @@
1
+ module Dyndoc
2
+
3
+ SOFTWARE={}
4
+
5
+ def self.software_init(force=false)
6
+
7
+ unless SOFTWARE[:R]
8
+ if RUBY_PLATFORM=~/mingw32/
9
+ cmd=Dir[File.join(ENV["HomeDrive"],"Program Files","R","**","R.exe")]
10
+ SOFTWARE[:R]=cmd[0] unless cmd.empty?
11
+ else
12
+ cmd=`type "R"`
13
+ SOFTWARE[:R]=cmd.strip.split(" ")[2] unless cmd.empty?
14
+ end
15
+ end
16
+
17
+ unless SOFTWARE[:Rscript]
18
+ if RUBY_PLATFORM=~/mingw32/
19
+ cmd=Dir[File.join(ENV["HomeDrive"],"Program Files","R","**","Rscript.exe")]
20
+ SOFTWARE[:Rscript]=cmd[0] unless cmd.empty?
21
+ else
22
+ cmd=`type "Rscript"`
23
+ SOFTWARE[:R]=cmd.strip.split(" ")[2] unless cmd.empty?
24
+ end
25
+ end
26
+
27
+ unless SOFTWARE[:ruby]
28
+ cmd=`type "ruby"`
29
+ SOFTWARE[:ruby]=cmd.strip.split(" ")[2] unless cmd.empty?
30
+ end
31
+
32
+ unless SOFTWARE[:pdflatex]
33
+ cmd=`type "pdflatex"`
34
+ if RUBY_PLATFORM =~ /msys/
35
+ SOFTWARE[:pdflatex]="pdflatex"
36
+ else
37
+ SOFTWARE[:pdflatex]=cmd.empty? ? "pdflatex" : cmd.strip.split(" ")[2]
38
+ end
39
+ end
40
+
41
+ unless SOFTWARE[:pandoc]
42
+ if File.exist? File.join(ENV["HOME"],".cabal","bin","pandoc")
43
+ SOFTWARE[:pandoc]=File.join(ENV["HOME"],".cabal","bin","pandoc")
44
+ else
45
+ cmd = `which pandoc`.strip
46
+ SOFTWARE[:pandoc]=cmd unless cmd.empty?
47
+ #cmd=`type "pandoc"`
48
+ #SOFTWARE[:pandoc]=cmd.strip.split(" ")[2] unless cmd.empty?
49
+ end
50
+ end
51
+
52
+ unless SOFTWARE[:ttm]
53
+ cmd=`type "ttm"`
54
+ SOFTWARE[:ttm]=cmd.strip.split(" ")[2] unless cmd.empty?
55
+ end
56
+
57
+ end
58
+
59
+ def self.software
60
+ SOFTWARE
61
+ end
62
+
63
+ def self.software?(software)
64
+ software - SOFTWARE.keys
65
+ end
66
+
67
+ def self.pdflatex
68
+ # this has to be initialized each time you need pdflatex since TEXINPUTS could change!
69
+ if ENV['TEXINPUTS']
70
+ "env TEXINPUTS=#{ENV['TEXINPUTS']}" + (RUBY_PLATFORM=~/mingw32/ ? "; " : " ") + SOFTWARE[:pdflatex]
71
+ else
72
+ SOFTWARE[:pdflatex]
73
+ end
74
+ end
75
+
76
+ def self.R
77
+ SOFTWARE[:R]
78
+ end
79
+
80
+ self.software_init
81
+
82
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dyndoc-ruby-exec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - CQLS
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |2
14
+ Converters and software for dyndoc.
15
+ email: rdrouilh@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/dyndoc-converter.rb
21
+ - lib/dyndoc-software.rb
22
+ homepage: http://cqls.upmf-grenoble.fr
23
+ licenses:
24
+ - MIT
25
+ - GPL-2
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements:
42
+ - none
43
+ rubyforge_project:
44
+ rubygems_version: 2.0.14
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Converters and software for dyndoc
48
+ test_files: []