From 4ef1c3099119cedff245acfe1ef26e5829e5bf62 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 15 Jul 2014 19:02:12 -0400 Subject: v5 v6: document images (more to clean up) --- data/doc/sisu/CHANGELOG_v5 | 1 + data/doc/sisu/CHANGELOG_v6 | 1 + lib/sisu/v5/options.rb | 12 ++++++------ lib/sisu/v5/shared_markup_alt.rb | 7 ++++++- lib/sisu/v5/src_shared.rb | 4 +--- lib/sisu/v5/sysenv.rb | 18 ++++++++++++++---- lib/sisu/v5/utils.rb | 7 +++++++ lib/sisu/v5/xml_docbook5.rb | 22 ++++++++++++++++++++++ lib/sisu/v6/options.rb | 12 ++++++------ lib/sisu/v6/shared_markup_alt.rb | 7 ++++++- lib/sisu/v6/src_shared.rb | 4 +--- lib/sisu/v6/sysenv.rb | 18 ++++++++++++++---- lib/sisu/v6/utils.rb | 7 +++++++ lib/sisu/v6/xml_docbook5.rb | 22 ++++++++++++++++++++++ 14 files changed, 114 insertions(+), 28 deletions(-) diff --git a/data/doc/sisu/CHANGELOG_v5 b/data/doc/sisu/CHANGELOG_v5 index 1f529617..f6c18141 100644 --- a/data/doc/sisu/CHANGELOG_v5 +++ b/data/doc/sisu/CHANGELOG_v5 @@ -57,6 +57,7 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_5.5.1.orig.tar.xz * general, document parts * css * base images + * document images %% 5.5.0.orig.tar.xz (2014-07-11:27/5) http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/sisu_5.5.0 diff --git a/data/doc/sisu/CHANGELOG_v6 b/data/doc/sisu/CHANGELOG_v6 index 6afff641..ddf381fd 100644 --- a/data/doc/sisu/CHANGELOG_v6 +++ b/data/doc/sisu/CHANGELOG_v6 @@ -47,6 +47,7 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_6.1.1.orig.tar.xz * general, document parts * css * base images + * document images %% 6.1.0.orig.tar.xz (2014-07-11:27/5) http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=log;h=refs/tags/sisu_6.1.0 diff --git a/lib/sisu/v5/options.rb b/lib/sisu/v5/options.rb index bc4d7da0..f40f0388 100644 --- a/lib/sisu/v5/options.rb +++ b/lib/sisu/v5/options.rb @@ -154,20 +154,20 @@ module SiSU_Commandline end end class Options - attr_accessor :cmd,:mod,:act,:dir_structure_by,:lingual,:f_pths,:files,:files_mod,:call_path,:base_path,:base_stub,:sub_location,:paths,:lngs,:f_pth,:pth,:fno,:fns,:fnb,:fnc,:fng,:fncb,:lng,:lng_base,:what,:make_instructions,:make_instructions_pod + attr_accessor :cmd,:mod,:act,:dir_structure_by,:lingual,:f_pths,:files,:files_mod,:call_path,:base_path,:base_stub,:sub_location,:image_src_path,:paths,:lngs,:f_pth,:pth,:fno,:fns,:fnb,:fnc,:fng,:fncb,:lng,:lng_base,:what,:make_instructions,:make_instructions_pod @@act=nil def initialize(a,call_path) - @cmd=@f_pth=@pth=@fno=@fns=@fnb=@fnc=@fng=@fncb=@what=@lng=@lng_base=@call_path=@base_path=@base_stub=@sub_location='' + @cmd=@f_pth=@pth=@fno=@fns=@fnb=@fnc=@fng=@fncb=@what=@lng=@lng_base=@call_path=@base_path=@base_stub=@image_src_path=@sub_location='' @f_pths,@files,@files_mod,@paths,@mod,@act=Array.new(5){[]} @env=SiSU_Env::InfoEnv.new @lng_base=@env.language_default_set @dir_structure_by=SiSU_Env::EnvCall.new.output_dir_structure.by? @lingual=SiSU_Env::EnvCall.new.mono_multi_lingual? @call_path=call_path - @base_path=SiSU_Utils::Path.new.base_markup(call_path) - r=Px[:lng_lst_rgx] - u=/.+?\/([^\/]+)(?:\/(?:#{r})$|$)/ - @base_stub=@base_path.gsub(u,'\1') + pth=SiSU_Utils::Path.new(call_path) + @base_path=pth.base_markup + @base_stub=pth.base_markup_stub + @image_src_path=pth.image_src @a=sisu_glob_rules(a) @a.freeze @make_instructions=HeaderCommon.new.sisu_document_make_instructions diff --git a/lib/sisu/v5/shared_markup_alt.rb b/lib/sisu/v5/shared_markup_alt.rb index 1fb078c6..92db52f3 100644 --- a/lib/sisu/v5/shared_markup_alt.rb +++ b/lib/sisu/v5/shared_markup_alt.rb @@ -279,7 +279,12 @@ module SiSU_TextRepresentation elsif FileTest.file?("#{@env.path.image_source_include}/#{i}") @env.path.image_source_include else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"ERROR - image:", %{"#{i}" missing}, "search locations: #{@env.path.image_source_include_local}, #{@env.path.image_source_include_remote} and #{@env.path.image_source_include}").error2 unless @md.opt.act[:quiet][:set]==:on + SiSU_Screen::Ansi.new( + @md.opt.act[:color_state][:set], + "ERROR - image:", + %{"#{i}" missing}, + "search locations: #{@env.path.image_source_include_local}, #{@env.path.image_source_include_remote} and #{@env.path.image_source_include}" + ).error2 unless @md.opt.act[:quiet][:set]==:on nil end img_type = /\S+\.(png|jpg|gif)/.match(i)[1] diff --git a/lib/sisu/v5/src_shared.rb b/lib/sisu/v5/src_shared.rb index 03d902fd..068120f5 100644 --- a/lib/sisu/v5/src_shared.rb +++ b/lib/sisu/v5/src_shared.rb @@ -157,9 +157,7 @@ module SiSU_Source images.delete_if {|x| x =~/https?:\/\// } #images=images.sort FileUtils::mkdir_p(@path_pod[:image]) - #unattractive hard coding ... ! - image_path='_sisu/image' - images_pwd="#{@opt.base_path}/#{image_path}" + 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 diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index 324f96e0..8d73e832 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -2716,7 +2716,11 @@ WOK else if @@local_image==true cmd=@cmd ? @cmd : '' - SiSU_Screen::Ansi.new(cmd,"WARNING - no local image directory or images:", defaults[:image_local] ).warn unless cmd =~/q/ + SiSU_Screen::Ansi.new( + cmd, + "WARNING - no local image directory or images:", + defaults[:image_local] + ).warn unless cmd =~/q/ @@local_image=false end url.images @@ -2727,14 +2731,20 @@ WOK if @@image_flag images=Dir.glob("#{image_external}/*.{png,jpg,gif}") pth="#{path.webserv}/#{@base_markup_dir_stub}" - FileUtils::mkdir_p("#{pth}/_sisu/image_external") unless FileTest.directory?("#{pth}/_sisu/image_external") - images.each { |i| File.install(i,"#{pth}/#{i}") } unless images.length > 0 + FileUtils::mkdir_p("#{pth}/_sisu/image_external") \ + unless FileTest.directory?("#{pth}/_sisu/image_external") + images.each { |i| File.install(i,"#{pth}/#{i}") } \ + unless images.length > 0 @@image_flag=false end "#{Xx[:html_relative2]}/_sisu/image_external" else if @@local_image==true - SiSU_Screen::Ansi.new(@cmd,"WARNING - image directory for external images or no such images:", :image_external ).warn unless @cmd =~/q/ + SiSU_Screen::Ansi.new( + @cmd, + "WARNING - image directory for external images or no such images:", + :image_external + ).warn unless @cmd =~/q/ @@local_image=false end url.images_external diff --git a/lib/sisu/v5/utils.rb b/lib/sisu/v5/utils.rb index 7db4143a..4d30d031 100644 --- a/lib/sisu/v5/utils.rb +++ b/lib/sisu/v5/utils.rb @@ -184,6 +184,13 @@ module SiSU_Utils m=/.+\/(?:src\/)?(\S+)/im base_markup[m,1] end + def image_src + if base_markup =~/sisupod\/doc[\/]?$/ + base_markup.gsub(/\/doc[\/]?$/,'/image') + elsif FileTest.directory?("#{base_markup}/_sisu/image") + "#{base_markup}/_sisu/image" + end + end def bmd base_markup end diff --git a/lib/sisu/v5/xml_docbook5.rb b/lib/sisu/v5/xml_docbook5.rb index 0fb6ee8d..62b8845c 100644 --- a/lib/sisu/v5/xml_docbook5.rb +++ b/lib/sisu/v5/xml_docbook5.rb @@ -128,8 +128,30 @@ module SiSU_XML_Docbook_Book #extract_endnotes data=markup_text(data) structure_build_collapsed(data) + document_images if @md.ec[:image] and @md.ec[:image].length > 0 #tail end + def document_images + img_pth={ + src: @md.opt.image_src_path, + dest: @md.env.path.webserv + '/_sisu/image', + } + unless FileTest.directory?(img_pth[:dest]) + #mkdir? + end + if FileTest.directory?(img_pth[:dest]) + @md.ec[:image].each do |x| + img={ + src: "#{img_pth[:src]}/#{x}", + dest: "#{img_pth[:dest]}/#{x}", + } + if FileTest.file?(img[:src]) + FileUtils::cp(img[:src],img[:dest]) + else p "Not Found: #{img[:src]}/#{x}" + end + end + end + end def spaces Ax[:spaces] end diff --git a/lib/sisu/v6/options.rb b/lib/sisu/v6/options.rb index eed42e51..104243a3 100644 --- a/lib/sisu/v6/options.rb +++ b/lib/sisu/v6/options.rb @@ -154,20 +154,20 @@ module SiSU_Commandline end end class Options - attr_accessor :cmd,:mod,:act,:dir_structure_by,:lingual,:f_pths,:files,:files_mod,:call_path,:base_path,:base_stub,:sub_location,:paths,:lngs,:f_pth,:pth,:fno,:fns,:fnb,:fnc,:fng,:fncb,:lng,:lng_base,:what,:make_instructions,:make_instructions_pod + attr_accessor :cmd,:mod,:act,:dir_structure_by,:lingual,:f_pths,:files,:files_mod,:call_path,:base_path,:base_stub,:sub_location,:image_src_path,:paths,:lngs,:f_pth,:pth,:fno,:fns,:fnb,:fnc,:fng,:fncb,:lng,:lng_base,:what,:make_instructions,:make_instructions_pod @@act=nil def initialize(a,call_path) - @cmd=@f_pth=@pth=@fno=@fns=@fnb=@fnc=@fng=@fncb=@what=@lng=@lng_base=@call_path=@base_path=@base_stub=@sub_location='' + @cmd=@f_pth=@pth=@fno=@fns=@fnb=@fnc=@fng=@fncb=@what=@lng=@lng_base=@call_path=@base_path=@base_stub=@image_src_path=@sub_location='' @f_pths,@files,@files_mod,@paths,@mod,@act=Array.new(5){[]} @env=SiSU_Env::InfoEnv.new @lng_base=@env.language_default_set @dir_structure_by=SiSU_Env::EnvCall.new.output_dir_structure.by? @lingual=SiSU_Env::EnvCall.new.mono_multi_lingual? @call_path=call_path - @base_path=SiSU_Utils::Path.new.base_markup(call_path) - r=Px[:lng_lst_rgx] - u=/.+?\/([^\/]+)(?:\/(?:#{r})$|$)/ - @base_stub=@base_path.gsub(u,'\1') + pth=SiSU_Utils::Path.new(call_path) + @base_path=pth.base_markup + @base_stub=pth.base_markup_stub + @image_src_path=pth.image_src @a=sisu_glob_rules(a) @a.freeze @make_instructions=HeaderCommon.new.sisu_document_make_instructions diff --git a/lib/sisu/v6/shared_markup_alt.rb b/lib/sisu/v6/shared_markup_alt.rb index 3bf3c7e4..1586f0c2 100644 --- a/lib/sisu/v6/shared_markup_alt.rb +++ b/lib/sisu/v6/shared_markup_alt.rb @@ -279,7 +279,12 @@ module SiSU_TextRepresentation elsif FileTest.file?("#{@env.path.image_source_include}/#{i}") @env.path.image_source_include else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"ERROR - image:", %{"#{i}" missing}, "search locations: #{@env.path.image_source_include_local}, #{@env.path.image_source_include_remote} and #{@env.path.image_source_include}").error2 unless @md.opt.act[:quiet][:set]==:on + SiSU_Screen::Ansi.new( + @md.opt.act[:color_state][:set], + "ERROR - image:", + %{"#{i}" missing}, + "search locations: #{@env.path.image_source_include_local}, #{@env.path.image_source_include_remote} and #{@env.path.image_source_include}" + ).error2 unless @md.opt.act[:quiet][:set]==:on nil end img_type = /\S+\.(png|jpg|gif)/.match(i)[1] diff --git a/lib/sisu/v6/src_shared.rb b/lib/sisu/v6/src_shared.rb index 495cc584..514e0458 100644 --- a/lib/sisu/v6/src_shared.rb +++ b/lib/sisu/v6/src_shared.rb @@ -157,9 +157,7 @@ module SiSU_Source images.delete_if {|x| x =~/https?:\/\// } #images=images.sort FileUtils::mkdir_p(@path_pod[:image]) - #unattractive hard coding ... ! - image_path='_sisu/image' - images_pwd="#{@opt.base_path}/#{image_path}" + 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 diff --git a/lib/sisu/v6/sysenv.rb b/lib/sisu/v6/sysenv.rb index f1b69edc..72aaf2b9 100644 --- a/lib/sisu/v6/sysenv.rb +++ b/lib/sisu/v6/sysenv.rb @@ -2716,7 +2716,11 @@ WOK else if @@local_image==true cmd=@cmd ? @cmd : '' - SiSU_Screen::Ansi.new(cmd,"WARNING - no local image directory or images:", defaults[:image_local] ).warn unless cmd =~/q/ + SiSU_Screen::Ansi.new( + cmd, + "WARNING - no local image directory or images:", + defaults[:image_local] + ).warn unless cmd =~/q/ @@local_image=false end url.images @@ -2727,14 +2731,20 @@ WOK if @@image_flag images=Dir.glob("#{image_external}/*.{png,jpg,gif}") pth="#{path.webserv}/#{@base_markup_dir_stub}" - FileUtils::mkdir_p("#{pth}/_sisu/image_external") unless FileTest.directory?("#{pth}/_sisu/image_external") - images.each { |i| File.install(i,"#{pth}/#{i}") } unless images.length > 0 + FileUtils::mkdir_p("#{pth}/_sisu/image_external") \ + unless FileTest.directory?("#{pth}/_sisu/image_external") + images.each { |i| File.install(i,"#{pth}/#{i}") } \ + unless images.length > 0 @@image_flag=false end "#{Xx[:html_relative2]}/_sisu/image_external" else if @@local_image==true - SiSU_Screen::Ansi.new(@cmd,"WARNING - image directory for external images or no such images:", :image_external ).warn unless @cmd =~/q/ + SiSU_Screen::Ansi.new( + @cmd, + "WARNING - image directory for external images or no such images:", + :image_external + ).warn unless @cmd =~/q/ @@local_image=false end url.images_external diff --git a/lib/sisu/v6/utils.rb b/lib/sisu/v6/utils.rb index 8995a860..4e7cb6e3 100644 --- a/lib/sisu/v6/utils.rb +++ b/lib/sisu/v6/utils.rb @@ -184,6 +184,13 @@ module SiSU_Utils m=/.+\/(?:src\/)?(\S+)/im base_markup[m,1] end + def image_src + if base_markup =~/sisupod\/doc[\/]?$/ + base_markup.gsub(/\/doc[\/]?$/,'/image') + elsif FileTest.directory?("#{base_markup}/_sisu/image") + "#{base_markup}/_sisu/image" + end + end def bmd base_markup end diff --git a/lib/sisu/v6/xml_docbook5.rb b/lib/sisu/v6/xml_docbook5.rb index 3baa21d9..f105eab9 100644 --- a/lib/sisu/v6/xml_docbook5.rb +++ b/lib/sisu/v6/xml_docbook5.rb @@ -128,8 +128,30 @@ module SiSU_XML_Docbook_Book #extract_endnotes data=markup_text(data) structure_build_collapsed(data) + document_images if @md.ec[:image] and @md.ec[:image].length > 0 #tail end + def document_images + img_pth={ + src: @md.opt.image_src_path, + dest: @md.env.path.webserv + '/_sisu/image', + } + unless FileTest.directory?(img_pth[:dest]) + #mkdir? + end + if FileTest.directory?(img_pth[:dest]) + @md.ec[:image].each do |x| + img={ + src: "#{img_pth[:src]}/#{x}", + dest: "#{img_pth[:dest]}/#{x}", + } + if FileTest.file?(img[:src]) + FileUtils::cp(img[:src],img[:dest]) + else p "Not Found: #{img[:src]}/#{x}" + end + end + end + end def spaces Ax[:spaces] end -- cgit v1.2.3