1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
# encoding: utf-8
=begin
* Name: SiSU
* Description: a framework for document structuring, publishing and search
* Author: Ralph Amissah
* Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah,
All Rights Reserved.
* License: GPL 3 or later:
SiSU, a framework for document structuring, publishing and search
Copyright (C) Ralph Amissah
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
If you have Internet connection, the latest version of the GPL should be
available at these locations:
<http://www.fsf.org/licensing/licenses/gpl.html>
<http://www.gnu.org/licenses/gpl.html>
<http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
* SiSU uses:
* Standard SiSU markup syntax,
* Standard SiSU meta-markup syntax, and the
* Standard SiSU object citation numbering and system
* Hompages:
<http://www.jus.uio.no/sisu>
<http://www.sisudoc.org>
* Git
<http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
<http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/v6/se_envcall.rb;hb=HEAD>
* Ralph Amissah
<ralph@amissah.com>
<ralph.amissah@gmail.com>
** Description: system environment, resource control and configuration details
=end
module SiSU_Env_Call
begin
require 'singleton'
rescue LoadError
SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
error('singleton NOT FOUND (LoadError)')
end
class EnvCall
@@rc,@@fns,@@fnn,@@fnb,@@fnt,@@flv,@@fnz=nil,nil,nil,nil,nil,nil,nil
@@ad={}
attr_accessor :rc,:fnn,:fnb,:fnt,:fnv,:fnz,:ad
def initialize(fns='')
@fns=fns
@sys=SiSU_Info_Sys::InfoSystem.instance
get_init=SiSU_Env::GetInit.new
@rc=get_init.sisu_yaml.rc
@ad=get_init.ads
if @fns \
and @fns != '' \
and @fns !=@@fns
@@fns,@@fnn,@@fnb,@@fnt,@@flv,@@fnz=@fns,nil,nil,nil,nil,nil
end
if @fns \
and @fns != '' #watch
m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm|ssi)$/
@@fnn ||=@fns[m,1]
@@fnb ||=@fns[m,2]
@@fnt ||=@fns[m,3]
@@flv ||=document_language_versions_found[:f]
unless @@fns =~/\S+?\.txz/
@@fnz ||=if @@fns =~/(?:\~\S{2,3})?\.(?:ssm\.sst|ssm)$/; @@fnb + '.ssm.txz'
elsif @@fnb; @@fnb + '.sst.txz'
else '' # e.g. termsheet
end
end
end
@fnn,@fnb,@fnt,@flv,@fnz=@@fnn,@@fnb,@@fnt,@@flv,@@fnz
end
def default_language?
if @rc \
&& defined? @rc['language_default']
if (@rc['language_default'].is_a?(String)) \
&& (@rc['language_default'] =~/#{Px[:lng_lst_rgx]}/)
@rc['language_default']
else 'en'
end
else 'en'
end
end
def mono_multi_lingual?
if @rc \
&& defined? @rc['output_dir_structure_by']
if @rc['output_dir_structure_by'] \
=~/dump/
:mono
elsif @rc['output_dir_structure_by'] \
=~/language|redirect/
:multi
elsif @rc['output_dir_structure_by'] \
=~/monolingual|filetype_mono|filenaneme_mono/
:mono
else :multi
end
else :multi
end
end
def output_dir_structure
def by?
output_structure=:filename #set default output structure
if @rc \
&& defined? @rc['output_dir_structure_by']
output_structure=if (@rc['output_dir_structure_by'] =~/dump/) \
or ((defined? @rc['output_structure']['dump']) \
&& @rc['output_structure']['dump'] ==true)
:dump
elsif (@rc['output_dir_structure_by'] =~/redirect/) \
or ((defined? @rc['output_structure']['redirect']) \
&& @rc['output_structure']['redirect'] ==true)
:redirect
elsif (@rc['output_dir_structure_by'] =~/language/) \
or ((defined? @rc['output_structure']['by_language']) \
&& @rc['output_structure']['by_language'] ==true)
:language
elsif (@rc['output_dir_structure_by'] =~/filetype/) \
or ((defined? @rc['output_structure']['by_filetype']) \
&& @rc['output_structure']['by_filetype'] ==true)
:filetype
elsif (@rc['output_dir_structure_by'] =~/filename/) \
or ((defined? @rc['output_structure']['by_filename']) \
&& @rc['output_structure']['by_filename'] ==true)
:filename
else #set default
:language
end
else #set default
:language
end
end
def dump?
((by?) ==:dump) \
? true
: false
end
def redirect?
((by?) ==:redirect) \
? true
: false
end
def by_language_code?
((by?) ==:language) \
? true
: false
end
def by_filetype?
((by?) ==:filetype) \
? true
: false
end
def by_filename?
((by?) ==:filename) \
? true
: false
end
def multilingual?
by_language_code?
end
self
end
def document_language_versions_found #REVISIT
@fn={}
filename=(@fns =~/\.ssm\.sst$/) \
? @fns.gsub(/\.ssm\.sst$/,'.ssm')
: @fns
if filename.is_a?(String) \
and not filename.empty?
if output_dir_structure.by_language_code?
m=/((.+?)(?:\~\w{2,3})?)\.(sst|ssm)$/
@fn[:b],@fn[:m],@fn[:t]=filename[m,1],filename[m,2],filename[m,3]
else m=/(.+?)\.(sst|ssm)$/
@fn[:b]=@fn[:m]=filename[m,1]
@fn[:t]=filename[m,2]
end
end
lng_base=SiSU_Env::InfoEnv.new.language_default_set
lang=SiSU_Env::StandardiseLanguage.new
langs=lang.codes
x=[]
if FileTest.file?("#{@fn[:m]}.#{@fn[:t]}")
n=@fn[:m].gsub(/^.+?\//,'')
n =n + '.' + @fn[:t]
x << { f: "#{@fn[:m]}.#{@fn[:t]}", l: lng_base, n: n }
end
langs.each do |l|
lng=SiSU_Env::StandardiseLanguage.new(l)
if FileTest.file?("#{@fn[:m]}~#{lng.code}.#{@fn[:t]}")
x << { f: "#{@fn[:m]}~#{lng.code}.#{@fn[:t]}", l: lng.code }
elsif FileTest.file?("#{@fn[:m]}~#{lng.name}.#{@fn[:t]}")
x << { f: "#{@fn[:m]}~#{lng.name}.#{@fn[:t]}", l: lng.code }
end
if FileTest.file?("#{lng.code}/#{@fn[:m]}~#{lng.code}.#{@fn[:t]}")
if FileTest.file?("#{lng.code}/#{@fn[:m]}~#{lng.code}.#{@fn[:t]}")
x << { f: "#{lng.code}/#{@fn[:m]}~#{lng.code}.#{@fn[:t]}", l: lng.code }
elsif FileTest.file?("#{lng.code}/#{@fn[:m]}~#{lng.name}.#{@fn[:t]}")
x << { f: "#{lng.code}/#{@fn[:m]}~#{lng.name}.#{@fn[:t]}", l: lng.code }
end
end
if FileTest.file?("#{lng.code}/#{@fn[:m]}.#{@fn[:t]}")
if FileTest.file?("#{lng.code}/#{@fn[:m]}.#{@fn[:t]}")
x << { f: "#{lng.code}/#{@fn[:m]}.#{@fn[:t]}", l: lng.code }
elsif FileTest.file?("#{lng.code}/#{@fn[:m]}.#{@fn[:t]}")
x << { f: "#{lng.code}/#{@fn[:m]}.#{@fn[:t]}", l: lng.code }
end
end
end
@fn[:f]=x
@fn
end
def published_manifests?(output_base)
@fn={}
@m=[]
unless (@fns.nil? \
or @fns.empty?)
if output_dir_structure.by_language_code?
m=/((.+?)(?:\~\w{2,3})?)\.((?:-|ssm\.)?sst$)/
@fn[:b],@fn[:m],@fn[:t]=@fns[m,1],@fns[m,2],@fns[m,3]
else m=/(.+?)\.((?:-|ssm\.)?sst$)/
@fn[:b]=@fn[:m]=@fns[m,1]
@fn[:t]=@fns[m,2]
end
end
lang=SiSU_Env::StandardiseLanguage.new
langs=lang.codes
x=[]
if FileTest.file?("#{@fn[:m]}.#{@fn[:t]}"); x << "#{@fn[:m]}.#{@fn[:t]}"
end
dir=SiSU_Env::InfoEnv.new(@fns)
@m << { m: 'sisu_manifest.html', l: 'English' } #fix later, default language
langs.each do |l|
lng=SiSU_Env::StandardiseLanguage.new(l)
fns_c="#{@fn[:m]}~#{lng.code}.#{@fn[:t]}"
fns_l="#{@fn[:m]}~#{lng.name}.#{@fn[:t]}"
if FileTest.file?(fns_c)
fn_set_lang=SiSU_Env::StandardiseLanguage.new.
file_to_language(fns_c) #reconsider file_to_language
lng=fn_set_lang[:n]
fn=SiSU_Env::EnvCall.new(fns_c).lang(fn_set_lang[:c])
@m << { m: fn[:manifest], l: lng }
elsif FileTest.file?(fns_l)
fn_set_lang=SiSU_Env::StandardiseLanguage.new.
file_to_language(fns_l) #reconsider file_to_language
@fnl=dir.i18n.lang_filename(fn_set_lang[:c])
fn=SiSU_Env::EnvCall.new(fns_l).lang(fn_set_lang[:c])
@m << { m: fn[:manifest], l: lng }
end
end
@m=@m.uniq
end
def filename(code,name,suffix)
"#{name}#{suffix}"
end
def lang(code)
{
html: filename(code,'','.html'),
book_index: filename(code,'book_index','.html'),
concordance: filename(code,'concordance','.html'),
sax: filename(code,'sax','.xml'),
dom: filename(code,'dom','.xml'),
docbook: filename(code,'docbook','.xml'),
xhtml: filename(code,'scroll','.xhtml'),
pdf_l: filename(code,'','.pdf'),
pdf_p: filename(code,'','.pdf'),
pdf_l_a4: filename(code,"a4",'.pdf'),
pdf_p_a4: filename(code,"a4",'.pdf'),
pdf_l_a5: filename(code,"a5",'.pdf'),
pdf_p_a5: filename(code,"a5",'.pdf'),
pdf_l_b5: filename(code,"b5",'.pdf'),
pdf_p_b5: filename(code,"b5",'.pdf'),
pdf_l_letter: filename(code,"letter",'.pdf'),
pdf_p_letter: filename(code,"letter",'.pdf'),
pdf_l_legal: filename(code,"legal",'.pdf'),
pdf_p_legal: filename(code,"legal",'.pdf'),
toc: filename(code,'toc','.html'),
doc: filename(code,fnb,'.html'),
index: filename(code,'index','.html'),
po: filename(code,@fns,'.po'),
pot: filename(code,@fns,'.pot'),
odf: filename(code,'','.odt'),
epub: filename(code,'','.epub'),
plain: filename(code,'','.txt'),
qrcode: filename(code,'','.jpg'),
manpage: filename(code,'','.1'), #fix, section number
wiki: filename(code,'wiki','.txt'),
digest: filename(code,'digest','.txt'),
metadata: filename(code,'metadata','.html'), #chk
manifest: filename(code,'manifest','.html'),
oai_pmh: filename(code,'oai_pmh','.xml'),
sitemap: filename(code,'sitemap','.xml'),
sitemap_touch: filename(code,"sitemap_#{fnb}",'.xml'),
sxs: filename(code,fnb,'.sxs.xml'),
sxd: filename(code,fnb,'.sxd.xml'),
sxn: filename(code,fnb,'.sxn.xml'),
sisupod: filename(nil,@fnz,''),
book_idx_html: filename(code,'book_index','.html'),
book_idx_epub: filename(code,'book_index','.xhtml'),
epub_concord: filename(code,'concordance','.xhtml'),
}
end
end
end
__END__
|