From 9700518408f388c9f070894f7986d94d80e4c070 Mon Sep 17 00:00:00 2001
From: Ralph Amissah
Date: Tue, 3 Dec 2013 00:30:50 -0500
Subject: v5: xml, fictionbook
---
lib/sisu/v5/xml_fictionbook2.rb | 366 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 366 insertions(+)
create mode 100644 lib/sisu/v5/xml_fictionbook2.rb
(limited to 'lib/sisu/v5/xml_fictionbook2.rb')
diff --git a/lib/sisu/v5/xml_fictionbook2.rb b/lib/sisu/v5/xml_fictionbook2.rb
new file mode 100644
index 00000000..8ee2fb89
--- /dev/null
+++ b/lib/sisu/v5/xml_fictionbook2.rb
@@ -0,0 +1,366 @@
+# encoding: utf-8
+=begin
+
+ * Name: SiSU
+
+ * Description: a framework for document structuring, publishing and search
+
+ * Author: Ralph Amissah
+
+ * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013 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 .
+
+ If you have Internet connection, the latest version of the GPL should be
+ available at these locations:
+
+
+
+
+
+ * SiSU uses:
+ * Standard SiSU markup syntax,
+ * Standard SiSU meta-markup syntax, and the
+ * Standard SiSU object citation numbering and system
+
+ * Hompages:
+
+
+
+ * Download:
+
+
+ * Git
+
+
+
+ * Ralph Amissah
+
+
+
+ ** Description: Fictionbook XML rendition
+
+=end
+module SiSU_XML_Fictionbook
+ require_relative 'particulars' # particulars.rb
+ include SiSU_Particulars
+ require_relative 'ao' # ao.rb
+ require_relative 'sysenv' # sysenv.rb
+ include SiSU_Env
+ require_relative 'txt_shared' # txt_shared.rb
+ include SiSU_TextUtils
+ require_relative 'xml_shared' # xml_shared.rb
+ include SiSU_XML_Munge
+ class Source
+ def initialize(opt)
+ @opt=opt
+ @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
+ end
+ def read
+ begin
+ @md,@ao_array=@particulars.md,@particulars.ao_array
+ @env=@particulars.env
+ report
+ SiSU_XML_Fictionbook::Source::Scroll.new(@ao_array,@md).songsheet
+ rescue
+ SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do
+ __LINE__.to_s + ':' + __FILE__
+ end
+ ensure
+ end
+ end
+ private
+ def report
+ 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.fictionbook_viewer} #{@md.file.output_path.xml_fictionbook.dir}/#{@md.file.base_filename.xml_fictionbook}"
+ : "[#{@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],'Fictionbook',tool).green_hi_blue
+ : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Fictionbook',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.xml_fictionbook.dir}/#{@md.file.base_filename.xml_fictionbook}").flow
+ end
+ end
+ end
+ class Scroll
}
+ endnotes.each do |en|
+ filename_fictionbook.puts SiSU_TextUtils::Wrap.new(en,80,6).line_wrap
+ end
+ end
+ end
+ def structure_build_collapsed(data,endnotes,images_base64)
+ file=SiSU_Env::FileOp.new(@md)
+ filename_fictionbook=file.write_file.xml_fictionbook
+ h=0
+ doc_position=:head
+ filename_fictionbook.puts head
+ data.each_with_index do |o,i|
+ ocn=(defined? o.ocn and not o.ocn.nil?) ? "\n#{Dx[:ocn_o]}#{o.ocn}#{Dx[:ocn_c]}" : ''
+ if o.is ==:heading
+ lev=o.lc
+ chlv=(o.lv.to_i == 1) \
+ ? @chlv=o.lc.to_i
+ : 0
+ unless doc_position==:head
+ filename_fictionbook.puts structure_build_tag_close(lev,h)
+ end
+ doc_position=:body_and_tail
+ filename_fictionbook.puts %{#{space*lev}<#{tags.fictionbook[lev]}>
+#{space*lev}
+}
+ filename_fictionbook.puts SiSU_TextUtils::Wrap.new("
",80,6).line_wrap
+ end
+ end
+ filename_fictionbook.puts structure_build_tag_close(0,h)
+ endnotes_build(endnotes,filename_fictionbook)
+ filename_fictionbook.puts tail(images_base64)
+ filename_fictionbook.close
+ end
+ def structure_build_tag_close(lev,h)
+ x=[]
+ case h
+ when 1
+ x << "#{space*1}#{tags.fictionbook[1]}>" if (lev <= 1)
+ when 2
+ x << "#{space*2}#{tags.fictionbook[2]}>" if (lev <= 2)
+ x << "#{space*1}#{tags.fictionbook[1]}>" if (lev <= 1)
+ when 3
+ x << "#{space*3}#{tags.fictionbook[3]}>" if (lev <= 3)
+ x << "#{space*2}#{tags.fictionbook[2]}>" if (lev <= 2)
+ x << "#{space*1}#{tags.fictionbook[1]}>" if (lev <= 1)
+ when 4
+ x << "#{space*4}#{tags.fictionbook[4]}>" if (lev <= 4)
+ x << "#{space*3}#{tags.fictionbook[3]}>" if (lev <= 3)
+ x << "#{space*2}#{tags.fictionbook[2]}>" if (lev <= 2)
+ x << "#{space*1}#{tags.fictionbook[1]}>" if (lev <= 1)
+ when 5
+ x << "#{space*5}#{tags.fictionbook[5]}>" if (lev <= 5)
+ x << "#{space*4}#{tags.fictionbook[4]}>" if (lev <= 4)
+ x << "#{space*3}#{tags.fictionbook[3]}>" if (lev <= 3)
+ x << "#{space*2}#{tags.fictionbook[2]}>" if (lev <= 2)
+ x << "#{space*1}#{tags.fictionbook[1]}>" if (lev <= 1)
+ when 6
+ x << "#{space*6}#{tags.fictionbook[6]}>" if (lev <= 6)
+ x << "#{space*5}#{tags.fictionbook[5]}>" if (lev <= 5)
+ x << "#{space*4}#{tags.fictionbook[4]}>" if (lev <= 4)
+ x << "#{space*3}#{tags.fictionbook[3]}>" if (lev <= 3)
+ x << "#{space*2}#{tags.fictionbook[2]}>" if (lev <= 2)
+ x << "#{space*1}#{tags.fictionbook[1]}>" if (lev <= 1)
+ end
+ x.join("\n")
+ end
+ end
+ end
+end
+__END__
--
cgit v1.2.3