Class: SiSU_Source::SiSUpodSource

Inherits:
Object
  • Object
show all
Includes:
SiSU_Composite_Doc_Utils
Defined in:
lib/sisu/src_shared.rb

Instance Method Summary collapse

Methods included from SiSU_Composite_Doc_Utils

#composite_and_imported_filenames_array, #extract_filenames, #insert_filename?, #inserts_array

Constructor Details

#initialize(opt, build = nil, place = nil) ⇒ SiSUpodSource

Returns a new instance of SiSUpodSource.



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
# File 'lib/sisu/src_shared.rb', line 62

def initialize(opt,build=nil,place=nil)
  @opt=opt
  @date=SiSU_Env::InfoDate.new.dt
  @env=SiSU_Env::InfoEnv.new(opt.fns)
  #@ver=SiSU_Env::InfoVersion.instance.get_version
  @v=(@opt.act[:verbose_plus][:set]==:on \
  || @opt.act[:maintenance][:set]==:on) \
  ? 'v' : ''
  @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
  @file=@particulars.file
  @local_path="#{@file.output_path.sisupod.dir}"
  processing_sisupod=@env.processing_path.processing_sisupod(opt)
  processing_sisupod.make
  path_pod=processing_sisupod.paths[:sisupod]
  path_pod_fnb=processing_sisupod.paths[:fnb]
  FileUtils::mkdir_p(path_pod) unless FileTest.directory?(path_pod)
  @path_pod={
    fnb:       path_pod_fnb,
    pod:       path_pod,
    doc:       path_pod + '/' + Gt[:doc] + '/' + opt.lng,
    po:        path_pod + '/' + Gt[:po]  + '/' + opt.lng,
    pot:       path_pod + '/' + Gt[:pot],
    conf:      path_pod + '/' + Gt[:conf],
    image:     path_pod + '/' + Gt[:image],
    audio:     path_pod + '/' + Gt[:audio],
    video:     path_pod + '/' + Gt[:video],
  }
end

Instance Method Details

#directoriesObject

NB not all possibilies met, revisit, also in case of composite file may wish to add README



290
291
292
# File 'lib/sisu/src_shared.rb', line 290

def directories
  SiSU_Env::InfoEnv.new.sisupod_v4(@opt)
end

#image_extraction(doc_import_list) ⇒ Object



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
# File 'lib/sisu/src_shared.rb', line 118

def image_extraction(doc_import_list)
  @rgx_rb_image=/["']\S*?([a-zA-Z0-9_-]+?\.(?:png|jpg|gif))["']/
  @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/
  doc_import_dir=@opt.sub_location
  images=[]
  if doc_import_list.length > 0
    doc_import_list=doc_import_list.uniq.flatten
    doc_import_list.each do |fn|
      file_array=IO.readlines(fn,'')
      file_array.each do |f|                                               #% work area
        f=f.gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image')                   # embedded symbol (image)
        if f !~/^%+\s/ \
        and f =~@rgx_image
          images=images_extract(f,images)
        end
      end
    end
  end
  gi=SiSU_Env::GetInit.new
  unless FileTest.file?("#{@path_pod[:conf]}/#{gi.makefile_name}")
    if gi.makefile \
    && FileTest.file?(gi.makefile)
      FileUtils::mkdir_p(@path_pod[:conf]) \
        unless FileTest.directory?(@path_pod[:conf])
      FileUtils::cp(gi.makefile,"#{@path_pod[:conf]}/#{gi.makefile_name}")
    end
    #get images from makefile, consider placing in param
  end
  if images \
  and images.length > 1
    images=images.flatten.uniq
    images.delete_if {|x| x =~/https?:\/\// }
    #images=images.sort
    FileUtils::mkdir_p(@path_pod[:image])
    images_pwd=@opt.image_src_path
    ##sequence copies base images, defaults used in all html outputs
      #image_source_base='/usr/share/sisu/image'
      #dir_pwd=Dir.pwd
      #Dir.chdir(image_source_base)
      #base_images=Dir.glob('*')
      #base_images.each do |i|
      #  FileUtils::cp_r(i,"#{images_path_pod}/#{i}")
      #end
      #Dir.chdir(dir_pwd)
    if FileTest.directory?(images_pwd)
      images=images.uniq
      images.each do |i|
        if FileTest.file?("#{images_pwd}/#{i}")
          FileUtils::cp(
            "#{images_pwd}/#{i}",
            "#{@path_pod[:image]}/#{i}"
          )
        else
          STDERR.puts \
            %{\t*WARN* did not find image - } \
            + %{"#{images_pwd}/#{i}" } \
            + %{[#{__FILE__}:#{__LINE__}]}
        end
      end
    else
      STDERR.puts \
        %{\t*WARN* did not find - } \
        + %{#{images_pwd} #{@path_pod[:image]} } \
        + %{[#{__FILE__}:#{__LINE__}]}
    end
  end
  if doc_import_list.length > 0 \
  and @opt.fno =~/\.ssm$/
    doc_import_list.each do |f|
      if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f}")
        FileUtils::cp(
          "#{@opt.base_path}#{doc_import_dir}/#{f}",
          "#{@path_pod[:doc]}/#{f}"
        )
      else
        STDERR.puts \
          %{\t*WARN* did not find image - } \
          + %{"#{@opt.base_path}#{doc_import_dir}/#{f}" } \
          + %{[#{__FILE__}:#{__LINE__}]}
      end
    end
  end
end

#images_extract(f, images) ⇒ Object

consider using param info



110
111
112
113
114
115
116
117
# File 'lib/sisu/src_shared.rb', line 110

def images_extract(f,images)                                                # consider using param info
  rgx_image=/(?:^|[^_\\])\{(?:\s*|\~\^\s+)(\S+?\.(?:png|jpg|gif)\b)/m
  if f !~/^%+\s/ \
  and f =~rgx_image
    images << f.scan(rgx_image).uniq
  end
  images.flatten
end

#language_versionsObject



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
# File 'lib/sisu/src_shared.rb', line 201

def language_versions
  x=@env.document_language_versions_found                                  #check multiple document language versions (param not used)
  doc_import_dir=@opt.sub_location
  if x[:f] \
  and x[:f].length > 0                                                     #store multiple document language versions, sisupod
    x[:f].each do |f|
      FileUtils::mkdir_p(@path_pod[:doc]) \
        unless FileTest.directory?(@path_pod[:doc])
      if f[:f] =~/\~(\S{2,3})\.ss[tm]$/
        lng_f=$1
        if @opt.lng == lng_f
          if @opt.fno =~/\.ssm$/
            if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}")
              FileUtils::cp(
                "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}",
                "#{@path_pod[:doc]}/#{f[:n]}"
              )
            else
              STDERR.puts \
                %{\t*WARN* did not find - } \
                + %{"#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" } \
                + %{[#{__FILE__}:#{__LINE__}]}
            end
          else
            if FileTest.file?("#{@opt.base_path}/#{f[:f]}")
              cpy= :no
              cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \
              or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/
                :yes
              elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \
              and @opt.f_pth[:lng_is] == 'en'
                :yes
              else :no
              end
              if cpy == :yes
                FileUtils::cp(
                  "#{@opt.base_path}/#{f[:f]}",
                  "#{@path_pod[:doc]}/#{f[:n]}"
                )
              end
            else
              STDERR.puts \
                %{\t*WARN* did not find - } \
                + %{"#{@opt.base_path}/#{f[:f]}" } \
                + %{[#{__FILE__}:#{__LINE__}]}
            end
          end
        end
      else
        if @opt.fno =~/\.ssm$/
          if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}")
            FileUtils::cp_r(
              "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}",
              "#{@path_pod[:doc]}/#{f[:n]}"
            )
          else
            STDERR.puts \
              %{\t*WARN* did not find - } \
              + %{"#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" } \
              + %{[#{__FILE__}:#{__LINE__}]}
          end
        else
          if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}")
            cpy= :no
            cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \
            or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/
              :yes
            elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \
            and @opt.f_pth[:lng_is] == 'en'
              :yes
            else :no
            end
            if cpy == :yes
              FileUtils::cp(
                "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}",
                "#{@path_pod[:doc]}/#{f[:n]}"
              )
            end
          else
            STDERR.puts \
              %{\t*WARN* did not find - } \
              + %{"#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" } \
              + %{[#{__FILE__}:#{__LINE__}]}
          end
        end
      end
    end
  end #NB not all possibilies met, revisit, also in case of composite file may wish to add README
end

#readObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/sisu/src_shared.rb', line 90

def read
  unless @opt.act[:quiet][:set]==:on
    (@opt.act[:verbose][:set]==:on \
    || @opt.act[:verbose_plus][:set]==:on \
    || @opt.act[:maintenance][:set]==:on) \
    ? SiSU_Screen::Ansi.new(
      @opt.act[:color_state][:set],
      'Assemble SiSU source',
      "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").
      green_hi_blue
    : ''
  end
  unless @opt.fns.empty?
    directories
    doc_import_list=composite_and_imported_filenames_array(@opt.fno)
    doc_import_list=[@opt.fno, doc_import_list].flatten
    image_extraction(doc_import_list)
    language_versions
  end
end