From c36e976c00bac90fd01fe12f6c9bc632e3b209b7 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 10 Mar 2010 16:43:15 -0500 Subject: epub, html: make robust where missing param values --- lib/sisu/v2/epub.rb | 34 ++++++++++++++++++++++++++-------- lib/sisu/v2/epub_format.rb | 17 ++++++++++++++--- lib/sisu/v2/epub_segments.rb | 5 ++++- lib/sisu/v2/html.rb | 15 +++++++++++---- 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/lib/sisu/v2/epub.rb b/lib/sisu/v2/epub.rb index 6df06025..e6ab1e12 100644 --- a/lib/sisu/v2/epub.rb +++ b/lib/sisu/v2/epub.rb @@ -499,7 +499,8 @@ module SiSU_EPUB segtoc << format_head_toc.head #<< ads.div.major toc_shared << format_head_toc.toc_head_escript if SiSU_EPUB_Format::Head_toc.method_defined? :toc_head_escript segtoc << format_head_toc.toc_head_escript if SiSU_EPUB_Format::Head_toc.method_defined? :toc_head_escript - if @md.rights.all + if defined? @md.rights.all \ + and @md.rights.all rights=format_head_toc.rights.all rights=SiSU_EPUB_Tune::Clean_xhtml.new(rights).clean end @@ -517,7 +518,8 @@ module SiSU_EPUB format_txt_obj=SiSU_EPUB_Format::Format_text_object.new(@md,txt_obj) toc_shared << format_txt_obj.center_bold segtoc << format_txt_obj.center_bold - if @md.creator.author + if defined? @md.creator.author \ + and @md.creator.author creator_endnote=@md.creator.author.gsub(/(\*+)/,%{ \\1}) tmp_head=creator_endnote + "\n" txt_obj={:txt =>tmp_head} @@ -529,21 +531,34 @@ module SiSU_EPUB segtoc << format_head_toc.copyat segtoc << seg_toc_band tmp_head=nil - if @md.prefix_a + if defined? @md.prefix_a \ + and @md.prefix_a tmp_head ||= %{#{@md.prefix_a}\n} toc_shared << tmp_head.dup segtoc << tmp_head.dup end tmp_head=nil toc_shared << @links_guide_toc - toc_shared << rights if @md.rights.all - toc_shared << prefix_b if @md.prefix_b + if defined? @md.rights.all \ + and @md.rights.all + toc_shared << rights + end + if defined? @md.prefix_b \ + and @md.prefix_b + toc_shared << prefix_b + end #Table of Contents added/appended here toc_shared << @toc[:scr] segtoc << @links_guide_toc segtoc << @toc[:seg] - segtoc << rights if @md.rights.all - segtoc << prefix_b if @md.prefix_b + if defined? @md.rights.all \ + and @md.rights.all + segtoc << rights + end + if defined? @md.prefix_b \ + and @md.prefix_b + segtoc << prefix_b + end #Segtoc tail added here segtoc << seg_toc_band_bottom segtoc << format_head_toc.xhtml_close @@ -618,7 +633,10 @@ module SiSU_EPUB def images img_pth=@md.env.path.image_source_local_tex @md.ec[:image].each do |x| - cp("#{img_pth}/#{x}","#{@md.env.path.epub}/OPS/image") if FileTest.directory?("#{@md.env.path.epub}/OPS/image") + if FileTest.directory?("#{@md.env.path.epub}/OPS/image") \ + and FileTest.file?("#{img_pth}/#{x}") + cp("#{img_pth}/#{x}","#{@md.env.path.epub}/OPS/image") + end end end def concordance diff --git a/lib/sisu/v2/epub_format.rb b/lib/sisu/v2/epub_format.rb index 5599a435..498912a3 100644 --- a/lib/sisu/v2/epub_format.rb +++ b/lib/sisu/v2/epub_format.rb @@ -1024,17 +1024,28 @@ WOK WOK end def metadata #metadata dc - illustrator=if defined? @md.creator.illustrator and @md.creator.illustrator =~/\S+/ + author=if defined? @md.creator.author \ + and @md.creator.author =~/\S+/ + %{\n #{@md.creator.author}} + else '' + end + illustrator=if defined? @md.creator.illustrator \ + and @md.creator.illustrator =~/\S+/ %{\n #{@md.creator.illustrator}} else '' end + rights=if defined? @md.rights.all \ + and @md.rights.all =~/\S+/ + %{\n #{@md.rights.all}} + else '' + end < #{@md.title.full} - #{@md.creator.author}#{illustrator} + #{author}#{illustrator} en-US ... - #{@md.rights.all} + #{rights} urn:uuid:#{@md.dgst[1]} WOK diff --git a/lib/sisu/v2/epub_segments.rb b/lib/sisu/v2/epub_segments.rb index 3f402c92..6436612c 100644 --- a/lib/sisu/v2/epub_segments.rb +++ b/lib/sisu/v2/epub_segments.rb @@ -300,7 +300,10 @@ WOK end @p_num ||= '' if @@is1==1 - @author=%{#{@md.creator.author}\n} if @md.creator.author.to_s =~/\S/ + if defined? @md.creator.author \ + and @md.creator.author + @author=%{#{@md.creator.author}\n} + end @@seg[:nav] << format_head_seg.navigation_band(@@segtocband) ocn=if @@heading1[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]; $1 #fix else '' diff --git a/lib/sisu/v2/html.rb b/lib/sisu/v2/html.rb index 4959d683..834eefa1 100644 --- a/lib/sisu/v2/html.rb +++ b/lib/sisu/v2/html.rb @@ -533,7 +533,7 @@ WOK format_txt_obj=SiSU_HTML_Format::Format_text_object.new(@md,txt_obj) toc_shared << format_txt_obj.center_bold @segtoc << format_txt_obj.center_bold - if @md.creator.author + if defined? @md.creator.author creator_endnote=@md.creator.author.gsub(/(\*+)/,%{ \\1}) tmp_head=creator_endnote + "\n" txt_obj={:txt =>tmp_head} @@ -553,13 +553,20 @@ WOK end tmp_head=nil toc_shared << @links_guide_toc - toc_shared << rights if @md.rights.all - toc_shared << prefix_b if @md.prefix_b + if defined? @md.rights.all #and ? @md.rights.all + toc_shared << rights + end + if defined? @md.prefix_b + toc_shared << prefix_b + end #Table of Contents added/appended here toc_shared << @toc[:scr] @segtoc << @links_guide_toc @segtoc << @toc[:seg] - @segtoc << rights if @md.rights.all + if defined? @md.rights.all \ + and not @md.rights.all.empty? + @segtoc << rights + end @segtoc << prefix_b if @md.prefix_b #Segtoc tail added here @segtoc << "

\n" #bugfix sort later DEBUGNOW -- cgit v1.2.3