Class: SiSU_XHTML_EPUB2::Source::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/xhtml_epub2.rb

Instance Method Summary collapse

Constructor Details

#initialize(md, output = '') ⇒ Output

Returns a new instance of Output.



730
731
732
733
734
735
736
# File 'lib/sisu/xhtml_epub2.rb', line 730

def initialize(md,output='')
  @md,@output=md,output
  @epub_doc="#{@md.fnb}.epub"
  @epub_header=SiSU_XHTML_EPUB2_Format::HeadInformation.new(@md)
  @make=SiSU_Env::ProcessingSettings.new(@md)
  @make_file=SiSU_Env::CreateFile.new(@md.fns)
end

Instance Method Details

#concordanceObject



809
810
811
# File 'lib/sisu/xhtml_epub2.rb', line 809

def concordance
  SiSU_XHTML_EPUB2_Concordance::Source.new(@md.opt).read
end

#cssObject



755
756
757
758
759
# File 'lib/sisu/xhtml_epub2.rb', line 755

def css
  out=@make_file.epub.xhtml_css
  out << SiSU_XHTML_EPUB2_Format::CSS.new.css_epub_xhtml
  out.close
end

#epub_metadata_opfObject



775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
# File 'lib/sisu/xhtml_epub2.rb', line 775

def 
  begin
    out=@make_file.epub.
    @output.each do |para|
      unless para =~/\A\s*\Z/
        out.puts para
      end
    end
    out.close
  rescue
    SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
      __LINE__.to_s + ':' + __FILE__
    end
  end
end

#epub_toc_ncxObject



760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# File 'lib/sisu/xhtml_epub2.rb', line 760

def epub_toc_ncx
  begin
    out=@make_file.epub.toc_ncx
    @output.each do |para|
      unless para =~/\A\s*\Z/
        out.puts para
      end
    end
    out.close
  rescue
    SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
      __LINE__.to_s + ':' + __FILE__
    end
  end
end

#imagesObject



790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
# File 'lib/sisu/xhtml_epub2.rb', line 790

def images
  img_pth=@md.env.path.image_source_include
  img_src_pth=unless @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/
    @md.file.output_path.epub.rel_image
  else
    pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1]
    pt + '/image'
  end
  @md.ec[:image].each do |x|
    if FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \
    && FileTest.file?("#{img_src_pth}/#{x}")
      FileUtils::cp("#{img_src_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image")
    elsif FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \
    && FileTest.file?("#{img_pth}/#{x}")
      FileUtils::cp("#{img_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image")
    else STDERR.puts %{\t*WARN* did not find image - "#{x}" in #{img_src_pth} or #{img_pth} [#{__FILE__}:#{__LINE__}]}
    end
  end
end

#make_cover_imageObject



830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
# File 'lib/sisu/xhtml_epub2.rb', line 830

def make_cover_image
  begin
    if @md.make.cover_image? \
    and @md.make.cover_image.is_a?(Hash) \
    and @md.make.cover_image[:cover] =~/\S+/
      filename_xhtml=@make_file.epub.xhtml_cover_image
      cover_image=<<WOK
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Cover</title>
    <meta http-equiv="Content-Type" content='text/html; charset=utf-8' />
    <link rel="stylesheet" href="css/xhtml.css" type="text/css" />
    <style type="text/css"> img { max-width: 100%; } </style>
  </head>
  <body xml:lang="en">
    <div class="svg_outer">
<div class="svg_inner">
  <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xl="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 #{@md.make.cover_image[:w]} #{@md.make.cover_image[:h]}" preserveAspectRatio="xMidYMid meet">
  <image width="#{@md.make.cover_image[:w]}" height="#{@md.make.cover_image[:h]}" xl:href="image/#{@md.make.cover_image[:cover]}" />
  </svg>
</div>
    </div>
  </body>
</html>
WOK
      filename_xhtml.puts cover_image,"\n"
      filename_xhtml.close
    end
  rescue
    SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
      __LINE__.to_s + ':' + __FILE__
    end
  end
end

#make_segtocObject



867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
# File 'lib/sisu/xhtml_epub2.rb', line 867

def make_segtoc
  begin
    if @make.build.toc?
      filename_xhtml=@make_file.epub.xhtml_index
      @output.each do |para|
        para=para.strip
        unless para =~/\A\s*\Z/
          filename_xhtml.puts para,"\n"
        end
      end
      filename_xhtml.close
    end
  rescue
    SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
      __LINE__.to_s + ':' + __FILE__
    end
  end
end

#metainf_containerObject

container.xml file in META-INF directory



750
751
752
753
754
# File 'lib/sisu/xhtml_epub2.rb', line 750

def metainf_container #container.xml file in META-INF directory
  out=@make_file.epub.metainf_cont
  out<<@epub_header.metainf_container
  out.close
end

#mimetypeObject



745
746
747
748
749
# File 'lib/sisu/xhtml_epub2.rb', line 745

def mimetype
  out=@make_file.epub.mimetype
  out<<@epub_header.mimetype
  out.close
end

#output_zipObject



812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
# File 'lib/sisu/xhtml_epub2.rb', line 812

def output_zip
  FileUtils::mkdir_p(@md.file.output_path.epub.dir) unless FileTest.directory?(@md.file.output_path.epub.dir)
  if FileTest.directory?(@md.env.processing_path.epub) \
  and SiSU_Env::SystemCall.new.zip
    pwd=Dir.pwd
    Dir.chdir(@md.env.processing_path.epub)
    system("
      zip -qXr9D #{@epub_doc} *
    ")
    FileUtils::mv(@epub_doc, @md.file.place_file.epub.dir)
    Dir.chdir(pwd)
    unless @md.opt.act[:maintenance][:set]==:on
      FileUtils::rm_r(@md.env.processing_path.epub)
    end
  else
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark('*EXITED epub* zip program not found') unless SiSU_Env::SystemCall.new.zip
  end
end

#songsheetObject



737
738
739
740
741
742
743
744
# File 'lib/sisu/xhtml_epub2.rb', line 737

def songsheet
  mimetype
  metainf_container
  css
  images if @md.ec[:image]
 #concordance #uncomment to enable inclusion of concordance file
  output_zip
end