aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/conf.rb
blob: 52de51beed099a98e8089383327d097daf6068a7 (plain)
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
#encoding: utf-8
=begin
- Name: SiSU

  - Description: documents, structuring, processing, publishing, search
    config

  - Author: Ralph Amissah
    <ralph.amissah@gmail.com>

  - Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
    2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019,
    2020, 2021, Ralph Amissah,

  - 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

  - Homepages:
    <http://www.sisudoc.org>

  - Git
    <https://git.sisudoc.org/projects/>
    <https://git.sisudoc.org/projects/?p=software/sisu.git;a=summary>
    <https://git.sisudoc.org/projects/?p=markup/sisu-markup-samples.git;a=summary>
=end
module SiSU_Initialize
  require_relative 'se'                                 # se.rb
    include SiSU_Env
    include SiSU_Screen
  require_relative 'relaxng'                            # relaxng.rb
    include SiSU_Relaxng
  require_relative 'css'                                # css.rb
    include SiSU_Style
  class Source
    def initialize(opt)
      @opt=opt
    end
    def read
      ConfigSite.new(@opt).make_homepage
      ConfigSite.new(@opt).css
      ConfigSite.new(@opt).dtd
      ConfigSite.new(@opt).cp_local_images
      ConfigSite.new(@opt).cp_external_images
      ConfigSite.new(@opt).cp_webserver_images
    end
  end
  class ConfigSite #config files such as css are not updated if they already exist unless forced using the --init=site modifier
    require_relative 'se'                               # se.rb
    def initialize(opt)
      @opt=opt
      @env=SiSU_Env::InfoEnv.new(@opt.fns)
      @suffix={
        rnc: 'rnc',
        rng: 'rng',
        xsd: 'xsd',
      }
      @path={
        xml: @env.path.output + '/_sisu/xml',
        xsd: @env.path.output + '/_sisu/xml/xsd',
        rnc: @env.path.output + '/_sisu/xml/rnc',
        rng: @env.path.output + '/_sisu/xml/rng',
        style: @env.path.output + '/' + @env.path.style,
      }
      @pwd,@home=Dir.pwd,@env.path.home
    end
    def make_homepage
      SiSU_Screen::Ansi.new(
        @opt.act[:color_state][:set],
        'invert',
        'Make homepage',
        ''
      ).colorize unless @opt.act[:quiet][:set]==:on
      SiSU_Env::CreateSite.new(@opt).homepage
    end
    def cp_local_images
      SiSU_Screen::Ansi.new(
        @opt.act[:color_state][:set],
        'invert',
        'Copy images',
        ''
      ).colorize unless @opt.act[:quiet][:set]==:on
      SiSU_Env::CreateSite.new(@opt).cp_local_images
      SiSU_Env::CreateSite.new(@opt).cp_webserver_images_local #this should not have been necessary
      SiSU_Env::CreateSite.new(@opt).cp_base_images #base images (nav etc.) used by all html
    end
    def cp_external_images
      SiSU_Screen::Ansi.new(
        @opt.act[:color_state][:set],
        'invert',
        'Copy external images',
        ''
      ).colorize if @opt.act[:verbose_plus][:set]==:on
      SiSU_Env::CreateSite.new(@opt).cp_external_images
    end
    def cp_webserver_images
      SiSU_Screen::Ansi.new(
        @opt.act[:color_state][:set],
        'invert',
        'Copy webserver/output file images',
        ''
      ).colorize unless @opt.act[:quiet][:set]==:on
      SiSU_Env::CreateSite.new(@opt).cp_webserver_images
    end
    def css
      SiSU_Screen::Ansi.new(
        @opt.act[:color_state][:set],
        'invert',
        'Configuring CSSs',
        ''
      ).colorize unless @opt.act[:quiet][:set]==:on
      SiSU_Env::CreateSite.new(@opt).cp_css
    end
    def dtd
      SiSU_Screen::Ansi.new(
        @opt.act[:color_state][:set],
        'invert',
        'Configuring DTDs',
        ''
      ).colorize unless @opt.act[:quiet][:set]==:on
      @rxng=SiSU_Relaxng::RelaxNG.new
      @path.each { |d| FileUtils::mkdir_p(d[1]) \
      unless FileTest.directory?(d[1]) }
      #ugly code, sort later
      if @rxng.methods.join =~/[^_]dtd_sax\b/
        if @rxng.dtd_sax.length > 200
          dtd=File.new("#{@path[:style]}/#{@rxng.rng_name.output_sax}",'w')
          dtd << @rxng.dtd_sax
          dtd.close
        else trang_rnc_model_output_sax
        end
      else trang_rnc_model_output_sax
      end
      if @rxng.methods.join =~/[^_]dtd_dom\b/
        if @rxng.dtd_dom.length > 200
          dtd=File.new("#{@path[:style]}/#{@rxng.rng_name.output_dom}",'w')
          dtd << @rxng.dtd_dom
          dtd.close
        else trang_rnc_model_output_dom
        end
      else trang_rnc_model_output_dom
      end
      if @rxng.methods.join =~/[^_]dtd_node\b/
        if @rxng.dtd_node.length > 200
          dtd=File.new("#{@path[:style]}/#{@rxng.rng_name.input_node}",'w')
          dtd << @rxng.dtd_node
          dtd.close
        else trang_rnc_model_input_node
        end
      else trang_rnc_model_input_node
      end
      if @rxng.methods.join =~/[^_]dtd_xhtml\b/
        if @rxng.dtd_xhtml.length > 200
          dtd=File.new("#{@path[:style]}/#{@rxng.rng_name.output_xhtml}",'w')
          dtd << @rxng.dtd_xhtml
          dtd.close
        else trang_rnc_model_output_xhtml
        end
      else trang_rnc_model_output_xhtml
      end
    end
    def trang_rnc_model_output_sax
      s=@suffix
      rnc_src=@env.processing_path.ao + '/sax.' + s[:rnc]
      rnc_file=@path[:rnc] + '/' + @rxng.rnc_name.output_sax
      rng_file=@path[:rng] + '/' + @rxng.rng_name.output_sax
      xsd_file=@path[:xsd] + '/' + @rxng.xsd_name.output_sax
      rnc=File.new(rnc_src,'w')
      rnc << @rxng.rnc_model_output_sax
      rnc.close
      #xsd
      schema=SiSU_Env::SystemCall.new(rnc_src,xsd_file)
      schema.relaxng(@opt.selections.str)
      #rng
      schema=SiSU_Env::SystemCall.new(rnc_src,rng_file)
      schema.relaxng(@opt.selections.str)
      #rnc
      if FileTest.file?(rnc_src)
        FileUtils::cp(rnc_src,rnc_file)
        FileUtils::chmod(0644,rnc_file)
      else STDERR.puts %{\t*WARN* did not find rnc - "#{rnc_src}" [#{__FILE__}:#{__LINE__}]}
      end
    end
    def trang_rnc_model_output_dom
      s=@suffix
      rnc_src=@env.processing_path.ao + '/dom.' + s[:rnc]
      rnc_file=@path[:rnc] + '/' + @rxng.rnc_name.output_dom
      rng_file=@path[:rng] + '/' + @rxng.rng_name.output_dom
      xsd_file=@path[:xsd] + '/' + @rxng.xsd_name.output_dom
      rnc=File.new(rnc_src,'w')
      rnc << @rxng.rnc_model_output_dom
      rnc.close
      #xsd
      schema=SiSU_Env::SystemCall.new(rnc_src,xsd_file)
      schema.relaxng(@opt.selections.str)
      #rng
      schema=SiSU_Env::SystemCall.new(rnc_src,rng_file)
      schema.relaxng(@opt.selections.str)
      #rnc
      if FileTest.file?(rnc_src)
        FileUtils::cp(rnc_src,rnc_file)
        FileUtils::chmod(0644,rnc_file)
      else STDERR.puts %{\t*WARN* did not find rnc - "#{rnc_src}" [#{__FILE__}:#{__LINE__}]}
      end
    end
    def trang_rnc_model_output_xhtml
      s=@suffix
      rnc_src=@env.processing_path.ao + '/xhtml.' + s[:rnc]
      rnc_file=@path[:rnc] + '/' + @rxng.rnc_name.output_xhtml
      rng_file=@path[:rng] + '/' + @rxng.rng_name.output_xhtml
      xsd_file=@path[:xsd] + '/' + @rxng.xsd_name.output_xhtml
      rnc=File.new(rnc_src,'w')
      rnc << @rxng.rnc_model_output_xhtml
      rnc.close
      #xsd
      schema=SiSU_Env::SystemCall.new(rnc_src,xsd_file)
      schema.relaxng(@opt.selections.str)
      #rng
      schema=SiSU_Env::SystemCall.new(rnc_src,rng_file)
      schema.relaxng(@opt.selections.str)
      #rnc
      if FileTest.file?(rnc_src)
        FileUtils::cp(rnc_src,rnc_file)
        FileUtils::chmod(0644,rnc_file)
      else STDERR.puts %{\t*WARN* did not find rnc - "#{rnc_src}" [#{__FILE__}:#{__LINE__}]}
      end
    end
    def trang_rnc_model_input_sax
      rnc_file=@env.processing_path.ao + '/sax.rnc'
      dtd_file=@path[:xsd] + '/' + @rxng.rng_name.input_sax
      rnc=File.new(rnc_file,'w')
      rnc << @rxng.rnc_model_output_sax
      rnc.close
      schema=SiSU_Env::SystemCall.new(rnc_file,dtd_file)
      schema.relaxng(@opt.selections.str)
    end
    def trang_rnc_model_input_dom
      rnc_file=@env.processing_path.ao + '/dom.rnc'
      dtd_file=@path[:xsd] + '/' + @rxng.rng_name.input_dom
      rnc=File.new(rnc_file,'w')
      rnc << @rxng.rnc_model_output_dom
      rnc.close
      schema=SiSU_Env::SystemCall.new(rnc_file,dtd_file)
      schema.relaxng(@opt.selections.str)
    end
    def trang_rnc_model_input_node
      rnc_file=@env.processing_path.ao + '/node.rnc'
      dtd_file=@path[:xsd] + '/' + @rxng.rng_name.input_node
      rnc=File.new(rnc_file,'w')
      rnc << @rxng.rnc_model_input_node
      rnc.close
      schema=SiSU_Env::SystemCall.new(rnc_file,dtd_file)
      schema.relaxng(@opt.selections.str)
    end
  end
end
__END__