# encoding: utf-8 =begin * Name: SiSU ** Description: documents, structuring, processing, publishing, search *** epub generation, processing ** 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, 2016 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] ** 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/xhtml_epub2.rb;hb=HEAD] =end module SiSU_XHTML_EPUB2 begin require 'pstore' rescue LoadError SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error('pstore NOT FOUND (LoadError)') end require_relative 'se_hub_particulars' # se_hub_particulars.rb include SiSU_Particulars require_relative 'xml_shared' # xml_shared.rb include SiSU_XML_Munge require_relative 'xhtml_table' # xhtml_table.rb require_relative 'xhtml_epub2_format' # xhtml_epub2_format.rb include SiSU_XHTML_EPUB2_Format require_relative 'xhtml_epub2_segments' # xhtml_epub2_segments.rb include SiSU_XHTML_EPUB2_Seg require_relative 'xhtml_epub2_tune' # xhtml_epub2_tune.rb include SiSU_XHTML_EPUB2_Tune require_relative 'xhtml_epub2_concordance' # xhtml_epub2_concordance.rb require_relative 'xhtml_epub2_persist' # xhtml_epub2_persist.rb class Source def initialize(opt) @opt=opt @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) end def read begin songsheet ensure Dir.chdir(@opt.f_pth[:pth]) end end def songsheet begin @md=@particulars.md @fnb=@md.fnb @env=@particulars.env unless @opt.act[:quiet][:set]==:on tool=(@opt.act[:verbose][:set]==:on \ || @opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) \ ? "#{@env.program.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" (@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], 'EPUB', tool ).green_hi_blue : SiSU_Screen::Ansi.new( @opt.act[:color_state][:set], 'EPUB', tool ).green_title_hi if (@opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new( @opt.act[:color_state][:set], @opt.fns, "#{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" ).flow end end @env.processing_path.epub_bld #(@md) @env.processing_path.epub_cp_images(@md) data=nil SiSU_Env::FileOp.new(@md).mkdir.output.epub @tuned_file_array=SiSU_XHTML_EPUB2::Source::XHTML_Environment.new(@particulars).tuned_file_instructions data=@tuned_file_array per=SiSU_XHTML_EPUB2::Source::Toc.new(@md,data).songsheet data=@tuned_file_array SiSU_XHTML_EPUB2::Source::ScrollHeadAndSegToc.new(@md,per).in_common #watch SiSU_XHTML_EPUB2::Source::Seg.new(@md,data).songsheet SiSU_XHTML_EPUB2::Source::Output.new(@md).songsheet rescue SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do __LINE__.to_s + ':' + __FILE__ end ensure unless (@opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) texfiles=Dir["#{@env.processing_path.tune}/#{@opt.fns}*"] texfiles.each do |f| if FileTest.file?(f) File.unlink(f) end end end SiSU_Env::Clear.new(@opt.selections.str,@opt.fns).param_instantiate @@flag,@@scr,@@seg,@@seg_endnotes,@@seg_subtoc={},{},{},{},{} @@tracker=0 @@seg_name,@@seg_name_html,@@seg_subtoc_array,@@seg_endnotes_array,@@tablefoot=Array.new(5){[]} @@filename_seg,@@seg_url,@@to_lev4,@@get_hash_to,@@get_hash_fn='','','','','' end end private class XHTML_Environment def initialize(particulars) @particulars=particulars @md,@env=particulars.md,particulars.env @env,@css=particulars.env,SiSU_Style::CSS.new end def directories SiSU_Env::FileOp.new(@md).mkdir.output.epub end def tuned_file_instructions @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) directories ao_array=@particulars.ao_array # ao file drawn here @tuned_file_array=SiSU_XHTML_EPUB2_Tune::Tune.new(ao_array,@md).songsheet @tuned_file_array end end class Endnotes include SiSU_XHTML_EPUB2_Format def initialize(md,data) @md,@data=md,data end def scroll @scr_endnotes=[] @data.each do |dob| pg=dob.dup unless pg.is ==:code if pg.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+ / endnote_array=[] if pg.obj=~/#{Mx[:en_a_o]}[\d*+].+?#{Mx[:en_a_c]}/m endnote_array = pg.obj.scan(/#{Mx[:en_a_o]}[\d*+]+(.+?)#{Mx[:en_a_c]}/m) end if pg.obj=~/#{Mx[:en_b_o]}[\d*]+\s.+?#{Mx[:en_b_c]}/m endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d*]+(.+?)#{Mx[:en_b_c]}/m) end if pg.obj=~/#{Mx[:en_b_o]}[\d+]+\s.+?#{Mx[:en_b_c]}/m endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d+]+(.+?)#{Mx[:en_b_c]}/m) end endnote_array.flatten.each do |note| txt_obj={ txt: note } format_scroll=SiSU_XHTML_EPUB2_Format::FormatScroll.new(@md,txt_obj) @scr_endnotes << format_scroll.endnote_body end end end end @scr_endnotes end end class Toc @@seg_url='' @@firstseg=nil def initialize(md=nil,data='') @md,@data=md,data @epub=SiSU_XHTML_EPUB2_Format::HeadInformation.new(@md) @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) if @md @make=SiSU_Env::ProcessingSettings.new(@md) @per=SiSU_XHTML_EPUB2_Persist::PersistTOC.new end def songsheet #extracts toc for scroll & seg begin if (@md.opt.act[:verbose][:set]==:on \ || @md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new( @md.opt.act[:color_state][:set], 'Toc' ).txt_grey end toc=nil @@firstseg=nil SiSU_XHTML_EPUB2_Persist::PersistTOC.new.persist_init md_opf_a_content,md_opf_a_spine,md_opf_a_guide=[],[],[] @nav_no=0 @s_a_no,@s_b_no,@s_c_no,@s_d_no,@lv5_no,@lv6_no=0,0,0,0,0,0 @per.ncx << @epub.toc_ncx.open #epub ncx navmap @per.ncx << @epub.toc_ncx.head_open << @epub.toc_ncx.head << @epub.toc_ncx.head_close @per.ncx << @epub.toc_ncx.doc_title << @epub.toc_ncx.doc_author @per.ncx << @epub.toc_ncx.navmap_open @per.opf << @epub.metadata_opf.package_open @per.opf << @epub.metadata_opf.metadata @per.opf << @epub.metadata_opf.manifest_open @per.seg << %{