sisu 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,893 @@
1
+ # encoding: utf-8
2
+ =begin
3
+
4
+ * Name: SiSU
5
+
6
+ ** Description: documents, structuring, processing, publishing, search
7
+ *** metadata harvest, extract topics and associated writings from document set
8
+ (topics use topic_register header)
9
+
10
+ ** Author: Ralph Amissah
11
+ <ralph@amissah.com>
12
+ <ralph.amissah@gmail.com>
13
+
14
+ ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
15
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
16
+ All Rights Reserved.
17
+
18
+ ** License: GPL 3 or later:
19
+
20
+ SiSU, a framework for document structuring, publishing and search
21
+
22
+ Copyright (C) Ralph Amissah
23
+
24
+ This program is free software: you can redistribute it and/or modify it
25
+ under the terms of the GNU General Public License as published by the Free
26
+ Software Foundation, either version 3 of the License, or (at your option)
27
+ any later version.
28
+
29
+ This program is distributed in the hope that it will be useful, but WITHOUT
30
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
31
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
32
+ more details.
33
+
34
+ You should have received a copy of the GNU General Public License along with
35
+ this program. If not, see <http://www.gnu.org/licenses/>.
36
+
37
+ If you have Internet connection, the latest version of the GPL should be
38
+ available at these locations:
39
+ <http://www.fsf.org/licensing/licenses/gpl.html>
40
+ <http://www.gnu.org/licenses/gpl.html>
41
+
42
+ <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
43
+
44
+ ** SiSU uses:
45
+ * Standard SiSU markup syntax,
46
+ * Standard SiSU meta-markup syntax, and the
47
+ * Standard SiSU object citation numbering and system
48
+
49
+ ** Hompages:
50
+ <http://www.jus.uio.no/sisu>
51
+ <http://www.sisudoc.org>
52
+
53
+ ** Git
54
+ <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
55
+ <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/harvest_topics.rb;hb=HEAD>
56
+
57
+ =end
58
+ module SiSU_HarvestTopics
59
+ require_relative 'html_harvest_author_format' # html_harvest_author_format.rb
60
+ require_relative 'html_parts' # html_parts.rb
61
+ class Songsheet
62
+ @@the_idx_topics={}
63
+ def initialize(opt,env)
64
+ @opt,@env=opt,env
65
+ @file_list=opt.files
66
+ end
67
+ def songsheet
68
+ idx_array={}
69
+ @opt.f_pths.each do |y|
70
+ lang_hash_file_array={}
71
+ name=y[:f]
72
+ filename=y[:pth] + '/' + y[:f]
73
+ File.open(filename,'r') do |file|
74
+ file.each_line("\n\n") do |line|
75
+ if line =~/^@(?:title|creator|classify):(?:\s|$)/m
76
+ lang_hash_file_array[y[:lng_is]] ||= []
77
+ lang_hash_file_array[y[:lng_is]] << line
78
+ elsif line =~/^@\S+?:(?:\s|$)/m \
79
+ or line =~/^(?:\s*\n|\s*$|%+ )/
80
+ else break
81
+ end
82
+ end
83
+ end
84
+ lang_hash_file_array.each_pair do |lang,a|
85
+ idx_array[lang] ||=[]
86
+ idx_array=SiSU_HarvestTopics::Harvest.new(
87
+ @opt,
88
+ @env,
89
+ a,
90
+ filename,
91
+ name,
92
+ idx_array,
93
+ lang
94
+ ).extract_harvest
95
+ end
96
+ end
97
+ the_hash=SiSU_HarvestTopics::Index.new(
98
+ @opt,
99
+ @env,
100
+ idx_array,
101
+ @@the_idx_topics
102
+ ).song
103
+ SiSU_HarvestTopics::OutputIndex.new(
104
+ @opt,
105
+ the_hash
106
+ ).html_print.html_songsheet
107
+ end
108
+ end
109
+ class Mix
110
+ def spaces
111
+ Ax[:spaces]
112
+ end
113
+ end
114
+ class Harvest
115
+ def initialize(opt,env,data,filename,name,idx_array,lang)
116
+ @opt, @env,@data,@filename,@name,@idx_array,@lang=
117
+ opt,env, data, filename, name, idx_array, lang
118
+ end
119
+ def extract_harvest
120
+ data, filename, name, idx_array, lang=
121
+ @data,@filename,@name,@idx_array,@lang
122
+ @idx_lst=@title=@subtitle=@fulltitle=@author=@author_format=nil
123
+ rgx={}
124
+ rgx[:author]=/^@creator:(?:[ ]+|.+?:author:[ ]+)(.+?)(?:\||\n)/m
125
+ rgx[:title]=/^@title:[ ]+(.+)/
126
+ rgx[:subtitle]=/^@title:.+?:subtitle:[ ]+(.+?)\n/m
127
+ rgx[:idx]=/^@classify:.+?:topic_register:[ ]+(.+?)(?:\n\n|\n\s+:\S|\n%)/m
128
+ data.each do |para|
129
+ if para=~ rgx[:idx]
130
+ @idx_list=(rgx[:idx].match(para)[1]).split(/\s*\n\s*/).join
131
+ end
132
+ if para=~ rgx[:title]
133
+ @title=rgx[:title].match(para)[1]
134
+ end
135
+ if para=~ rgx[:subtitle]
136
+ @subtitle=rgx[:subtitle].match(para)[1]
137
+ end
138
+ if para=~ rgx[:author]
139
+ @author_format=rgx[:author].match(para)[1]
140
+ end
141
+ break if @title && @subtitle && @author && @idx_lst
142
+ end
143
+ @fulltitle=@subtitle ? (@title + ' - ' + @subtitle) : @title
144
+ if @title \
145
+ and @author_format \
146
+ and @idx_list
147
+ creator=SiSU_FormatAuthor::Author.new(@author_format.strip).author_details
148
+ @authors,@authorship=creator[:authors],creator[:authorship]
149
+ file=if name=~/~[a-z]{2,3}\.ss[mt]$/
150
+ name.sub(/~[a-z]{2,3}\.ss[mt]$/,'')
151
+ else
152
+ name.sub(/\.ss[mt]$/,'')
153
+ end
154
+ page=if @env.output_dir_structure.by? == :language
155
+ "#{lang}/sisu_manifest.html"
156
+ else
157
+ "sisu_manifest.#{lang}.html"
158
+ end
159
+ idx_array[lang] <<=if @idx_list =~/;/
160
+ g=@idx_list.scan(/[^;]+/)
161
+ g.each.map do |i|
162
+ i=i.strip
163
+ {
164
+ filename: filename,
165
+ file: file,
166
+ rough_idx: i,
167
+ title: @fulltitle,
168
+ author: creator,
169
+ page: page,
170
+ lang: lang
171
+ }
172
+ end
173
+ else {
174
+ filename: filename,
175
+ file: file,
176
+ rough_idx: @idx_list,
177
+ title: @fulltitle,
178
+ author: creator,
179
+ page: page,
180
+ lang: lang,
181
+ }
182
+ end
183
+ else
184
+ if (@opt.act[:verbose_plus][:set]==:on \
185
+ || @opt.act[:maintenance][:set]==:on)
186
+ p "missing required field in #{@filename} - [title]: <<#{@title}>>; [author]: <<#{@author_format}>>; [idx]: <<#{@idx_list}>>"
187
+ end
188
+ end
189
+ idx_array[lang]=idx_array[lang].flatten
190
+ idx_array
191
+ end
192
+ end
193
+ class Index < Mix
194
+ def initialize(opt,env,idx_array,the_idx)
195
+ @opt, @env,@idx_array,@the_idx=
196
+ opt,env, idx_array, the_idx
197
+ @@the_idx_topics=@the_idx
198
+ end
199
+ def song
200
+ the_idx=construct_book_topic_keys
201
+ construct_book_topic_hash(the_idx)
202
+ end
203
+ def capital(txt)
204
+ txt_a=txt.scan(/\S+/)
205
+ tx=''
206
+ txt_a.each do |t|
207
+ tx += t[0].chr.capitalize + t[1,txt.length] + ' '
208
+ end
209
+ tx.strip
210
+ end
211
+ def capital_(txt)
212
+ txt[0].chr.capitalize + txt[1,txt.length]
213
+ end
214
+ def contents(idx,lang)
215
+ names=''
216
+ idx[:author][:last_first_format_a].each do |n|
217
+ s=n.sub(/(.+?)(?:,.+|$)/,'\1').gsub(/\s+/,'_')
218
+ names=if @env.output_dir_structure.by? == :language
219
+ names += %{<a href="authors.html##{s}">#{n}</a>, }
220
+ else
221
+ names += %{<a href="authors.#{lang}.html##{s}">#{n}</a>, }
222
+ end
223
+ end
224
+ {
225
+ filename: idx[:filename],
226
+ file: idx[:file],
227
+ author: names,
228
+ title: idx[:title],
229
+ page: idx[:page]
230
+ }
231
+ end
232
+ def capital_(txt)
233
+ txt[0].chr.capitalize + txt[1,txt.length]
234
+ end
235
+ def key_create(c,alt)
236
+ x=nil
237
+ x=if c.length==6
238
+ c[0].to_s + '|' +
239
+ capital(c[1][0].to_s) + '|' +
240
+ capital(c[2][0].to_s) + '|' +
241
+ capital(c[3][0].to_s) + '|' +
242
+ capital(alt.to_s)
243
+ elsif c.length==5
244
+ c[0].to_s + '|' +
245
+ capital(c[1][0].to_s) + '|' +
246
+ capital(c[2][0].to_s) + '|' +
247
+ capital(alt.to_s)
248
+ elsif c.length==4
249
+ c[0].to_s + '|' +
250
+ capital(c[1][0].to_s) + '|' +
251
+ capital(alt.to_s)
252
+ elsif c.length==3
253
+ c[0].to_s + '|' +
254
+ capital(alt.to_s)
255
+ end
256
+ end
257
+ def construct_book_topic_keys
258
+ idx_array=@idx_array
259
+ @idx_a=[]
260
+ @the_a=[]
261
+ idx_array.each_pair do |lang,idx_arr|
262
+ @@the_idx_topics[lang] ||= {}
263
+ idx_arr.each do |idx|
264
+ if idx[:rough_idx]
265
+ idx_lst=idx[:rough_idx].scan(/[^:]+/)
266
+ else
267
+ puts "no topic register in: << #{idx[:filename]} >>"
268
+ next
269
+ end
270
+ idx_a=[]
271
+ idx_lst.each do |c|
272
+ idx_a << c.scan(/[^|\n]+/m)
273
+ end
274
+ idx_a << contents(idx,lang)
275
+ @idx_a << [lang] + idx_a
276
+ end
277
+ end
278
+ @idx_a.each do |c|
279
+ if c.length > 1 \
280
+ and c.is_a?(Array)
281
+ if c[2].is_a?(Hash)
282
+ c[1].each do |alt|
283
+ v=key_create(c,alt)
284
+ @the_a << [v, c[2]] if v
285
+ end
286
+ end
287
+ end
288
+ if c.length > 2 \
289
+ and c.is_a?(Array)
290
+ if c[3].is_a?(Hash)
291
+ c[2].each do |alt|
292
+ v=key_create(c,alt)
293
+ @the_a << [v, c[3]] if v
294
+ end
295
+ end
296
+ end
297
+ if c.length > 3 \
298
+ and c.is_a?(Array)
299
+ if c[4].is_a?(Hash)
300
+ c[3].each do |alt|
301
+ v=key_create(c,alt)
302
+ @the_a << [v, c[4]] if v
303
+ end
304
+ end
305
+ end
306
+ if c.length > 4 \
307
+ and c.is_a?(Array)
308
+ if c[5].is_a?(Hash)
309
+ c[4].each do |alt|
310
+ v=key_create(c,alt)
311
+ @the_a << [v, c[5]] if v
312
+ end
313
+ end
314
+ end
315
+ if c.length > 5 \
316
+ and c.is_a?(Array)
317
+ if c[6].is_a?(Hash)
318
+ c[5].each do |alt|
319
+ v=key_create(c,alt)
320
+ @the_a << [v, c[6]] if v
321
+ end
322
+ end
323
+ end
324
+ end
325
+ @the_a.sort_by { |x| x[0] } #; y.each {|z| puts z}
326
+ end
327
+ def construct_book_topic_hash(t)
328
+ @the_h={}
329
+ t.each do |z|
330
+ x=z[0].scan(/[^|]+/)
331
+ depth=x.length
332
+ extract=(depth-1)
333
+ k=case extract
334
+ when 4
335
+ { x[0] => { x[1] => { x[2] => { x[3] => { x[4] => z[1] } } } } }
336
+ when 3
337
+ { x[0] => { x[1] => { x[2] => { x[3] => z[1] } } } }
338
+ when 2
339
+ { x[0] => { x[1] => { x[2] => z[1] } } }
340
+ when 1
341
+ { x[0] => { x[1] => z[1] } }
342
+ when 0
343
+ { x[0] => z[1] }
344
+ end
345
+ if extract >= 0
346
+ k.each_pair do |x0,y0|
347
+ if extract == 0
348
+ @the_h[x0] ||={ md: [] }
349
+ @the_h[x0][:md] << y0
350
+ else
351
+ @the_h[x0] ||={}
352
+ end
353
+ #puts spaces*0 + x0
354
+ if extract >= 1
355
+ y0.each_pair do |x1,y1|
356
+ if extract == 1
357
+ @the_h[x0][x1] ||={ md: [] }
358
+ @the_h[x0][x1][:md] << y1
359
+ else
360
+ @the_h[x0][x1] ||={}
361
+ end
362
+ #puts spaces*1 + x1
363
+ if extract >= 2
364
+ y1.each_pair do |x2,y2|
365
+ if extract == 2
366
+ @the_h[x0][x1][x2] ||={ md: [] }
367
+ @the_h[x0][x1][x2][:md] << y2
368
+ else
369
+ @the_h[x0][x1][x2] ||={}
370
+ end
371
+ #puts spaces*2 + x2
372
+ if extract >= 3
373
+ y2.each_pair do |x3,y3|
374
+ if extract == 3
375
+ @the_h[x0][x1][x2][x3] ||={ md: [] }
376
+ @the_h[x0][x1][x2][x3][:md] << y3
377
+ else
378
+ @the_h[x0][x1][x2][x3] ||={}
379
+ end
380
+ #puts spaces*3 + x3
381
+ if extract == 4
382
+ y3.each_pair do |x4,y4|
383
+ if extract == 4
384
+ @the_h[x0][x1][x2][x3][x4] ||={ md: [] }
385
+ @the_h[x0][x1][x2][x3][x4][:md] << y4
386
+ else
387
+ @the_h[x0][x1][x2][x3][x4] ||={}
388
+ end
389
+ #puts spaces*4 + x4
390
+ if extract == 5
391
+ y4.each_pair do |x5,y5|
392
+ if extract == 5
393
+ @the_h[x0][x1][x2][x3][x4][x5] ||={ md: [] }
394
+ @the_h[x0][x1][x2][x3][x4][x5][:md] << y5
395
+ end
396
+ #puts spaces*5 + x5
397
+ end
398
+ end
399
+ end
400
+ end
401
+ end
402
+ end
403
+ end
404
+ end
405
+ end
406
+ end
407
+ end
408
+ end
409
+ end
410
+ #@the_h.each_pair { |x,y| p x; p y }
411
+ @the_h
412
+ end
413
+ def traverse_base
414
+ @the_h.each_pair do |x0,y0|
415
+ puts spaces*0 + x0 if x0.is_a?(String)
416
+ if y0.is_a?(Hash)
417
+ y0.each_pair do |x1,y1|
418
+ puts spaces*1 + x1 if x1.is_a?(String)
419
+ if y1.is_a?(Hash)
420
+ y1.each_pair do |x2,y2|
421
+ puts spaces*2 + x2 if x2.is_a?(String)
422
+ if y2.is_a?(Hash)
423
+ y2.each_pair do |x3,y3|
424
+ puts spaces*3 + x3 if x3.is_a?(String)
425
+ if y3.is_a?(Hash)
426
+ y3.each_pair do |x4,y4|
427
+ puts spaces*4 + x4 if x4.is_a?(String)
428
+ if y4.is_a?(Hash)
429
+ y4.each_pair do |x5,y5|
430
+ puts spaces*5 + x5 if x5.is_a?(String)
431
+ end
432
+ end
433
+ end
434
+ end
435
+ end
436
+ end
437
+ end
438
+ end
439
+ end
440
+ end
441
+ end
442
+ end
443
+ def traverse
444
+ @the_h.each_pair do |x0,y0|
445
+ puts spaces*0 + x0 if x0.is_a?(String)
446
+ if y0.is_a?(Hash)
447
+ if y0.has_key?(:md)
448
+ y0[:md].each { |x| puts spaces*5 + x[:title] }
449
+ end
450
+ y0.each_pair do |x1,y1|
451
+ puts spaces*1 + x1 if x1.is_a?(String)
452
+ if y1.is_a?(Hash)
453
+ if y1.has_key?(:md)
454
+ y1[:md].each { |x| puts spaces*5 + x[:title] }
455
+ end
456
+ y1.each_pair do |x2,y2|
457
+ puts spaces*2 + x2 if x2.is_a?(String)
458
+ if y2.is_a?(Hash)
459
+ if y2.has_key?(:md)
460
+ y2[:md].each { |x| puts spaces*5 + x[:title] }
461
+ end
462
+ y2.each_pair do |x3,y3|
463
+ puts spaces*3 + x3 if x3.is_a?(String)
464
+ if y3.is_a?(Hash)
465
+ if y3.has_key?(:md)
466
+ y3[:md].each { |x| puts spaces*5 + x[:title] }
467
+ end
468
+ y3.each_pair do |x4,y4|
469
+ puts spaces*4 + x4 if x4.is_a?(String)
470
+ if y4.is_a?(Hash)
471
+ if y4.has_key?(:md)
472
+ y4[:md].each { |x| puts spaces*5 + x[:title] }
473
+ end
474
+ y4.each_pair do |x5,y5|
475
+ puts spaces*5 + x4 if x4.is_a?(String)
476
+ end
477
+ end
478
+ end
479
+ end
480
+ end
481
+ end
482
+ end
483
+ end
484
+ end
485
+ end
486
+ end
487
+ end
488
+ end
489
+ class OutputIndex < Mix
490
+ require_relative 'i18n' # i18n.rb
491
+ def initialize(opt,the_idx)
492
+ @opt,@the_idx=opt,the_idx
493
+ @env=SiSU_Env::InfoEnv.new
494
+ @rc=SiSU_Env::GetInit.new.sisu_yaml.rc
495
+ @alphabet_list=%W[9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
496
+ @alph=@alphabet_list.dup
497
+ @letter=@alph.shift
498
+ end
499
+ def html_file_open
500
+ @the_idx.keys.each do |lng|
501
+ @output ||={}
502
+ @output[lng] ||={}
503
+ harvest_pth,file='',''
504
+ if @env.output_dir_structure.by? == :language
505
+ harvest_pth=@env.path.webserv + '/' \
506
+ + @opt.base_stub + '/' \
507
+ + lng + '/' \
508
+ + 'manifest'
509
+ file=harvest_pth + '/' + 'topics.html'
510
+ elsif @env.output_dir_structure.by? == :filetype
511
+ harvest_pth=@env.path.webserv + '/' \
512
+ + @opt.base_stub + '/' \
513
+ + 'manifest'
514
+ file=harvest_pth + '/' + 'topics.' + lng + '.html'
515
+ elsif @env.output_dir_structure.by? == :filename
516
+ harvest_pth=@env.path.webserv + '/' \
517
+ + @opt.base_stub
518
+ file=harvest_pth + '/' + 'topics.' + lng + '.html'
519
+ end
520
+ FileUtils::mkdir_p(harvest_pth) \
521
+ unless FileTest.directory?(harvest_pth)
522
+ fileinfo=(@opt.act[:verbose][:set]==:on \
523
+ || @opt.act[:verbose_plus][:set]==:on \
524
+ || @opt.act[:urls_selected][:set]==:on \
525
+ || @opt.act[:maintenance][:set]==:on) \
526
+ ? ("file://#{file}")
527
+ : ''
528
+ SiSU_Screen::Ansi.new(
529
+ @opt.act[:color_state][:set],
530
+ "harvest topics(#{@opt.files.length} files)",
531
+ fileinfo
532
+ ).dark_grey_title_hi unless @opt.act[:quiet][:set]==:on
533
+ @output[lng][:html]=File.new(file,'w')
534
+ if @opt.act[:maintenance][:set]==:on
535
+ @output[lng][:html_mnt]=File.new("#{@env.path.pwd}/topics.html",'w')
536
+ end
537
+ end
538
+ end
539
+ def html_file_close
540
+ @the_idx.keys.each do |lng|
541
+ @output[lng][:html].close
542
+ @output[lng][:html_mnt].close if @output[lng][:html_mnt].is_a?(File)
543
+ end
544
+ end
545
+ def html_print
546
+ def html_songsheet
547
+ #traverse
548
+ html_file_open
549
+ html_head
550
+ html_alph
551
+ html_body_traverse
552
+ html_tail
553
+ html_file_close
554
+ end
555
+ def html_body_traverse
556
+ @the_idx.each_pair do |x0,y0|
557
+ lng=x0
558
+ if x0.is_a?(String)
559
+ #do_string_name(lng,'lev0',x0)
560
+ #puts spaces*0 + x0
561
+ end
562
+ if y0.is_a?(Hash)
563
+ if y0.has_key?(:md)
564
+ y0[:md].each do |x|
565
+ #do_hash(lng,attrib,x) #lv==0 ?
566
+ #puts spaces*5 + x[:title]
567
+ end
568
+ end
569
+ y0.each_pair do |x1,y1|
570
+ if x1.is_a?(String)
571
+ do_string_name(lng,'lev0',x1)
572
+ #puts spaces*1 + x1
573
+ end
574
+ if y1.is_a?(Hash)
575
+ if y1.has_key?(:md)
576
+ y1[:md].each do |x|
577
+ do_hash(lng,0,x)
578
+ #puts spaces*5 + x[:title]
579
+ end
580
+ end
581
+ y1.each_pair do |x2,y2|
582
+ if x2.is_a?(String)
583
+ do_string(lng,'lev1',x2)
584
+ #puts spaces*2 + x2
585
+ end
586
+ if y2.is_a?(Hash)
587
+ if y2.has_key?(:md)
588
+ y2[:md].each do |x|
589
+ do_hash(lng,1,x)
590
+ #puts spaces*5 + x[:title]
591
+ end
592
+ end
593
+ y2.each_pair do |x3,y3|
594
+ if x3.is_a?(String)
595
+ do_string(lng,'lev2',x3)
596
+ #puts spaces*3 + x3
597
+ end
598
+ if y3.is_a?(Hash)
599
+ if y3.has_key?(:md)
600
+ y3[:md].each do |x|
601
+ do_hash(lng,2,x)
602
+ #puts spaces*5 + x[:title]
603
+ end
604
+ end
605
+ y3.each_pair do |x4,y4|
606
+ if x4.is_a?(String)
607
+ do_string(lng,'lev3',x4)
608
+ #puts spaces*4 + x4
609
+ end
610
+ if y4.is_a?(Hash)
611
+ if y4.has_key?(:md)
612
+ y4[:md].each do |x|
613
+ do_hash(lng,3,x)
614
+ #puts spaces*5 + x[:title]
615
+ end
616
+ end
617
+ y4.each_pair do |x5,y5|
618
+ if x5.is_a?(String)
619
+ do_string(lng,'lev4',x5)
620
+ #puts spaces*5 + x5
621
+ end
622
+ end
623
+ end
624
+ end
625
+ end
626
+ end
627
+ end
628
+ end
629
+ end
630
+ end
631
+ end
632
+ end
633
+ end
634
+ def html_head_adjust(lng,type='')
635
+ css_path,authors='',''
636
+ if @env.output_dir_structure.by? == :language
637
+ css_path=(type !~/maintenance/) \
638
+ ? '../../_sisu/css/harvest.css'
639
+ : 'harvest.css'
640
+ authors='authors.html'
641
+ elsif @env.output_dir_structure.by? == :filetype
642
+ css_path=(type !~/maintenance/) \
643
+ ? '../_sisu/css/harvest.css'
644
+ : 'harvest.css'
645
+ authors="authors.#{lng}.html"
646
+ elsif @env.output_dir_structure.by? == :filename
647
+ css_path=(type !~/maintenance/) \
648
+ ? './_sisu/css/harvest.css'
649
+ : 'harvest.css'
650
+ authors="authors.#{lng}.html"
651
+ end
652
+ ln=SiSU_i18n::Languages.new.language.list
653
+ harvest_languages=''
654
+ @the_idx.keys.each do |lg|
655
+ if @env.output_dir_structure.by? == :language
656
+ harvest_pth="../../#{lg}/manifest"
657
+ file=harvest_pth + '/' + 'topics.html'
658
+ elsif @env.output_dir_structure.by? == :filetype
659
+ harvest_pth='.'
660
+ file=harvest_pth + '/' + 'topics.' + lg + '.html'
661
+ elsif @env.output_dir_structure.by? == :filename
662
+ harvest_pth='.'
663
+ file=harvest_pth + '/topics.' + lg + '.html'
664
+ end
665
+ l=ln[lg][:t]
666
+ harvest_languages +=
667
+ %{<a href="#{file}">#{l}</a>&nbsp;&nbsp;&nbsp;}
668
+ end
669
+ sv=SiSU_Env::InfoVersion.instance.get_version
670
+ if @env.output_dir_structure.by? == :language
671
+ home_pth='../..'
672
+ output_structure_by='(output organised by language &amp; filetype)'
673
+ elsif @env.output_dir_structure.by? == :filetype
674
+ home_pth='..'
675
+ output_structure_by='(output organised by filetype)'
676
+ elsif @env.output_dir_structure.by? == :filename
677
+ home_pth='.'
678
+ output_structure_by='(output organised by filename)'
679
+ else
680
+ home_pth='.'
681
+ output_structure_by='(output organised by ?)'
682
+ end
683
+ <<WOK
684
+ <!DOCTYPE html>
685
+ <html>
686
+ <head>
687
+ <meta charset="utf-8">
688
+ <title>SiSU Metadata Harvest - Topics</title>
689
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
690
+ <meta name="dc.title" content= "SiSU metadata harvest, Topics - SiSU information Structuring Universe, Structured information Serialised Units" />
691
+ <meta name="dc.subject" content= "document structuring, ebook, publishing, PDF, LaTeX, XML, ODF, SQL, postgresql, sqlite, electronic book, electronic publishing, electronic document, electronic citation, data structure, citation systems, granular search, digital library" />
692
+ <meta name="generator" content="#{sv.project} #{sv.version} of #{sv.date_stamp} (n*x and Ruby!)" />
693
+ <link rel="generator" href="http://www.jus.uio.no/sisu/SiSU" />
694
+ <link href="#{css_path}" rel="stylesheet">
695
+ <link rel="shortcut icon" href="../_sisu/image/rb7.ico" />
696
+ </head>
697
+ <body lang="en" xml:lang="en">
698
+ <a name="top" id="top"></a>
699
+ <a name="up" id="up"></a>
700
+ <a name="start" id="start"></a>
701
+ <h1>SiSU Metadata Harvest - Topics #{output_structure_by}</h1>
702
+ <p>[<a href="#{home_pth}/index.html">&nbsp;HOME&nbsp;</a>] also see <a href="#{authors}">SiSU Metadata Harvest - Authors</a></p>
703
+ <p>#{@env.widget_static.search_form}</p>
704
+ <hr />
705
+ <p class="tiny">#{harvest_languages}</p>
706
+ <hr />
707
+ WOK
708
+ end
709
+ def html_head
710
+ @the_idx.keys.each do |lng|
711
+ @output[lng][:html_mnt] \
712
+ << html_head_adjust(lng,'maintenance') \
713
+ if @opt.act[:maintenance][:set]==:on
714
+ @output[lng][:html] << html_head_adjust(lng)
715
+ end
716
+ end
717
+ def html_alph
718
+ a=[]
719
+ a << '<p>'
720
+ @alph.each do |x|
721
+ a << ((x =~/[0-9]/) \
722
+ ? ''
723
+ : %{<a href="##{x}">#{x}</a>,&nbsp;})
724
+ end
725
+ a=a.join
726
+ @the_idx.keys.each do |lng|
727
+ @output[lng][:html_mnt] << a \
728
+ if @opt.act[:maintenance][:set]==:on
729
+ @output[lng][:html] << a
730
+ end
731
+ end
732
+ def html_tail
733
+ a =<<WOK
734
+ <hr />
735
+ <a name="bottom" id="bottom"></a>
736
+ <a name="down" id="down"></a>
737
+ <a name="end" id="end"></a>
738
+ <a name="finish" id="finish"></a>
739
+ <a name="stop" id="stop"></a>
740
+ <a name="credits"></a>
741
+ #{SiSU_Proj_HTML::Bits.new.credits_sisu}
742
+ </body>
743
+ </html>
744
+ WOK
745
+ @the_idx.keys.each do |lng|
746
+ @output[lng][:html_mnt] << a \
747
+ if @output[lng][:html_mnt].is_a?(File)
748
+ @output[lng][:html] << a
749
+ end
750
+ end
751
+ def do_html(lng,html)
752
+ @output[lng][:html] << html
753
+ end
754
+ def do_html_maintenance(lng,html)
755
+ @output[lng][:html_mnt] << html \
756
+ if @output[lng][:html_mnt].is_a?(File)
757
+ end
758
+ def do_string(lng,attrib,string)
759
+ html=%{<p class="#{attrib}">#{string}</p>}
760
+ do_html(lng,html)
761
+ do_html_maintenance(lng,html) \
762
+ if @output[lng][:html_mnt].is_a?(File)
763
+ end
764
+ def do_string_default(lng,attrib,string)
765
+ html=%{<p class="#{attrib}">#{string}</p>}
766
+ do_html(lng,html)
767
+ end
768
+ def do_string_maintenance(lng,attrib,string)
769
+ html=%{<p class="#{attrib}">#{string}</p>}
770
+ do_html_maintenance(lng,html) \
771
+ if @output[lng][:html_mnt].is_a?(File)
772
+ end
773
+ def do_string_name(lng,attrib,string)
774
+ f=/^(\S)/.match(string)[1]
775
+ if @lng != lng
776
+ @alph=@alphabet_list.dup
777
+ @letter=@alph.shift
778
+ @lng = lng
779
+ end
780
+ if @letter < f
781
+ while @letter < f
782
+ if @alph.length > 0
783
+ @letter=@alph.shift
784
+ if @output[lng][:html_mnt].is_a?(File)
785
+ @output[lng][:html_mnt] \
786
+ << %{\n<p class="letter"><a name="#{@letter}">#{@letter}</a></p><p class="book_index_lev1"><a name="#{@letter.downcase}"></a></p>}
787
+ end
788
+ @output[lng][:html] \
789
+ << %{\n<p class="letter"><a name="#{@letter}">#{@letter}</a></p><p class="book_index_lev1"><a name="#{@letter.downcase}"></a></p>}
790
+ else break
791
+ end
792
+ end
793
+ end
794
+ name=string.strip.gsub(/\s+/,'_')
795
+ html=%{<p class="#{attrib}"><a name="#{name}">#{string}</a></p>}
796
+ do_html(lng,html)
797
+ do_html_maintenance(lng,html) \
798
+ if @output[lng][:html_mnt].is_a?(File)
799
+ end
800
+ def do_array(lng,lv,array)
801
+ lv+=1
802
+ array.each do |b|
803
+ do_case(lng,lv,b)
804
+ end
805
+ end
806
+ def do_hash_md(lng,attrib,hash)
807
+ lang_code_insert=SiSU_Env::FilenameLanguageCodeInsert.new(@opt,lng).language_code_insert
808
+ manifest_at=if @env.output_dir_structure.by? == :language
809
+ hash[:file] + Sfx[:html]
810
+ elsif @env.output_dir_structure.by? == :filetype
811
+ hash[:file] + lang_code_insert + Sfx[:html]
812
+ elsif @env.output_dir_structure.by? == :filename
813
+ "./#{hash[:file]}/#{hash[:page]}"
814
+ else '' #error
815
+ end
816
+ html=%{<a href="#{manifest_at}">#{hash[:title]}</a> - #{hash[:author]}}
817
+ do_string_default(lng,attrib,html)
818
+ end
819
+ def do_hash_md_maintenance(lng,attrib,hash)
820
+ if @output[lng][:html_mnt].is_a?(File) #should not be run for presentation output
821
+ html=%{[<a href="#{hash[:file]}.sst">src</a>]&nbsp;&nbsp;<a href="file://#{@env.path.output}/#{hash[:file]}/#{hash[:page]}">#{hash[:title]}</a> - #{hash[:author]}}
822
+ do_string_maintenance(lng,attrib,html)
823
+ end
824
+ end
825
+ def do_hash(lng,lv,hash)
826
+ lv+=1
827
+ key=[]
828
+ hash.each_key do |m|
829
+ if m == :md
830
+ do_case(lng,lv,hash[m])
831
+ elsif m != :title \
832
+ and m != :author \
833
+ and m != :filename \
834
+ and m != :file \
835
+ and m != :rough_idx \
836
+ and m != :page
837
+ key << m
838
+ elsif m == :title
839
+ do_hash_md(lng,'work',hash)
840
+ do_hash_md_maintenance(lng,'work',hash)
841
+ end
842
+ end
843
+ if key.length > 0
844
+ key.sort.each do |m|
845
+ attrib="lev#{lv}"
846
+ lv==0 ? do_string_name(lng,attrib,m) : do_string(lng,attrib,m)
847
+ do_case(lng,lv,hash[m])
848
+ end
849
+ end
850
+ end
851
+ def do_case(lng,lv,a)
852
+ case a
853
+ when String
854
+ attrib="lev#{lv}"
855
+ if a=~/S/
856
+ lv==0 ? do_string_name(lng,attrib,a) : do_string(lng,attrib,a)
857
+ end
858
+ when Array
859
+ do_array(lng,lv,a)
860
+ when Hash
861
+ do_hash(lng,lv,a)
862
+ end
863
+ end
864
+ #def html_body
865
+ # the_idx=@the_idx
866
+ # the_idx.each_pair do |lng,lng_array|
867
+ # lng_array.sort.each do |a|
868
+ # do_case(lng,-1,a)
869
+ # end
870
+ # end
871
+ #end
872
+ self
873
+ end
874
+ end
875
+ end
876
+ __END__
877
+ terms -|_ t{tl1} -|_ {fa}[fa]{filenames and other details}
878
+ | |_ {tl2} -|_ {fa}[fa]{filenames and other details}
879
+ | | |_{tl3} -|_ {fa}[fa]{filenames and other details}
880
+ | | | |_{tl4} - {fa}[fa]{filenames and other details}
881
+ | | | |
882
+ | | | |_{tl4a} - {fa}[fa]{filenames and other details}
883
+ | | | |
884
+ | | | |_{tl4b} - {fa}[fa]{filenames and other details}
885
+ | | | |
886
+ | | | |_ ...
887
+ | | |
888
+ | | |_{tl3a} - {fa}[fa]{filenames and other details}
889
+ | |
890
+ | |_{tl2a} - {fa}[fa]{filenames and other details}
891
+ |
892
+ |_ t{tl1a} -|_ {fa}[fa]{filenames and other details}
893
+ |_ ...