d: composite documents (.ssm), extract insert files list
authorRalph Amissah <ralph@amissah.com>
Sun, 11 Jan 2015 15:00:39 +0000 (10:00 -0500)
committerRalph Amissah <ralph@amissah.com>
Tue, 20 Jan 2015 04:46:16 +0000 (23:46 -0500)
data/doc/sisu/CHANGELOG_v6
lib/sisu/develop/ao_composite.rb
lib/sisu/develop/hub_actions.rb
lib/sisu/develop/src_shared.rb
lib/sisu/develop/utils_composite.rb [new file with mode: 0644]

index 59ba4d9f0ff6e26eb3da445e0bbb82769e6078c6..33b82b20088dc88722056f05e1fa6f395d3273f7 100644 (file)
@@ -92,6 +92,8 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_6.4.0.orig.tar.xz
     marked up documents, i.e. to place translated versions of a sisu document
     under po4a management
 
     marked up documents, i.e. to place translated versions of a sisu document
     under po4a management
 
+  * utils_composite, composite documents (.ssm) extract the list of insert files
+
   * sisu.org addition, modification, consider
 
 ** SiSU "UnFrozen" - prior to end of Debian Freeze
   * sisu.org addition, modification, consider
 
 ** SiSU "UnFrozen" - prior to end of Debian Freeze
index d6a4867b155cfb37770401cf90e05f18d26f106e..a60593d97a23e2d8e6c138adde3bcb8286d66f77 100644 (file)
@@ -57,6 +57,7 @@
 =end
 module SiSU_Assemble
   require_relative 'se'                                 # se.rb
 =end
 module SiSU_Assemble
   require_relative 'se'                                 # se.rb
+  require_relative 'utils_composite'                    # utils_composite.rb
   class RemoteImage
     def initialize
       @env=SiSU_Env::InfoEnv.new
   class RemoteImage
     def initialize
       @env=SiSU_Env::InfoEnv.new
@@ -86,6 +87,7 @@ module SiSU_Assemble
     end
   end
   class Composite
     end
   end
   class Composite
+    include SiSU_Composite_Doc_Utils # composite doc, .ssm, extract all related insert files, array of filenames test
     def initialize(opt)
       @opt=opt
       @env=SiSU_Env::InfoEnv.new
     def initialize(opt)
       @opt=opt
       @env=SiSU_Env::InfoEnv.new
@@ -100,14 +102,14 @@ module SiSU_Assemble
             'Composite Document',
             "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}",
           ).grey_title_hi unless @opt.act[:quiet][:set]==:on
             'Composite Document',
             "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}",
           ).grey_title_hi unless @opt.act[:quiet][:set]==:on
+          composite_and_imported_filenames_array(@opt.fno) # composite doc, .ssm, extract all related insert files, array of filenames test
           assembled=loadfile(@opt.fno)
           assembled=loadfile(@opt.fno)
-          #assembled=insertions?(fns_array)
-          write(assembled)
           write(assembled)
         end
         Dir.chdir(pwd)
       rescue
           write(assembled)
         end
         Dir.chdir(pwd)
       rescue
-        SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
+        SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).
+          location do
           __LINE__.to_s + ':' + __FILE__
         end
       ensure
           __LINE__.to_s + ':' + __FILE__
         end
       ensure
index 36a06000db0ad6d24546c2f17337200ad8147e64..68f0aef9b4d72488fee4b0b331741177feef95cd 100644 (file)
@@ -56,6 +56,8 @@
 =end
 module SiSU_Hub_Actions
   class HubActions
 =end
 module SiSU_Hub_Actions
   class HubActions
+    require_relative 'utils_composite'                    # utils_composite.rb
+    include SiSU_Composite_Doc_Utils                      # composite doc, .ssm, extract all related insert files, array of filenames test
     def initialize(opt)
       @opt=opt
     end
     def initialize(opt)
       @opt=opt
     end
index ebd4f9d981d5ed7a454806e26046e31bc059b8ad..948342c77993115e4c9fe2a802fbf48f4c5bf981 100644 (file)
@@ -59,6 +59,8 @@ module SiSU_Source
   class SiSUpodSource
     require_relative 'se'                               # se.rb
     require_relative 'se_hub_particulars'               # se_hub_particulars.rb
   class SiSUpodSource
     require_relative 'se'                               # se.rb
     require_relative 'se_hub_particulars'               # se_hub_particulars.rb
+    require_relative 'utils_composite'                  # utils_composite.rb
+    include SiSU_Composite_Doc_Utils                    # composite doc, .ssm, extract all related insert files, array of filenames test
     def initialize(opt,build=nil,place=nil)
       @opt=opt
       @date=SiSU_Env::InfoDate.new.dt
     def initialize(opt,build=nil,place=nil)
       @opt=opt
       @date=SiSU_Env::InfoDate.new.dt
@@ -74,7 +76,6 @@ module SiSU_Source
       processing_sisupod.make
       path_pod=processing_sisupod.paths[:sisupod]
       path_pod_fnb=processing_sisupod.paths[:fnb]
       processing_sisupod.make
       path_pod=processing_sisupod.paths[:sisupod]
       path_pod_fnb=processing_sisupod.paths[:fnb]
-      @doc_import_list=[]
       FileUtils::mkdir_p(path_pod) unless FileTest.directory?(path_pod)
       @path_pod={
         fnb:       path_pod_fnb,
       FileUtils::mkdir_p(path_pod) unless FileTest.directory?(path_pod)
       @path_pod={
         fnb:       path_pod_fnb,
@@ -102,8 +103,7 @@ module SiSU_Source
       end
       unless @opt.fns.empty?
         directories
       end
       unless @opt.fns.empty?
         directories
-        file_array=IO.readlines(@opt.fno,'')
-        doc_import_list=pod_source_build(file_array) #this needs to be built in case of multi-lingual for all of them, before single pass tar
+        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
         doc_import_list=[@opt.fno, doc_import_list].flatten
         image_extraction(doc_import_list)
         language_versions
@@ -165,7 +165,10 @@ module SiSU_Source
           images=images.uniq
           images.each do |i|
             if FileTest.file?("#{images_pwd}/#{i}")
           images=images.uniq
           images.each do |i|
             if FileTest.file?("#{images_pwd}/#{i}")
-              FileUtils::cp("#{images_pwd}/#{i}","#{@path_pod[:image]}/#{i}")
+              FileUtils::cp(
+                "#{images_pwd}/#{i}",
+                "#{@path_pod[:image]}/#{i}"
+              )
             else
               STDERR.puts \
                 %{\t*WARN* did not find image - "#{images_pwd}/#{i}" [#{__FILE__}:#{__LINE__}]}
             else
               STDERR.puts \
                 %{\t*WARN* did not find image - "#{images_pwd}/#{i}" [#{__FILE__}:#{__LINE__}]}
@@ -180,7 +183,10 @@ module SiSU_Source
       and @opt.fno =~/\.ssm$/
         doc_import_list.each do |f|
           if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f}")
       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}")
+            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__}]}
           else
             STDERR.puts \
               %{\t*WARN* did not find image - "#{@opt.base_path}#{doc_import_dir}/#{f}" [#{__FILE__}:#{__LINE__}]}
@@ -194,14 +200,17 @@ module SiSU_Source
       if x[:f] \
       and x[:f].length > 0                                                     #store multiple document language versions, sisupod
         x[:f].each do |f|
       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])
+          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]}")
           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]}")
+                  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__}]}
                 else
                   STDERR.puts \
                     %{\t*WARN* did not find - "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]}
@@ -218,8 +227,10 @@ module SiSU_Source
                   else :no
                   end
                   if cpy == :yes
                   else :no
                   end
                   if cpy == :yes
-                    FileUtils::cp("#{@opt.base_path}/#{f[:f]}",
-                      "#{@path_pod[:doc]}/#{f[:n]}")
+                    FileUtils::cp(
+                      "#{@opt.base_path}/#{f[:f]}",
+                      "#{@path_pod[:doc]}/#{f[:n]}"
+                    )
                   end
                 else
                   STDERR.puts \
                   end
                 else
                   STDERR.puts \
@@ -230,8 +241,10 @@ module SiSU_Source
           else
             if @opt.fno =~/\.ssm$/
               if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}")
           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]}")
+                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__}]}
               else
                 STDERR.puts \
                   %{\t*WARN* did not find - "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]}
@@ -248,8 +261,10 @@ module SiSU_Source
                 else :no
                 end
                 if cpy == :yes
                 else :no
                 end
                 if cpy == :yes
-                  FileUtils::cp("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}",
-                    "#{@path_pod[:doc]}/#{f[:n]}")
+                  FileUtils::cp(
+                    "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}",
+                    "#{@path_pod[:doc]}/#{f[:n]}"
+                  )
                 end
               else
                 STDERR.puts \
                 end
               else
                 STDERR.puts \
@@ -263,35 +278,6 @@ module SiSU_Source
     def directories
       SiSU_Env::InfoEnv.new.sisupod_v4(@opt)
     end
     def directories
       SiSU_Env::InfoEnv.new.sisupod_v4(@opt)
     end
-    def ssm_doc_import_list(f)
-      if @opt.fno =~/\.ss[mi]$/
-        doc_import_list=[]
-        if f =~@rgx_doc_import
-          doc_import_list << f.scan(@rgx_doc_import)
-        end
-        doc_import_list.flatten.each do |i|
-          if i =~/.ssi/
-            file_array=IO.readlines(i,'')
-            pod_source_build(file_array)
-          end
-        end
-      end
-      doc_import_list.uniq.flatten
-    end
-    def pod_source_build(file_array)
-      @pwd=Dir.pwd
-      @rgx_doc_import=/^<<\s*(\S+?\.ss[ti])/
-      doc_import_list=[]
-      file_array.each do |f|                                                   #% work area
-        if f !~/^%+\s/
-          if @opt.fno =~/\.ss[mi]$/
-            @doc_import_list << ssm_doc_import_list(f)
-            doc_import_list=@doc_import_list.flatten.uniq
-          end
-        end
-      end
-      doc_import_list
-    end
   end
 end
 __END__
   end
 end
 __END__
diff --git a/lib/sisu/develop/utils_composite.rb b/lib/sisu/develop/utils_composite.rb
new file mode 100644 (file)
index 0000000..ee8fe77
--- /dev/null
@@ -0,0 +1,115 @@
+# encoding: utf-8
+=begin
+
+* Name: SiSU
+
+** Description: documents, structuring, processing, publishing, search
+*** system environment, debug related
+
+** Author: Ralph Amissah
+  <ralph@amissah.com>
+  <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 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/develop/utils_composite.rb;hb=HEAD>
+
+=end
+module SiSU_Composite_Doc_Utils
+  def inserts_array(loadfilename)
+    IO.readlines(loadfilename,'')
+  end
+  def insert_filename?(para)
+    if para =~ /^<<\s+((?:https?|file):\/\/\S+?\.ss[it])$/ # and NetTest
+      url($1.strip)
+    elsif para =~/^<<\s*(\S+?\.ss[it])$/
+      $1.strip
+    end
+  end
+  def extract_filenames(loadfilename,file_names_arr)
+    file_names_arr << loadfilename
+    ssi_files=[]
+    if loadfilename =~/\S+?\.ss[im]$/
+      inserts_array(loadfilename).each do |para|
+        filen=insert_filename?(para)
+        file_names_arr << filen
+        if filen =~/\S+?\.ssi$/
+          ssi_files << filen
+        end
+      end
+    end
+    ssi_files.each do |fn|
+      extract_filenames(fn,file_names_arr)
+    end
+    file_names_arr.flatten.compact.uniq.sort
+  end
+  def composite_and_imported_filenames_array(loadfilename)
+    file_names_arr=[]
+    begin
+      if FileTest.file?(loadfilename)
+        if loadfilename =~/\S+?\.ss[itm]$/
+          if (@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],
+              'loading:',
+              loadfilename,
+            ).txt_grey
+          end
+          file_names_arr=extract_filenames(loadfilename,file_names_arr)
+        end
+      end
+      if (@opt.act[:verbose_plus][:set]==:on \
+      || @opt.act[:maintenance][:set]==:on)
+        p file_names_arr ;p file_names_arr.length
+      end
+      file_names_arr
+    rescue
+      SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
+        __LINE__.to_s + ':' + __FILE__
+      end
+    ensure
+    end
+  end
+end
+__END__