aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v3/sisupod_make.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v3/sisupod_make.rb')
-rw-r--r--lib/sisu/v3/sisupod_make.rb305
1 files changed, 31 insertions, 274 deletions
diff --git a/lib/sisu/v3/sisupod_make.rb b/lib/sisu/v3/sisupod_make.rb
index 984d807d..7b7957ab 100644
--- a/lib/sisu/v3/sisupod_make.rb
+++ b/lib/sisu/v3/sisupod_make.rb
@@ -56,285 +56,42 @@
=end
module SiSU_Doc
- include SiSU_Env
- class Source
- require_relative 'sysenv' # sysenv.rb
+ require_relative 'shared_sisupod_source' # shared_sisupod_source.rb
+ include SiSU_Source
+ require_relative 'sysenv' # sysenv.rb
+ include SiSU_Env
+ class Source < SiSU_Source::SiSUpodSource
require_relative 'response' # response.rb
- require_relative 'particulars' # particulars.rb
- def initialize(opt)
- @opt=opt
- m=/.+\/(?:src\/)?(\S+)/im
- @date=SiSU_Env::InfoDate.new.dt
- @env=SiSU_Env::InfoEnv.new(@opt.fns)
- @ver=SiSU_Env::InfoVersion.instance.get_version
- @ans=SiSU_Response::Response.new
- pod_path="#{@env.processing_path.processing_sisupod(@opt)}"
- @v=(@opt.cmd =~/[VM]/) ? 'v' : ''
- @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
- @file=@particulars.file
- @local_path="#{@file.output_path.sisupod.dir}"
+ def initialize(opt,build=nil,place=nil)
+ super(opt,build,place)
@zipfile=@opt.fno.gsub(/(?:\~\S{2,3})?(\.ss[tm])$/,'\1')
- FileUtils::mkdir_p(pod_path) unless FileTest.directory?(pod_path)
- FileUtils::rm_rf("#{@env.processing_path.processing_sisupod(@opt)}/*") if FileTest.directory?("#{@env.processing_path.processing_sisupod(@opt)}")
- end
- def read
- unless @opt.cmd =~/q/
- @opt.cmd=~/[MVv]/ \
- ? SiSU_Screen::Ansi.new(@opt.cmd,'Share SiSU Document (txz)',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").green_hi_blue
- : SiSU_Screen::Ansi.new(@opt.cmd,'Share SiSU Document (txz)',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").green_title_hi
- end
- unless @opt.fns.empty?
- if @opt.cmd=~/[MVv]/
- SiSU_Screen::Ansi.new(@opt.cmd,'Make sisu document (txz) and place in output directory',"#{@opt.fns} -> file://#{@file.output_path.sisupod.dir}/#{@zipfile}.txz").warn if @opt.cmd =~/[MVv]/
- end
- directories
- sisupod_build
- #sisupod_tar_xz
- else
- if @opt.cmd =~/[MVv]/
- SiSU_Screen::Ansi.new(@opt.cmd,'Make (zip (txz)) of sisu work directory',"#{@env.stub_pwd}\_#{@date}.txz").warn
- SiSU_Screen::Ansi.new(@opt.cmd,'').blue_tab
- end
- ans=@ans.response?('make sisupod of entire directory?')
- if ans; sisupod_zip_directory
- end
- end
- end
- def sisupod_zip_directory
- sisupod_directory="sisupod-#{@env.stub_pwd}-#{@date}.ssp"
- unless File.symlink?('sisupod'); File.symlink(Dir.pwd,'sisupod')
- end
- re_base_dir='^sisupod/([^.][^/]*\.(ssm|ssi|sst)$|_sisu/)'
- re_files='/[a-zA-Z0-9.~_-]+\.(ssm|ssi|sst|rb|css|png|jpg|gif|yaml)$'
- re_ignore='/[.~_-][^/]+$'
- if File.symlink?('sisupod')
- info="SiSU sisupod #{@ver[:version]} directory contents #{sisupod_directory}"
- system(%{
- echo "#{info}"
- echo "#{info}" > sisu_zip.txt
- zip -qz #{sisupod_directory} sisu_zip.txt < sisu_zip.txt
- for I in `find -H sisupod -print | \
- egrep "#{re_base_dir}" | \
- egrep "#{re_files}" | \
- egrep -v "#{re_ignore}" `
- do zip #{sisupod_directory} $I
- done
- })
- else puts "the required systemlink 'sisupod' could not be created on the current directory: remove the file or directory named 'sisupod' within #{Dir.pwd}"
- end
- if @opt.cmd =~/[MVv]/
- SiSU_Screen::Ansi.new(@opt.cmd,'Share SiSU Document (tar xz)',@opt.fns).green_hi_blue
- SiSU_Screen::Ansi.new(@opt.cmd,'Zipped directory (tgz)',sisupod_directory).warn
- SiSU_Screen::Ansi.new('',sisupod_directory).blue_tab
- end
- end
- def directories
- SiSU_Env::InfoEnv.new.sisupod_v3(@opt)
- end
- def select_skin(skin='') #skin loading logic here
- load "#{SiSU_lib}/defaults.rb"
- @skin={}
- skin_path = [
- "#{@env.path.pwd}/_sisu/skin",
- "#{@env.path.home}/.sisu/skin",
- '/etc/sisu/skin',
- "#{@env.processing_path.processing_sisupod(@opt)}/external_document/skin"
- ]
- sk_doc,sk_dir="doc/#{skin}.rb","dir/skin_#{@env.stub_pwd}.rb"
- skin_path.each do |v| #document skin priority 1
- if FileTest.file?("#{v}/#{sk_doc}")
- @skin={ name_path: "#{v}/#{sk_doc}", type: :doc }
- break
- end
- end
- unless @skin.length > 0
- skin_path.each do |v| #directory skin priority 2
- if FileTest.file?("#{v}/#{sk_dir}")
- @skin={ name_path: "#{v}/#{sk_dir}", type: :dir }
- break
- end
- end
- end
- @skin
- end
- 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
- def sisupod_build #see also sisupod in sysenv
- @pwd=Dir.pwd
- @rgx_rb_image=/["']\S*?([a-zA-Z0-9_-]+?\.(?:png|jpg|gif))["']/
- @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/
- @rgx_skin=/^\s+:skin:\s+(\S+)/
- @rgx_doc_import=/^<<\s*(\S+?\.ss[ti])/
- file_array=IO.readlines(@opt.fno,'')
- skin,images,doc_import=[],[],[]
- doc_import_dir=@opt.sub_location
- file_array.each do |f| #% work area
- if f !~/^%+\s/
- skin << f.scan(@rgx_skin).uniq.flatten if f =~@rgx_skin
- 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
- if @opt.fno =~/\.ssm$/
- doc_import << f.scan(@rgx_doc_import) if f =~@rgx_doc_import
- end
- end
- end
- if doc_import.length > 0
- doc_import=doc_import.uniq.flatten
- doc_import.each do |fn|
- file_array=IO.readlines(fn,'')
- file_array.each do |f| #% work area
- if f !~/^%+\s/ \
- and f =~@rgx_image
- images=images_extract(f,images)
- end
- end
- end
- end
- docskin=nil
- if skin \
- and skin.length > 0
- docskin=skin.pop.flatten.join
- skin_source=select_skin(docskin)
- else
- skin_source=select_skin
- end
- docskin_place="#{@env.processing_path.processing_sisupod(@opt)}/doc/_sisu/skin/#{skin_source[:type].to_s}"
- FileUtils::mkdir_p(docskin_place)
- if skin_source[:type] == :dir
- docskin_with_path="#{docskin_place}/skin_#{@env.stub_pwd}.rb"
- docskin=[docskin_with_path.gsub(/.+?\/(skin_\S+?)\.rb/,'\1')]
- docskin='skin_sisupod'
- end
- if skin_source \
- and skin_source[:name_path]
- unless skin_source[:name_path].nil? \
- or skin_source[:name_path].empty?
- if FileTest.file?(skin_source[:name_path])
- FileUtils::cp(skin_source[:name_path],"#{docskin_place}/#{docskin}.rb")
- skinfile_array=IO.readlines(skin_source[:name_path],'')
- para_images=[]
- skinfile_array.each do |f| #% work area
- unless f =~/^%+ / #hmmm
- images << f.scan(@rgx_rb_image).uniq if f =~@rgx_rb_image
- #does not really discriminate, may duplicate images in sisu file, and may take images from default image pool
- end
- end
- else STDERR.puts %{\t*WARN* did not find - "#{skin_source[:name_path]}" [#{__FILE__}:#{__LINE__}]}
- end
- end
- end
- #1. mapping in doc dir?
- #2. need images used by skin, scan skin??
- if images \
- and images.length > 1
- images=images.flatten.uniq
- images.delete_if {|x| x =~/https?:\/\// }
- #images=images.sort
- path_pod="#{@env.processing_path.processing_sisupod(@opt)}"
- path_pod_conf="#{@env.processing_path.processing_sisupod(@opt)}/_sisu"
- images_path_pod="#{path_pod}/image"
- FileUtils::mkdir_p(images_path_pod)
- #unattractive hard coding ... !
- image_path='_sisu/image'
- images_pwd="#{@env.path.pwd}/#{image_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}","#{images_path_pod}/#{i}") if FileTest.file?("#{images_pwd}/#{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} #{images_path_pod} [#{__FILE__}:#{__LINE__}]}
- end
- end
- if doc_import.length > 0 \
- and @opt.fno =~/\.ssm$/
- doc_import.each do |f|
- if FileTest.file?("#{@env.path.pwd}#{doc_import_dir}/#{f}")
- FileUtils::cp("#{@env.path.pwd}#{doc_import_dir}/#{f}","#{@env.processing_path.processing_sisupod(@opt)}/doc/#{@opt.lng}/#{f}")
- else STDERR.puts %{\t*WARN* did not find image - "#{@env.path.pwd}#{doc_import_dir}/#{f}" [#{__FILE__}:#{__LINE__}]}
- end
- end
+ @ans=SiSU_Response::Response.new
+ if @opt.cmd=~/[MVv]/
+ SiSU_Screen::Ansi.new(@opt.cmd,'Assemble source for sisu document',"#{@opt.fns} -> file://#{@file.output_path.sisupod.dir}/#{@zipfile}.txz").warn
end
- x=@env.document_language_versions_found #check multiple document language versions (param not used)
- if x[:f] \
- and x[:f].length > 0 #store multiple document language versions, sisupod
- x[:f].each do |f|
- pth="#{@env.processing_path.processing_sisupod(@opt)}/doc/#{@opt.lng}"
- FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
- if f[:f] =~/\~(\S{2,3})\.ss[tm]$/
- lng_f=$1
- if @opt.lng == lng_f
- if @opt.fno =~/\.ssm$/
- if FileTest.file?("#{@env.path.pwd}#{doc_import_dir}/#{f[:f]}")
- FileUtils::cp("#{@env.path.pwd}#{doc_import_dir}/#{f[:f]}",
- "#{@env.processing_path.processing_sisupod(@opt)}/doc/#{@opt.lng}/#{f[:n]}")
- else STDERR.puts %{\t*WARN* did not find - "#{@env.path.pwd}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]}
- end
- else
- if FileTest.file?("#{@env.path.pwd}/#{f[:f]}")
- FileUtils::cp("#{@env.path.pwd}/#{f[:f]}",
- "#{@env.processing_path.processing_sisupod(@opt)}/doc/#{@opt.lng}/#{f[:n]}")
- else STDERR.puts %{\t*WARN* did not find - "#{@env.path.pwd}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]}
- end
- end
- end
- else
- if @opt.fno =~/\.ssm$/
- if FileTest.file?("#{@env.path.pwd}#{doc_import_dir}/#{f[:f]}")
- FileUtils::cp_r("#{@env.path.pwd}#{doc_import_dir}/#{f[:f]}",
- "#{@env.processing_path.processing_sisupod(@opt)}/doc/#{@opt.lng}/#{f[:n]}")
- else STDERR.puts %{\t*WARN* did not find - "#{@env.path.pwd}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]}
- end
- else
- if FileTest.file?("#{@env.path.pwd}/#{f[:f]}")
- FileUtils::cp("#{@env.path.pwd}/#{f[:f]}",
- "#{@env.processing_path.processing_sisupod(@opt)}/doc/#{@opt.lng}/#{f[:n]}")
- else STDERR.puts %{\t*WARN* did not find - "#{@env.path.pwd}/#{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
def sisupod_tar_xz
- FileUtils::mkdir_p(@file.output_path.sisupod.dir) unless FileTest.directory?(@file.output_path.sisupod.dir)
- tree=(@opt.cmd =~/[vVM]/ \
- && SiSU_Env::SystemCall.new.program_found?('tree')) \
- ? 'tree sisupod'
- : ''
- if FileTest.directory?(@env.processing_path.processing_sisupod(@opt))
- Dir.chdir("#{@env.processing_path.root_dir}/#{@env.processing_path.user}/pods/#{@opt.fns}")
- system(%{
- #{tree}
- tar -cJf #{@zipfile}.txz sisupod
- #echo "#{@file.place_file.sisupod.dir}"
- })
- FileUtils::mv("#{@zipfile}.txz",@file.place_file.sisupod.dir)
- FileUtils::rm_r(Dir.glob("sisupod/*"))
- Dir.chdir(@env.path.pwd)
- SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz").blue_tab if @opt.cmd=~/[MVv]/
- else
- SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz not built").blue_tab if @opt.cmd=~/[MVv]/
+ begin
+ FileUtils::mkdir_p(@file.output_path.sisupod.dir) unless FileTest.directory?(@file.output_path.sisupod.dir)
+ tree=(@opt.cmd =~/[vVM]/ \
+ && SiSU_Env::SystemCall.new.program_found?('tree')) \
+ ? 'tree sisupod'
+ : ''
+ if FileTest.directory?(@path_pod[:fnb])
+ Dir.chdir(@path_pod[:fnb])
+ system(%{
+ #{tree}
+ tar -cJf #{@zipfile}.txz sisupod
+ #echo "#{@file.place_file.sisupod.dir}"
+ })
+ FileUtils::mv("#{@zipfile}.txz",@file.place_file.sisupod.dir)
+ Dir.chdir(@env.path.pwd)
+ SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz").blue_tab if @opt.cmd=~/[MVv]/
+ else
+ SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz not built").blue_tab if @opt.cmd=~/[MVv]/
+ end
+ rescue
+ ensure
end
end
end