sisu 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. checksums.yaml +7 -0
  2. data/bin/sisu +367 -0
  3. data/bin/sisugem +367 -0
  4. data/data/sisu/image/arrow_next_red.png +0 -0
  5. data/data/sisu/image/arrow_prev_red.png +0 -0
  6. data/data/sisu/image/arrow_up_red.png +0 -0
  7. data/data/sisu/image/b_bluebell.png +0 -0
  8. data/data/sisu/image/b_doc.png +0 -0
  9. data/data/sisu/image/b_epub.png +0 -0
  10. data/data/sisu/image/b_home.png +0 -0
  11. data/data/sisu/image/b_info.png +0 -0
  12. data/data/sisu/image/b_odf.png +0 -0
  13. data/data/sisu/image/b_pdf.png +0 -0
  14. data/data/sisu/image/b_search.png +0 -0
  15. data/data/sisu/image/b_toc.png +0 -0
  16. data/data/sisu/image/bullet_08.png +0 -0
  17. data/data/sisu/image/bullet_09.png +0 -0
  18. data/data/sisu/image/bullet_10.png +0 -0
  19. data/data/sisu/image/bullet_11.png +0 -0
  20. data/data/sisu/image/bullet_12.png +0 -0
  21. data/data/sisu/image/bullet_doc.png +0 -0
  22. data/data/sisu/image/bullet_red.png +0 -0
  23. data/data/sisu/image/dot_clear.png +0 -0
  24. data/data/sisu/image/dot_white.png +0 -0
  25. data/data/sisu/image/gplv3.png +0 -0
  26. data/data/sisu/image/gplv3_free_software.png +0 -0
  27. data/data/sisu/image/next.png +0 -0
  28. data/data/sisu/image/previous.png +0 -0
  29. data/data/sisu/image/rb7.ico +0 -0
  30. data/data/sisu/image/sisu.png +0 -0
  31. data/data/sisu/image/toctoc.png +0 -0
  32. data/data/sisu/version.yml +5 -0
  33. data/lib/sisu.rb +94 -0
  34. data/lib/sisu/air.rb +80 -0
  35. data/lib/sisu/ao.rb +590 -0
  36. data/lib/sisu/ao_character_check.rb +102 -0
  37. data/lib/sisu/ao_composite.rb +286 -0
  38. data/lib/sisu/ao_doc_objects.rb +565 -0
  39. data/lib/sisu/ao_doc_str.rb +2269 -0
  40. data/lib/sisu/ao_endnotes.rb +136 -0
  41. data/lib/sisu/ao_expand_insertions.rb +514 -0
  42. data/lib/sisu/ao_hash_digest.rb +174 -0
  43. data/lib/sisu/ao_idx.rb +422 -0
  44. data/lib/sisu/ao_images.rb +187 -0
  45. data/lib/sisu/ao_metadata.rb +86 -0
  46. data/lib/sisu/ao_misc_arrange.rb +207 -0
  47. data/lib/sisu/ao_numbering.rb +720 -0
  48. data/lib/sisu/ao_persist.rb +194 -0
  49. data/lib/sisu/ao_references.rb +502 -0
  50. data/lib/sisu/ao_syntax.rb +640 -0
  51. data/lib/sisu/cgi.rb +84 -0
  52. data/lib/sisu/cgi_pgsql.rb +270 -0
  53. data/lib/sisu/cgi_sql_common.rb +986 -0
  54. data/lib/sisu/cgi_sqlite.rb +244 -0
  55. data/lib/sisu/conf.rb +287 -0
  56. data/lib/sisu/constants.rb +388 -0
  57. data/lib/sisu/css.rb +3484 -0
  58. data/lib/sisu/db_columns.rb +1997 -0
  59. data/lib/sisu/db_create.rb +689 -0
  60. data/lib/sisu/db_dbi.rb +90 -0
  61. data/lib/sisu/db_drop.rb +207 -0
  62. data/lib/sisu/db_import.rb +877 -0
  63. data/lib/sisu/db_indexes.rb +146 -0
  64. data/lib/sisu/db_load_tuple.rb +323 -0
  65. data/lib/sisu/db_remove.rb +182 -0
  66. data/lib/sisu/db_select.rb +230 -0
  67. data/lib/sisu/db_sqltxt.rb +173 -0
  68. data/lib/sisu/db_tests.rb +114 -0
  69. data/lib/sisu/dbi.rb +166 -0
  70. data/lib/sisu/dbi_discrete.rb +206 -0
  71. data/lib/sisu/digests.rb +306 -0
  72. data/lib/sisu/dp.rb +1606 -0
  73. data/lib/sisu/dp_identify_markup.rb +161 -0
  74. data/lib/sisu/dp_make.rb +668 -0
  75. data/lib/sisu/embedded.rb +149 -0
  76. data/lib/sisu/errors.rb +84 -0
  77. data/lib/sisu/generic_parts.rb +131 -0
  78. data/lib/sisu/git.rb +277 -0
  79. data/lib/sisu/html.rb +775 -0
  80. data/lib/sisu/html_concordance.rb +391 -0
  81. data/lib/sisu/html_format.rb +1348 -0
  82. data/lib/sisu/html_harvest.rb +109 -0
  83. data/lib/sisu/html_harvest_author_format.rb +111 -0
  84. data/lib/sisu/html_harvest_authors.rb +466 -0
  85. data/lib/sisu/html_harvest_topics.rb +893 -0
  86. data/lib/sisu/html_lite_shared.rb +324 -0
  87. data/lib/sisu/html_manifest.rb +1032 -0
  88. data/lib/sisu/html_minitoc.rb +230 -0
  89. data/lib/sisu/html_parts.rb +437 -0
  90. data/lib/sisu/html_persist.rb +237 -0
  91. data/lib/sisu/html_promo.rb +440 -0
  92. data/lib/sisu/html_scroll.rb +235 -0
  93. data/lib/sisu/html_segments.rb +716 -0
  94. data/lib/sisu/html_shared.rb +62 -0
  95. data/lib/sisu/html_table.rb +64 -0
  96. data/lib/sisu/html_tune.rb +301 -0
  97. data/lib/sisu/hub.rb +277 -0
  98. data/lib/sisu/hub_actions.rb +1122 -0
  99. data/lib/sisu/hub_loop_markup_files.rb +170 -0
  100. data/lib/sisu/hub_options.rb +1695 -0
  101. data/lib/sisu/i18n.rb +702 -0
  102. data/lib/sisu/manpage.rb +377 -0
  103. data/lib/sisu/manpage_format.rb +85 -0
  104. data/lib/sisu/object_munge.rb +307 -0
  105. data/lib/sisu/prog_text_translation.rb +1702 -0
  106. data/lib/sisu/qrcode.rb +754 -0
  107. data/lib/sisu/relaxng.rb +1153 -0
  108. data/lib/sisu/remote.rb +246 -0
  109. data/lib/sisu/rexml.rb +148 -0
  110. data/lib/sisu/se.rb +158 -0
  111. data/lib/sisu/se_cleanoutput.rb +145 -0
  112. data/lib/sisu/se_clear.rb +105 -0
  113. data/lib/sisu/se_createsite.rb +273 -0
  114. data/lib/sisu/se_css.rb +221 -0
  115. data/lib/sisu/se_date.rb +92 -0
  116. data/lib/sisu/se_db.rb +214 -0
  117. data/lib/sisu/se_envcall.rb +326 -0
  118. data/lib/sisu/se_file_op.rb +2758 -0
  119. data/lib/sisu/se_filemap.rb +247 -0
  120. data/lib/sisu/se_get_init.rb +238 -0
  121. data/lib/sisu/se_hub_particulars.rb +234 -0
  122. data/lib/sisu/se_info_env.rb +2179 -0
  123. data/lib/sisu/se_info_port.rb +70 -0
  124. data/lib/sisu/se_info_system.rb +202 -0
  125. data/lib/sisu/se_load.rb +108 -0
  126. data/lib/sisu/se_processing.rb +659 -0
  127. data/lib/sisu/se_programs.rb +394 -0
  128. data/lib/sisu/se_remotes.rb +553 -0
  129. data/lib/sisu/se_standardise_lang.rb +176 -0
  130. data/lib/sisu/se_version.rb +174 -0
  131. data/lib/sisu/shared_images.rb +137 -0
  132. data/lib/sisu/shared_markup_alt.rb +336 -0
  133. data/lib/sisu/shared_metadata.rb +1361 -0
  134. data/lib/sisu/shared_sem.rb +156 -0
  135. data/lib/sisu/sisu_thor_lib.rb +407 -0
  136. data/lib/sisu/sitemaps.rb +224 -0
  137. data/lib/sisu/src_kdissert_share.rb +102 -0
  138. data/lib/sisu/src_po4a_share.rb +309 -0
  139. data/lib/sisu/src_po4a_shelf.rb +1217 -0
  140. data/lib/sisu/src_po4a_shelf_set.rb +297 -0
  141. data/lib/sisu/src_po4a_sst_ao_sst.rb +893 -0
  142. data/lib/sisu/src_po4a_sst_ao_sst_set.rb +284 -0
  143. data/lib/sisu/src_po4a_sstm.rb +135 -0
  144. data/lib/sisu/src_shared.rb +347 -0
  145. data/lib/sisu/src_sisupod_make.rb +171 -0
  146. data/lib/sisu/src_sisupod_sstm.rb +109 -0
  147. data/lib/sisu/sst_convert_markup.rb +323 -0
  148. data/lib/sisu/sst_do_inline_footnotes.rb +440 -0
  149. data/lib/sisu/sst_from_xml.rb +178 -0
  150. data/lib/sisu/sst_identify_markup.rb +482 -0
  151. data/lib/sisu/sst_to_s_xml_sax.rb +471 -0
  152. data/lib/sisu/termsheet.rb +163 -0
  153. data/lib/sisu/texinfo.rb +430 -0
  154. data/lib/sisu/texinfo_format.rb +541 -0
  155. data/lib/sisu/texpdf.rb +1162 -0
  156. data/lib/sisu/texpdf_format.rb +1689 -0
  157. data/lib/sisu/texpdf_parts.rb +235 -0
  158. data/lib/sisu/txt_asciidoc.rb +354 -0
  159. data/lib/sisu/txt_asciidoc_decorate.rb +207 -0
  160. data/lib/sisu/txt_markdown.rb +389 -0
  161. data/lib/sisu/txt_markdown_decorate.rb +207 -0
  162. data/lib/sisu/txt_orgmode.rb +376 -0
  163. data/lib/sisu/txt_orgmode_decorate.rb +186 -0
  164. data/lib/sisu/txt_output.rb +86 -0
  165. data/lib/sisu/txt_plain.rb +410 -0
  166. data/lib/sisu/txt_plain_decorate.rb +189 -0
  167. data/lib/sisu/txt_read.rb +109 -0
  168. data/lib/sisu/txt_rst.rb +371 -0
  169. data/lib/sisu/txt_rst_decorate.rb +186 -0
  170. data/lib/sisu/txt_shared.rb +241 -0
  171. data/lib/sisu/txt_textile.rb +367 -0
  172. data/lib/sisu/txt_textile_decorate.rb +186 -0
  173. data/lib/sisu/update.rb +141 -0
  174. data/lib/sisu/urls.rb +696 -0
  175. data/lib/sisu/utils.rb +232 -0
  176. data/lib/sisu/utils_composite.rb +115 -0
  177. data/lib/sisu/utils_response.rb +114 -0
  178. data/lib/sisu/utils_screen_text_color.rb +472 -0
  179. data/lib/sisu/utils_spell.rb +99 -0
  180. data/lib/sisu/webrick.rb +191 -0
  181. data/lib/sisu/wikispeak.rb +375 -0
  182. data/lib/sisu/xhtml.rb +472 -0
  183. data/lib/sisu/xhtml_epub2.rb +890 -0
  184. data/lib/sisu/xhtml_epub2_concordance.rb +322 -0
  185. data/lib/sisu/xhtml_epub2_format.rb +2272 -0
  186. data/lib/sisu/xhtml_epub2_persist.rb +278 -0
  187. data/lib/sisu/xhtml_epub2_segments.rb +599 -0
  188. data/lib/sisu/xhtml_epub2_tune.rb +330 -0
  189. data/lib/sisu/xhtml_parts.rb +183 -0
  190. data/lib/sisu/xhtml_shared.rb +62 -0
  191. data/lib/sisu/xhtml_table.rb +97 -0
  192. data/lib/sisu/xml_docbook5.rb +376 -0
  193. data/lib/sisu/xml_dom.rb +624 -0
  194. data/lib/sisu/xml_fictionbook2.rb +389 -0
  195. data/lib/sisu/xml_format.rb +865 -0
  196. data/lib/sisu/xml_md_oai_pmh_dc.rb +229 -0
  197. data/lib/sisu/xml_odf_odt.rb +887 -0
  198. data/lib/sisu/xml_odf_odt_format.rb +674 -0
  199. data/lib/sisu/xml_parts.rb +191 -0
  200. data/lib/sisu/xml_persist.rb +126 -0
  201. data/lib/sisu/xml_sax.rb +521 -0
  202. data/lib/sisu/xml_scaffold_structure_collapsed.rb +198 -0
  203. data/lib/sisu/xml_scaffold_structure_sisu.rb +201 -0
  204. data/lib/sisu/xml_shared.rb +665 -0
  205. data/lib/sisu/xml_tables.rb +261 -0
  206. data/lib/sisu/zap.rb +90 -0
  207. metadata +251 -0
@@ -0,0 +1,890 @@
1
+ # encoding: utf-8
2
+ =begin
3
+
4
+ * Name: SiSU
5
+
6
+ ** Description: documents, structuring, processing, publishing, search
7
+ *** epub generation, processing
8
+
9
+ ** Author: Ralph Amissah
10
+ <ralph@amissah.com>
11
+ <ralph.amissah@gmail.com>
12
+
13
+ ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
15
+ All Rights Reserved.
16
+
17
+ ** License: GPL 3 or later:
18
+
19
+ SiSU, a framework for document structuring, publishing and search
20
+
21
+ Copyright (C) Ralph Amissah
22
+
23
+ This program is free software: you can redistribute it and/or modify it
24
+ under the terms of the GNU General Public License as published by the Free
25
+ Software Foundation, either version 3 of the License, or (at your option)
26
+ any later version.
27
+
28
+ This program is distributed in the hope that it will be useful, but WITHOUT
29
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31
+ more details.
32
+
33
+ You should have received a copy of the GNU General Public License along with
34
+ this program. If not, see <http://www.gnu.org/licenses/>.
35
+
36
+ If you have Internet connection, the latest version of the GPL should be
37
+ available at these locations:
38
+ <http://www.fsf.org/licensing/licenses/gpl.html>
39
+ <http://www.gnu.org/licenses/gpl.html>
40
+
41
+ <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
42
+
43
+ ** SiSU uses:
44
+ * Standard SiSU markup syntax,
45
+ * Standard SiSU meta-markup syntax, and the
46
+ * Standard SiSU object citation numbering and system
47
+
48
+ ** Hompages:
49
+ <http://www.jus.uio.no/sisu>
50
+ <http://www.sisudoc.org>
51
+
52
+ ** Git
53
+ <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
54
+ <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/xhtml_epub2.rb;hb=HEAD>
55
+
56
+ =end
57
+ module SiSU_XHTML_EPUB2
58
+ begin
59
+ require 'pstore'
60
+ rescue LoadError
61
+ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
62
+ error('pstore NOT FOUND (LoadError)')
63
+ end
64
+ require_relative 'se_hub_particulars' # se_hub_particulars.rb
65
+ include SiSU_Particulars
66
+ require_relative 'xml_shared' # xml_shared.rb
67
+ include SiSU_XML_Munge
68
+ require_relative 'xhtml_table' # xhtml_table.rb
69
+ require_relative 'xhtml_epub2_format' # xhtml_epub2_format.rb
70
+ include SiSU_XHTML_EPUB2_Format
71
+ require_relative 'xhtml_epub2_segments' # xhtml_epub2_segments.rb
72
+ include SiSU_XHTML_EPUB2_Seg
73
+ require_relative 'xhtml_epub2_tune' # xhtml_epub2_tune.rb
74
+ include SiSU_XHTML_EPUB2_Tune
75
+ require_relative 'xhtml_epub2_concordance' # xhtml_epub2_concordance.rb
76
+ require_relative 'xhtml_epub2_persist' # xhtml_epub2_persist.rb
77
+ class Source
78
+ def initialize(opt)
79
+ @opt=opt
80
+ @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
81
+ end
82
+ def read
83
+ begin
84
+ songsheet
85
+ ensure
86
+ Dir.chdir(@opt.f_pth[:pth])
87
+ end
88
+ end
89
+ def songsheet
90
+ begin
91
+ @md=@particulars.md
92
+ @fnb=@md.fnb
93
+ @env=@particulars.env
94
+ unless @opt.act[:quiet][:set]==:on
95
+ tool=(@opt.act[:verbose][:set]==:on \
96
+ || @opt.act[:verbose_plus][:set]==:on \
97
+ || @opt.act[:maintenance][:set]==:on) \
98
+ ? "#{@env.program.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}"
99
+ : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}"
100
+ (@opt.act[:verbose][:set]==:on \
101
+ || @opt.act[:verbose_plus][:set]==:on \
102
+ || @opt.act[:maintenance][:set]==:on) \
103
+ ? SiSU_Screen::Ansi.new(
104
+ @opt.act[:color_state][:set],
105
+ 'EPUB',
106
+ tool
107
+ ).green_hi_blue
108
+ : SiSU_Screen::Ansi.new(
109
+ @opt.act[:color_state][:set],
110
+ 'EPUB',
111
+ tool
112
+ ).green_title_hi
113
+ if (@opt.act[:verbose_plus][:set]==:on \
114
+ || @opt.act[:maintenance][:set]==:on)
115
+ SiSU_Screen::Ansi.new(
116
+ @opt.act[:color_state][:set],
117
+ @opt.fns,
118
+ "#{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}"
119
+ ).flow
120
+ end
121
+ end
122
+ @env.processing_path.epub_bld #(@md)
123
+ @env.processing_path.epub_cp_images(@md)
124
+ data=nil
125
+ SiSU_Env::FileOp.new(@md).mkdir.output.epub
126
+ @tuned_file_array=SiSU_XHTML_EPUB2::Source::XHTML_Environment.new(@particulars).tuned_file_instructions
127
+ data=@tuned_file_array
128
+ per=SiSU_XHTML_EPUB2::Source::Toc.new(@md,data).songsheet
129
+ data=@tuned_file_array
130
+ SiSU_XHTML_EPUB2::Source::ScrollHeadAndSegToc.new(@md,per).in_common #watch
131
+ SiSU_XHTML_EPUB2::Source::Seg.new(@md,data).songsheet
132
+ SiSU_XHTML_EPUB2::Source::Output.new(@md).songsheet
133
+ rescue
134
+ SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
135
+ __LINE__.to_s + ':' + __FILE__
136
+ end
137
+ ensure
138
+ unless (@opt.act[:verbose_plus][:set]==:on \
139
+ || @opt.act[:maintenance][:set]==:on)
140
+ texfiles=Dir["#{@env.processing_path.tune}/#{@opt.fns}*"]
141
+ texfiles.each do |f|
142
+ if FileTest.file?(f)
143
+ File.unlink(f)
144
+ end
145
+ end
146
+ end
147
+ SiSU_Env::Clear.new(@opt.selections.str,@opt.fns).param_instantiate
148
+ @@flag,@@scr,@@seg,@@seg_endnotes,@@seg_subtoc={},{},{},{},{}
149
+ @@tracker=0
150
+ @@seg_name,@@seg_name_html,@@seg_subtoc_array,@@seg_endnotes_array,@@tablefoot=Array.new(5){[]}
151
+ @@filename_seg,@@seg_url,@@to_lev4,@@get_hash_to,@@get_hash_fn='','','','',''
152
+ end
153
+ end
154
+ private
155
+ class XHTML_Environment
156
+ def initialize(particulars)
157
+ @particulars=particulars
158
+ @md,@env=particulars.md,particulars.env
159
+ @env,@css=particulars.env,SiSU_Style::CSS.new
160
+ end
161
+ def directories
162
+ SiSU_Env::FileOp.new(@md).mkdir.output.epub
163
+ end
164
+ def tuned_file_instructions
165
+ @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set])
166
+ directories
167
+ ao_array=@particulars.ao_array # ao file drawn here
168
+ @tuned_file_array=SiSU_XHTML_EPUB2_Tune::Tune.new(ao_array,@md).songsheet
169
+ @tuned_file_array
170
+ end
171
+ end
172
+ class Endnotes
173
+ include SiSU_XHTML_EPUB2_Format
174
+ def initialize(md,data)
175
+ @md,@data=md,data
176
+ end
177
+ def scroll
178
+ @scr_endnotes=[]
179
+ @data.each do |dob|
180
+ pg=dob.dup
181
+ unless pg.is ==:code
182
+ if pg.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+ /
183
+ endnote_array=[]
184
+ if pg.obj=~/#{Mx[:en_a_o]}[\d*+].+?#{Mx[:en_a_c]}/m
185
+ endnote_array = pg.obj.scan(/#{Mx[:en_a_o]}[\d*+]+(.+?)#{Mx[:en_a_c]}/m)
186
+ end
187
+ if pg.obj=~/#{Mx[:en_b_o]}[\d*]+\s.+?#{Mx[:en_b_c]}/m
188
+ endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d*]+(.+?)#{Mx[:en_b_c]}/m)
189
+ end
190
+ if pg.obj=~/#{Mx[:en_b_o]}[\d+]+\s.+?#{Mx[:en_b_c]}/m
191
+ endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d+]+(.+?)#{Mx[:en_b_c]}/m)
192
+ end
193
+ endnote_array.flatten.each do |note|
194
+ txt_obj={ txt: note }
195
+ format_scroll=SiSU_XHTML_EPUB2_Format::FormatScroll.new(@md,txt_obj)
196
+ @scr_endnotes << format_scroll.endnote_body
197
+ end
198
+ end
199
+ end
200
+ end
201
+ @scr_endnotes
202
+ end
203
+ end
204
+ class Toc
205
+ @@seg_url=''
206
+ @@firstseg=nil
207
+ def initialize(md=nil,data='')
208
+ @md,@data=md,data
209
+ @epub=SiSU_XHTML_EPUB2_Format::HeadInformation.new(@md)
210
+ @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) if @md
211
+ @make=SiSU_Env::ProcessingSettings.new(@md)
212
+ @per=SiSU_XHTML_EPUB2_Persist::PersistTOC.new
213
+ end
214
+ def songsheet #extracts toc for scroll & seg
215
+ begin
216
+ if (@md.opt.act[:verbose][:set]==:on \
217
+ || @md.opt.act[:verbose_plus][:set]==:on \
218
+ || @md.opt.act[:maintenance][:set]==:on)
219
+ SiSU_Screen::Ansi.new(
220
+ @md.opt.act[:color_state][:set],
221
+ 'Toc'
222
+ ).txt_grey
223
+ end
224
+ toc=nil
225
+ @@firstseg=nil
226
+ SiSU_XHTML_EPUB2_Persist::PersistTOC.new.persist_init
227
+ md_opf_a_content,md_opf_a_spine,md_opf_a_guide=[],[],[]
228
+ @nav_no=0
229
+ @s_a_no,@s_b_no,@s_c_no,@s_d_no,@lv5_no,@lv6_no=0,0,0,0,0,0
230
+ @per.ncx << @epub.toc_ncx.open #epub ncx navmap
231
+ @per.ncx << @epub.toc_ncx.head_open << @epub.toc_ncx.head << @epub.toc_ncx.head_close
232
+ @per.ncx << @epub.toc_ncx.doc_title << @epub.toc_ncx.doc_author
233
+ @per.ncx << @epub.toc_ncx.navmap_open
234
+ @per.opf << @epub.metadata_opf.package_open
235
+ @per.opf << @epub.metadata_opf.metadata
236
+ @per.opf << @epub.metadata_opf.manifest_open
237
+ @per.seg << %{<div class="content">\n<div class="substance">}
238
+ @per.scr << %{<div class="content">\n<div class="substance">}
239
+ if defined? @md.make.cover_image \
240
+ and @md.make.cover_image.is_a?(Hash) \
241
+ and @md.make.cover_image[:cover] =~/\S+/
242
+ md_opf_a_content << @epub.metadata_opf.manifest_cover_image_information(@md)
243
+ md_opf_a_spine << @epub.metadata_opf.spine_cover_image
244
+ md_opf_a_guide << @epub.metadata_opf.guide_cover_image
245
+ end
246
+ md_opf_a_content << @epub.metadata_opf.manifest_content_sisu_toc
247
+ if @make.build.toc?
248
+ md_opf_a_spine << @epub.metadata_opf.spine_sisu_toc
249
+ md_opf_a_guide << @epub.metadata_opf.guide_sisu_toc
250
+ end
251
+ @ncxo=[false,false,false,false,false,false,false]
252
+ @dob_toc2,@dob_toc3=nil,nil
253
+ @ncx_cls=[]
254
+ @level_a_first_occurrence=true
255
+ @data.each do |dob|
256
+ if dob.is==:heading \
257
+ || dob.is==:heading_insert
258
+ dob_toc=dob.dup
259
+ toc=case dob_toc.ln
260
+ when 0
261
+ @s_a_no +=1
262
+ lv_name='section_a' + @s_a_no.to_s
263
+ @nav_no+=1
264
+ @nav_no2=@nav_no
265
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7]
266
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6]
267
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5]
268
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4]
269
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[3]
270
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[2]
271
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[1]
272
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[0]
273
+ @ncxo[0],@ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6],@ncxo[7]=
274
+ true, false, false, false, false, false, false, false
275
+ @epub.sections(dob_toc,lv_name)
276
+ if @level_a_first_occurrence \
277
+ && @make.build.toc?
278
+ @per.ncx << @epub.toc_ncx.navmap_sisu_toc(@nav_no) #epub ncx navmap, toc
279
+ @nav_no+=1
280
+ @level_a_first_occurrence=false
281
+ end
282
+ @per.ncx << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc
283
+ md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name)
284
+ md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name)
285
+ md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name)
286
+ SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_0
287
+ when 1
288
+ @s_b_no +=1
289
+ lv_name='section_b' + @s_b_no.to_s
290
+ @nav_no+=1
291
+ @nav_no2=@nav_no
292
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7]
293
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6]
294
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5]
295
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4]
296
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[3]
297
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[2]
298
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[1]
299
+ @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6],@ncxo[7]=
300
+ true, false, false, false, false, false, false
301
+ @epub.sections(dob_toc,lv_name)
302
+ @per.ncx << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc
303
+ md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name)
304
+ md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name)
305
+ md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name)
306
+ SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_1
307
+ when 2
308
+ @s_c_no +=1
309
+ lv_name='section_c' + @s_c_no.to_s
310
+ @nav_no+=1
311
+ @nav_no2=@nav_no
312
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7]
313
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6]
314
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5]
315
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4]
316
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[3]
317
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[2]
318
+ @ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6],@ncxo[7]=
319
+ true, false, false, false, false, false
320
+ @epub.sections(dob_toc,lv_name)
321
+ @per.ncx << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc
322
+ md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name)
323
+ md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name)
324
+ md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name)
325
+ SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_2
326
+ when 3
327
+ @s_d_no +=1
328
+ lv_name='section_d' + @s_d_no.to_s
329
+ @nav_no+=1
330
+ @nav_no3=@nav_no
331
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7]
332
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6]
333
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5]
334
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4]
335
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[3]
336
+ @ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6],@ncxo[7]=
337
+ true, false, false, false, false
338
+ @epub.sections(dob_toc,lv_name)
339
+ @per.ncx << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc
340
+ md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name)
341
+ md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name)
342
+ md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name)
343
+ SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_3
344
+ when 4
345
+ @ncx_cls=[]
346
+ lv_name=dob_toc.name
347
+ @nav_no+=1
348
+ @dob_name=dob.name
349
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7]
350
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6]
351
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5]
352
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4]
353
+ @ncxo[4],@ncxo[5],@ncxo[6],@ncxo[7]=
354
+ true, false, false, false
355
+ @per.ncx << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc
356
+ md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name)
357
+ md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name)
358
+ md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name)
359
+ SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_4
360
+ when 5
361
+ @ncx_cls=[]
362
+ hashtag='#o' + dob_toc.ocn.to_s
363
+ lv_name=@dob_name
364
+ @nav_no+=1
365
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7]
366
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6]
367
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5]
368
+ @ncxo[5],@ncxo[6],@ncxo[7]=
369
+ true, false, false
370
+ @per.ncx << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc
371
+ md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag)
372
+ md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag)
373
+ md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag)
374
+ SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_5
375
+ when 6
376
+ @ncx_cls=[]
377
+ hashtag='#o' + dob_toc.ocn.to_s
378
+ lv_name=@dob_name
379
+ @nav_no+=1
380
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7]
381
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6]
382
+ @ncxo[6],@ncxo[7]=
383
+ true, false
384
+ @per.ncx << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc
385
+ md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag)
386
+ md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag)
387
+ md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag)
388
+ SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_6
389
+ when 7
390
+ @ncx_cls=[]
391
+ hashtag='#o' + dob_toc.ocn.to_s
392
+ lv_name=@dob_name
393
+ @nav_no+=1
394
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[7]
395
+ @ncxo[7]=true
396
+ @per.ncx << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc
397
+ md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag)
398
+ md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag)
399
+ md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag)
400
+ SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_7
401
+ else nil
402
+ end
403
+ toc.each do |k,d|
404
+ d.gsub!(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
405
+ end if toc
406
+ if @@firstseg.nil? \
407
+ and dob.ln==4 \
408
+ and dob.name =~/\S+/
409
+ @@firstseg=dob.name
410
+ end
411
+ if toc
412
+ begin
413
+ @per.seg << toc[:seg]
414
+ @per.scr << toc[:seg]
415
+ rescue
416
+ SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
417
+ __LINE__.to_s + ':' + __FILE__
418
+ end
419
+ end
420
+ end
421
+ end
422
+ end
423
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[6]
424
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[5]
425
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[4]
426
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[3]
427
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[2]
428
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[1]
429
+ @per.ncx << @epub.toc_ncx.navpoint_close if @ncxo[0]
430
+ @ncxo[0],@ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=false,false,false,false,false,false,false
431
+ md_opf_a_content << @epub.metadata_opf.manifest_images(@md.ec[:image])
432
+ @per.seg << "</div>\n</div>"
433
+ @per.scr << "</div>\n</div>"
434
+ @per.ncx << @epub.toc_ncx.navmap_close
435
+ @per.ncx << @epub.toc_ncx.close
436
+ @per.opf << md_opf_a_content << @epub.metadata_opf.manifest_close
437
+ @per.opf << @epub.metadata_opf.spine_open << md_opf_a_spine << @epub.metadata_opf.spine_close
438
+ @per.opf << @epub.metadata_opf.guide_open << md_opf_a_guide << @epub.metadata_opf.guide_close
439
+ @per.opf << @epub.metadata_opf.package_close
440
+ @per.opf=@per.opf.flatten
441
+ SiSU_XHTML_EPUB2::Source::Output.new(@md,@per.opf).epub_metadata_opf
442
+ SiSU_XHTML_EPUB2::Source::Output.new(@md,@per.ncx).epub_toc_ncx
443
+ @md.firstseg=@@firstseg
444
+ @per
445
+ ensure
446
+ SiSU_XHTML_EPUB2_Persist::Persist.new.persist_init
447
+ end
448
+ end
449
+ protected
450
+ def level_0
451
+ dob=@data
452
+ linkname=dob.obj.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'').strip
453
+ link=dob.ocn
454
+ title=linkname
455
+ toc={}
456
+ txt_obj={ txt: title }
457
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
458
+ toc[:seg]=format_toc.lev1
459
+ title=if dob.ocn ==0 then linkname
460
+ else
461
+ @per.scr << '<br />'
462
+ link=(dob.ln) \
463
+ ? dob.ln
464
+ : ''
465
+ %{<b><a href="##{link}">#{linkname}</a></b>}
466
+ end
467
+ txt_obj={ txt: title }
468
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
469
+ toc[:scr]=format_toc.lev1
470
+ toc
471
+ end
472
+ def level_1
473
+ dob=@data
474
+ linkname=dob.obj.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'').strip
475
+ link=dob.ocn
476
+ title=if dob.obj !~/Document Information/
477
+ linkname
478
+ else
479
+ link='metadata'
480
+ %{<b><a href="#{link}#{Sfx[:epub_xhtml]}">#{linkname}</a></b>}
481
+ end
482
+ toc={}
483
+ txt_obj={ txt: title }
484
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
485
+ toc[:seg]=if dob.name =~/^meta/ \
486
+ and dob.obj =~/Document Information/ #check
487
+ format_toc.lev0
488
+ else format_toc.lev1
489
+ end
490
+ title=if dob.ocn ==0
491
+ if dob.name =~/^meta/ \
492
+ and dob.obj =~/Document Information/
493
+ %{<a href="#docinfo">#{linkname}</a>}
494
+ else linkname
495
+ end
496
+ else
497
+ @per.scr << '<br />'
498
+ link=(dob.ln) \
499
+ ? dob.ln
500
+ : ''
501
+ %{<b><a href="##{link}">#{linkname}</a></b>}
502
+ end
503
+ txt_obj={ txt: title }
504
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
505
+ toc[:scr]=if dob.name =~/^meta/ \
506
+ and dob.obj =~/Document Information/
507
+ format_toc.lev0
508
+ else format_toc.lev1
509
+ end
510
+ toc
511
+ end
512
+ def level_2
513
+ dob=@data
514
+ linkname=dob.obj.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'').strip
515
+ ocn=dob.ocn
516
+ if ocn \
517
+ and ocn !~/#/
518
+ p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn)
519
+ end
520
+ txt_obj={ txt: linkname }
521
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
522
+ toc={}
523
+ toc[:seg]=format_toc.lev2
524
+ if p_num
525
+ title=%{#{p_num.goto}#{linkname}</a>}
526
+ txt_obj={ txt: title }
527
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
528
+ toc[:scr]=format_toc.lev2
529
+ end
530
+ toc
531
+ end
532
+ def level_3
533
+ dob=@data
534
+ linkname=dob.obj.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'').strip
535
+ ocn=dob.ocn
536
+ if ocn \
537
+ and ocn !~/#/
538
+ p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn)
539
+ end
540
+ txt_obj={ txt: linkname }
541
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
542
+ toc={}
543
+ toc[:seg]=format_toc.lev3
544
+ if p_num
545
+ title=%{#{p_num.goto}#{linkname}</a>}
546
+ txt_obj={ txt: title }
547
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
548
+ toc[:scr]=format_toc.lev3
549
+ end
550
+ toc
551
+ end
552
+ def level_4
553
+ dob=@data
554
+ linkname=dob.obj.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'').strip
555
+ ocn=dob.ocn
556
+ p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) if ocn
557
+ if dob.ln==4
558
+ seg_link=%{ <a href="#{dob.name}#{Sfx[:epub_xhtml]}">
559
+ #{dob.obj}
560
+ </a> }
561
+ @@seg_url=dob.name
562
+ elsif dob.obj =~/\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+/
563
+ seg_link=dob.obj.gsub(/^(\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+)(.*)/,
564
+ %{<a href="\\1#{Sfx[:epub_xhtml]}">} +
565
+ %{\\1 \\2</a> })
566
+ end
567
+ p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) if ocn
568
+ txt_obj={ txt: seg_link }
569
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
570
+ toc={}
571
+ toc[:seg]=format_toc.lev4
572
+ title=%{#{p_num.goto}#{linkname}</a>} if p_num
573
+ txt_obj={ txt: title }
574
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
575
+ toc[:scr]=format_toc.lev4
576
+ toc
577
+ end
578
+ def level_5
579
+ dob=@data
580
+ linkname=dob.obj.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'').strip
581
+ ocn=dob.ocn
582
+ toc={}
583
+ if ocn \
584
+ and ocn !~/#/
585
+ p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn)
586
+ lnk_n_txt=%{ <a href="#{@@seg_url}#{Sfx[:epub_xhtml]}#o#{ocn}">
587
+ #{linkname}
588
+ </a>}
589
+ txt_obj={ txt: lnk_n_txt }
590
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
591
+ toc[:seg]=format_toc.lev5
592
+ title=%{#{p_num.goto}#{linkname}</a>}
593
+ txt_obj={ txt: title }
594
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
595
+ toc[:scr]=format_toc.lev5
596
+ end
597
+ toc
598
+ end
599
+ def level_6
600
+ dob=@data
601
+ linkname=dob.obj.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'').strip
602
+ ocn=dob.ocn
603
+ toc={}
604
+ if ocn \
605
+ and ocn !~/#/
606
+ p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn)
607
+ lnk_n_txt=%{ <a href="#{@@seg_url}#{Sfx[:epub_xhtml]}#o#{ocn}">
608
+ #{linkname}
609
+ </a>}
610
+ txt_obj={ txt: lnk_n_txt }
611
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
612
+ toc[:seg]=format_toc.lev6
613
+ title=%{#{p_num.goto}#{linkname}</a>}
614
+ txt_obj={ txt: title }
615
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
616
+ toc[:scr]=format_toc.lev6
617
+ end
618
+ toc
619
+ end
620
+ def level_7
621
+ dob=@data
622
+ linkname=dob.obj.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'').strip
623
+ ocn=dob.ocn
624
+ toc={}
625
+ if ocn \
626
+ and ocn !~/#/
627
+ p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn)
628
+ lnk_n_txt=%{ <a href="#{@@seg_url}#{Sfx[:epub_xhtml]}#o#{ocn}">
629
+ #{linkname}
630
+ </a>}
631
+ txt_obj={ txt: lnk_n_txt }
632
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
633
+ toc[:seg]=format_toc.lev7
634
+ title=%{#{p_num.goto}#{linkname}</a>}
635
+ txt_obj={ txt: title }
636
+ format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj)
637
+ toc[:scr]=format_toc.lev7
638
+ end
639
+ toc
640
+ end
641
+ end
642
+ class ScrollHeadAndSegToc < Toc
643
+ def initialize(md='',per='',links_guide_toc='')
644
+ @md,@per,@links_guide_toc=md,per,links_guide_toc
645
+ end
646
+ def in_common
647
+ toc_shared=[]
648
+ segtoc=[]
649
+ if (@md.opt.act[:verbose][:set]==:on \
650
+ || @md.opt.act[:verbose_plus][:set]==:on \
651
+ || @md.opt.act[:maintenance][:set]==:on)
652
+ SiSU_Screen::Ansi.new(
653
+ @md.opt.act[:color_state][:set],
654
+ 'Scroll & Segtoc'
655
+ ).txt_grey
656
+ end
657
+ format_head_toc=SiSU_XHTML_EPUB2_Format::HeadToc.new(@md)
658
+ dochead=format_head_toc.head
659
+ dochead=dochead.gsub(/toc\.(html)/,'doc.\1') #kludge
660
+ toc_shared << dochead #<< ads.div.major
661
+ segtoc << format_head_toc.head #<< ads.div.major
662
+ if defined? @md.rights.all \
663
+ and @md.rights.all
664
+ rights=format_head_toc.rights.all
665
+ rights=SiSU_XHTML_EPUB2_Tune::CleanXHTML.new(rights).clean
666
+ end
667
+ if defined? @md.notes.prefix_b \
668
+ and @md.notes.prefix_b
669
+ prefix_b=format_head_toc.prefix_b
670
+ prefix_b=SiSU_XHTML_EPUB2_Tune::CleanXHTML.new(prefix_b).clean
671
+ end
672
+ tmp_head=nil
673
+ doc_title_endnote=@md.title.full.gsub(/(\*+)/,'<sup><a href="#endnotes">\1</a></sup>')
674
+ tmp_head=doc_title_endnote + "\n"
675
+ txt_obj={ txt: tmp_head }
676
+ format_txt_obj=SiSU_XHTML_EPUB2_Format::FormatTextObject.new(@md,txt_obj)
677
+ toc_shared << format_txt_obj.center_bold
678
+ segtoc << format_txt_obj.center_bold
679
+ if defined? @md.creator.author \
680
+ and @md.creator.author
681
+ creator_endnote=@md.creator.author.gsub(/(\*+)/,%{#{$ep[:hsp]}<sup><a href="#notes">\\1</a></sup>})
682
+ tmp_head=creator_endnote + "\n"
683
+ txt_obj={ txt: tmp_head }
684
+ format_txt_obj=SiSU_XHTML_EPUB2_Format::FormatTextObject.new(@md,txt_obj)
685
+ toc_shared << format_txt_obj.center_bold
686
+ segtoc << format_txt_obj.center_bold
687
+ end
688
+ tmp_head=nil
689
+ if defined? @md.prefix_a \
690
+ and @md.prefix_a
691
+ tmp_head ||= %{#{@md.prefix_a}\n}
692
+ toc_shared << tmp_head.dup
693
+ segtoc << tmp_head.dup
694
+ end
695
+ tmp_head=nil
696
+ toc_shared << @links_guide_toc
697
+ if defined? @md.rights.all \
698
+ and @md.rights.all
699
+ toc_shared << rights
700
+ end
701
+ if defined? @md.prefix_b \
702
+ and @md.prefix_b
703
+ toc_shared << prefix_b
704
+ end
705
+ #Table of Contents added/appended here
706
+ toc_shared << @per.scr
707
+ segtoc << @links_guide_toc
708
+ segtoc << @per.seg
709
+ if defined? @md.rights.all \
710
+ and @md.rights.all
711
+ segtoc << rights
712
+ end
713
+ if defined? @md.prefix_b \
714
+ and @md.prefix_b
715
+ segtoc << prefix_b
716
+ end
717
+ #Segtoc tail added here
718
+ segtoc << format_head_toc.xhtml_close
719
+ segtoc=segtoc.flatten.compact #watch
720
+ SiSU_XHTML_EPUB2::Source::Output.new(@md).make_cover_image
721
+ SiSU_XHTML_EPUB2::Source::Output.new(@md,segtoc).make_segtoc
722
+ segtoc=[]
723
+ @per.scr,@per.seg=[],[]
724
+ toc_shared
725
+ end
726
+ end
727
+ class Table < SiSU_XHTML_Table::TableXHTML
728
+ end
729
+ class Seg < SiSU_XHTML_EPUB2_Seg::Seg
730
+ end
731
+ class Output
732
+ def initialize(md,output='')
733
+ @md,@output=md,output
734
+ @epub_doc="#{@md.fnb}.epub"
735
+ @epub_header=SiSU_XHTML_EPUB2_Format::HeadInformation.new(@md)
736
+ @make=SiSU_Env::ProcessingSettings.new(@md)
737
+ @make_file=SiSU_Env::CreateFile.new(@md.fns)
738
+ end
739
+ def songsheet
740
+ mimetype
741
+ metainf_container
742
+ css
743
+ images if @md.ec[:image]
744
+ #concordance #uncomment to enable inclusion of concordance file
745
+ output_zip
746
+ end
747
+ def mimetype
748
+ out=@make_file.epub.mimetype
749
+ out<<@epub_header.mimetype
750
+ out.close
751
+ end
752
+ def metainf_container #container.xml file in META-INF directory
753
+ out=@make_file.epub.metainf_cont
754
+ out<<@epub_header.metainf_container
755
+ out.close
756
+ end
757
+ def css
758
+ out=@make_file.epub.xhtml_css
759
+ out << SiSU_XHTML_EPUB2_Format::CSS.new.css_epub_xhtml
760
+ out.close
761
+ end
762
+ def epub_toc_ncx
763
+ begin
764
+ out=@make_file.epub.toc_ncx
765
+ @output.each do |para|
766
+ unless para =~/\A\s*\Z/
767
+ out.puts para
768
+ end
769
+ end
770
+ out.close
771
+ rescue
772
+ SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
773
+ __LINE__.to_s + ':' + __FILE__
774
+ end
775
+ end
776
+ end
777
+ def epub_metadata_opf
778
+ begin
779
+ out=@make_file.epub.metadata
780
+ @output.each do |para|
781
+ unless para =~/\A\s*\Z/
782
+ out.puts para
783
+ end
784
+ end
785
+ out.close
786
+ rescue
787
+ SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
788
+ __LINE__.to_s + ':' + __FILE__
789
+ end
790
+ end
791
+ end
792
+ def images
793
+ img_pth=@md.env.path.image_source_include
794
+ img_src_pth=unless @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/
795
+ @md.file.output_path.epub.rel_image
796
+ else
797
+ pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1]
798
+ pt + '/image'
799
+ end
800
+ @md.ec[:image].each do |x|
801
+ if FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \
802
+ && FileTest.file?("#{img_src_pth}/#{x}")
803
+ FileUtils::cp("#{img_src_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image")
804
+ elsif FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \
805
+ && FileTest.file?("#{img_pth}/#{x}")
806
+ FileUtils::cp("#{img_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image")
807
+ else STDERR.puts %{\t*WARN* did not find image - "#{x}" in #{img_src_pth} or #{img_pth} [#{__FILE__}:#{__LINE__}]}
808
+ end
809
+ end
810
+ end
811
+ def concordance
812
+ SiSU_XHTML_EPUB2_Concordance::Source.new(@md.opt).read
813
+ end
814
+ def output_zip
815
+ FileUtils::mkdir_p(@md.file.output_path.epub.dir) unless FileTest.directory?(@md.file.output_path.epub.dir)
816
+ if FileTest.directory?(@md.env.processing_path.epub) \
817
+ and SiSU_Env::SystemCall.new.zip
818
+ pwd=Dir.pwd
819
+ Dir.chdir(@md.env.processing_path.epub)
820
+ system("
821
+ zip -qXr9D #{@epub_doc} *
822
+ ")
823
+ FileUtils::mv(@epub_doc, @md.file.place_file.epub.dir)
824
+ Dir.chdir(pwd)
825
+ unless @md.opt.act[:maintenance][:set]==:on
826
+ FileUtils::rm_r(@md.env.processing_path.epub)
827
+ end
828
+ else
829
+ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark('*EXITED epub* zip program not found') unless SiSU_Env::SystemCall.new.zip
830
+ end
831
+ end
832
+ def make_cover_image
833
+ begin
834
+ if @md.make.cover_image? \
835
+ and @md.make.cover_image.is_a?(Hash) \
836
+ and @md.make.cover_image[:cover] =~/\S+/
837
+ filename_xhtml=@make_file.epub.xhtml_cover_image
838
+ cover_image=<<WOK
839
+ <?xml version='1.0' encoding='utf-8'?>
840
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
841
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
842
+ <html xmlns="http://www.w3.org/1999/xhtml">
843
+ <head>
844
+ <title>Cover</title>
845
+ <meta http-equiv="Content-Type" content='text/html; charset=utf-8' />
846
+ <link rel="stylesheet" href="css/xhtml.css" type="text/css" />
847
+ <style type="text/css"> img { max-width: 100%; } </style>
848
+ </head>
849
+ <body xml:lang="en">
850
+ <div class="svg_outer">
851
+ <div class="svg_inner">
852
+ <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">
853
+ <image width="#{@md.make.cover_image[:w]}" height="#{@md.make.cover_image[:h]}" xl:href="image/#{@md.make.cover_image[:cover]}" />
854
+ </svg>
855
+ </div>
856
+ </div>
857
+ </body>
858
+ </html>
859
+ WOK
860
+ filename_xhtml.puts cover_image,"\n"
861
+ filename_xhtml.close
862
+ end
863
+ rescue
864
+ SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
865
+ __LINE__.to_s + ':' + __FILE__
866
+ end
867
+ end
868
+ end
869
+ def make_segtoc
870
+ begin
871
+ if @make.build.toc?
872
+ filename_xhtml=@make_file.epub.xhtml_index
873
+ @output.each do |para|
874
+ para=para.strip
875
+ unless para =~/\A\s*\Z/
876
+ filename_xhtml.puts para,"\n"
877
+ end
878
+ end
879
+ filename_xhtml.close
880
+ end
881
+ rescue
882
+ SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
883
+ __LINE__.to_s + ':' + __FILE__
884
+ end
885
+ end
886
+ end
887
+ end
888
+ end
889
+ end
890
+ __END__