3cb87577ce038e5ecf42fc2a3c0e34ed4adbddb6
[software/sisu] / lib / sisu / develop / html_minitoc.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** html minitoc
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/develop/html_minitoc.rb;hb=HEAD>
55
56 =end
57 module SiSU_HTML_MiniToc
58 require_relative 'html_tune' # html_tune.rb
59 include SiSU_HTML_Tune
60 class TocMini
61 @@seg_mini=nil
62 @@seg_url=''
63 @@firstseg=nil
64 def initialize(md,data)
65 @md,@data=md,data
66 @pat_strip_heading_name=/<a name="h?\d.*?">(.+?)<\/a>/
67 @ocn_html_identifier=SiSU_Env::ProcessingSettings.new(@md).ocn_html_identifier
68 @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) if @md
69 end
70 def songsheet
71 if (@md.opt.act[:verbose][:set]==:on \
72 || @md.opt.act[:verbose_plus][:set]==:on \
73 || @md.opt.act[:maintenance][:set]==:on)
74 SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Toc').txt_grey
75 end
76 toc=nil
77 @toc=[]
78 @data.each do |txt|
79 if txt.is ==:heading \
80 || txt.is ==:heading_insert
81 txt.obj=txt.obj.gsub(/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]}).+?(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,''). #remove endnotes from toc
82 gsub(/<a name="-\d+" href="#_\d+">&nbsp;<sup>\d+<\/sup>&nbsp;<\/a>/,'').
83 gsub(@pat_strip_heading_name,'\1')
84 #gsub(/(.*?)<a name="(\d+)"><\/a>(.*)/,'\1') #2002w42 altered gsub - problematic? - suspect
85 toc=case txt.ln
86 when 0 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_0
87 when 1 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_1
88 when 2 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_2
89 when 3 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_3
90 when 4 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_4
91 when 5 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_5
92 when 6 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_6
93 else
94 end
95 @toc << toc
96 end
97 end
98 @toc
99 end
100 protected
101 def level_concordance
102 format_head_toc=SiSU_HTML_Format::HeadToc.new(@md)
103 @@seg_mini << format_head_toc.mini_seg_concordance
104 end
105 def level_metadata
106 format_head_toc=SiSU_HTML_Format::HeadToc.new(@md)
107 @@seg_mini << format_head_toc.mini_seg_metadata
108 end
109 def level_word_index
110 format_head_toc=SiSU_HTML_Format::HeadToc.new(@d0c)
111 @@seg_mini << format_head_toc.mini_concordance
112 end
113 def level_0
114 txt=@data
115 if (txt.is ==:heading \
116 || txt.is ==:heading_insert) \
117 && txt.ocn !=0
118 txt.obj=txt.obj.gsub(@pat_strip_heading_name,'\1')
119 end
120 txt_obj={ txt: txt.obj }
121 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
122 toc_mini=format_toc.mini_lev0
123 toc_mini
124 end
125 def level_1
126 txt=@data
127 if (txt.is ==:heading \
128 || txt.is ==:heading_insert) \
129 && txt.ocn !=0
130 txt.obj=txt.obj.gsub(@pat_strip_heading_name,'\1')
131 end
132 title=unless txt.obj =~/Document Information/ then txt.obj
133 else
134 link='metadata'
135 %{<b><a href="#{link}#{@md.lang_code_insert}#{Sfx[:html]}">#{txt.obj}</a></b>}
136 end
137 txt_obj={ txt: title }
138 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
139 toc_mini=if txt.name =~/^meta/ \
140 and txt.obj=~/Document Information/
141 format_toc.mini_tail
142 else format_toc.mini_lev1
143 end
144 toc_mini
145 end
146 def level_2
147 txt=@data
148 if (txt.is ==:heading \
149 || txt.is ==:heading_insert) \
150 && txt.ocn !=0
151 txt.obj=txt.obj.gsub(@pat_strip_heading_name,'\1')
152 end
153 txt_obj={ txt: txt.obj }
154 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
155 toc_mini=format_toc.mini_lev2
156 toc_mini
157 end
158 def level_3
159 txt=@data
160 txt_obj={ txt: txt.obj }
161 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
162 toc_mini=format_toc.mini_lev3
163 toc_mini
164 end
165 def level_4
166 txt=@data
167 unless txt =~/~metadata/
168 if txt.ln ==4
169 fnh={
170 fn: txt.name,
171 }
172 f=@md.file.base_filename.html_seg(fnh)
173 seg_link=%{ <a href="#{f}" target="_top">
174 #{txt.obj}
175 </a> }
176 @@seg_url=txt.name
177 elsif txt.obj =~/\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+/
178 fn,hd=/^(\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+)(.*)/.match(dob.obj)[1,2]
179 fnh={
180 fn: fn,
181 }
182 f=@md.file.base_filename.html_seg(fnh)
183 seg_link=%{<a href="#{f}" target="_top">#{fn} #{hd}</a> }
184 end
185 txt_obj={ txt: seg_link }
186 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
187 toc_mini=format_toc.mini_lev4
188 toc_mini
189 end
190 end
191 def level_5
192 txt=@data
193 if (txt.is ==:heading \
194 || txt.is ==:heading_insert) \
195 && txt.ocn !=0
196 txt.obj=txt.obj.gsub(@pat_strip_heading_name,'\1')
197 end
198 fnh={
199 fn: @@seg_url,
200 }
201 f=@md.file.base_filename.html_seg(fnh)
202 lnk_n_txt=%{ <a href="#{f}##{@ocn_html_identifier}#{txt.ocn}">
203 #{txt.obj}
204 </a>}
205 txt_obj={ txt: lnk_n_txt }
206 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
207 toc_mini=format_toc.mini_lev5
208 toc_mini
209 end
210 def level_6
211 txt=@data
212 if (txt.is ==:heading \
213 || txt.is ==:heading_insert) \
214 && txt.ocn !=0
215 txt.obj=txt.obj.gsub(@pat_strip_heading_name,'\1')
216 end
217 fnh={
218 fn: @@seg_url,
219 }
220 f=@md.file.base_filename.html_seg(fnh)
221 lnk_n_txt=%{ <a href="#{f}##{@ocn_html_identifier}#{txt.ocn}">
222 #{txt.obj}
223 </a>}
224 txt_obj={ txt: lnk_n_txt }
225 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
226 toc_mini=format_toc.mini_lev6
227 toc_mini
228 end
229 end
230 end
231 __END__