aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v0/dal_idx.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v0/dal_idx.rb')
-rw-r--r--lib/sisu/v0/dal_idx.rb157
1 files changed, 74 insertions, 83 deletions
diff --git a/lib/sisu/v0/dal_idx.rb b/lib/sisu/v0/dal_idx.rb
index 26fc66b6..74ec0d15 100644
--- a/lib/sisu/v0/dal_idx.rb
+++ b/lib/sisu/v0/dal_idx.rb
@@ -76,9 +76,10 @@ module SiSU_book_index
@env ||=SiSU_Env::Info_env.new(@md.fns)
end
def indexing_song
- @data=extract_book_index(@data)
- @data=clean_index(@data)
- @data
+ data=@data
+ data,sisu_markup_idx,html_idx=extract_book_index(data)
+ data=clean_and_insert_index(data,sisu_markup_idx)
+ [data,sisu_markup_idx,html_idx]
end
def extract_book_index(data)
tuned_file=[]
@@ -89,24 +90,30 @@ module SiSU_book_index
idx_array << @rgx_idx_ocn_init.match(para)[0].gsub(@rgx_idx_ocn_init,"\\1~\\2~#{@seg}") if para =~ @rgx_idx_ocn_init
tuned_file << para if para
end
- #idx_array.each do |i|
- # i.gsub!(@rgx_idx_ocn_init,'\1~\2')
- #end
idx_array=construct_idx_array(idx_array) if idx_array.length > 0
if idx_array.length > 0
- if @md.cmd.inspect =~/M/
- the_idx=construct_book_index(idx_array)
- screen_print(the_idx) if @md.cmd.inspect =~/M/
- puts "\n---"
- path="#{@env.path.output}/#{@md.fnb}"
- @file_index_all=File.open("#{path}/#{@md.fn[:book_index]}",'w')
- screen_html(the_idx)
- @file_index_all.close
- puts "\n---"
- screen_sisu_markup(the_idx)
+ the_idx=construct_book_index(idx_array)
+ #screen_print(the_idx) if @md.cmd.inspect =~/V/
+ sisu_markup_idx,html_idx=nil,nil
+ if @md.book_index
+ idx=index(the_idx)
+ output_html_idx(idx[:html])
+ html_idx=idx[:html]
+ sisu_markup_idx=idx[:sst]
end
end
- tuned_file
+ [tuned_file,sisu_markup_idx,html_idx]
+ end
+ def output_html_idx(html_idx)
+ if @md.book_index
+ path="#{@env.path.output}/#{@md.fnb}"
+ Dir.mkdir(path) unless FileTest.directory?(path)
+ html_index_file=File.new("#{path}/#{@md.fn[:book_index]}",'w')
+ puts "#{path}/#{@md.fn[:book_index]}"
+ #html_file(the_idx)
+ html_idx.each {|x| html_index_file << x }
+ html_index_file.close
+ end
end
def construct_idx_array(idx_array)
idx_lst=[]
@@ -163,11 +170,22 @@ module SiSU_book_index
#p the_idx; p '-----'
the_idx
end
- def screen_print(the_idx)
+ def index(the_idx)
+ @x=1
+ @idx={}
+ @idx[:sst],@idx[:html]=[],[]
+ @idx[:sst] << "\n\n#{Mx[:br_page_new]}"
+ @idx[:sst] << "\n\n#{Mx[:lv_o]}2:#{Mx[:lv_c]}Index #{Mx[:id_o]}~0;0:0;x0#{Mx[:id_c]}"
+ @idx[:sst] << "\n\n#{Mx[:lv_o]}4:idx#{Mx[:lv_c]} [Index] #{Mx[:pa_non_object_dummy_heading]} #{Mx[:id_o]}~0;0:0;x0#{Mx[:id_c]}"
the_idx.each do |i|
i.each do |x|
if x.class == String
- print "\n" + x + ', '
+ @idx[:sst] << %{\n\n#{Mx[:fa_bold_o]}#{x},#{Mx[:fa_bold_c]} }
+ aname=x.gsub(/\s+/,'_')
+ @idx[:html] << %{\n<p class="book_index_lev1"><a name="##{aname}"><b>#{x}</b></a>, }
+ @o=@idx[:sst].index(@idx[:sst].last) #@o=@idx[:sst].length - 1
+ @q=@idx[:html].index(@idx[:html].last) #@o=@idx[:html].length - 1
+ print "\n" + x + ', ' if @md.cmd =~/V/
elsif x.class == Array
p 'array error? -->'
print x
@@ -175,43 +193,55 @@ module SiSU_book_index
if x['a1'].class == Array
x['a1'].each do |a|
if a[:range]
- print a[:range] + ', '
+ @idx[:sst][@o]=@idx[:sst][@o] + %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{a[:seg]}.html##{a[:ocn]}, }
+ @idx[:html][@q]=@idx[:html][@q] + %{<a href="#{a[:seg]}.html##{a[:ocn]}">#{a[:range]}</a>, }
+ print a[:range] + ', ' if @md.cmd =~/V/
elsif a[:ocn]
- print a[:ocn] + ', '
+ @idx[:sst][@o]=@idx[:sst][@o] + %{#{Mx[:lnk_o]}#{a[:ocn]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{a[:seg]}.html##{a[:ocn]}, }
+ @idx[:html][@q]=@idx[:html][@q] + %{<a href="#{a[:seg]}.html##{a[:ocn]}">#{a[:ocn]}</a>, }
+ print a[:ocn] + ', ' if @md.cmd =~/V/
else p 'error'
end
end
+ @idx[:html][@q]=@idx[:html][@q] + '</p>'
end
if x['b1']
m=x['b1']
m=m.sort
m.each do |k,y|
if k !~/a1/
- print "\n\t" + k + ', '
- #p y
+ @idx[:sst][@o]=@idx[:sst][@o] + %{#{k}, }
+ @idx[:html][@q]=@idx[:html][@q] + %{\n<p class="book_index_lev2">#{k}, }
+ print "\n\t" + k + ', ' if @md.cmd =~/V/
y.each do |z|
if z[:range]
- print z[:range] + ', '
+ @idx[:sst][@o]=@idx[:sst][@o] + %{#{Mx[:lnk_o]}#{z[:range]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{z[:seg]}.html##{z[:ocn]}, }
+ @idx[:html][@q]=@idx[:html][@q] + %{<a href="#{z[:seg]}.html##{z[:ocn]}">#{z[:range]}</a>, }
+ print z[:range] + ', ' if @md.cmd =~/V/
elsif z[:ocn]
- print z[:ocn] + ', '
+ @idx[:sst][@o]=@idx[:sst][@o] + %{#{Mx[:lnk_o]}#{z[:ocn]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{z[:seg]}.html##{z[:ocn]}, }
+ @idx[:html][@q]=@idx[:html][@q] + %{<a href="#{z[:seg]}.html##{z[:ocn]}">#{z[:ocn]}</a>, }
+ print z[:ocn] + ', ' if @md.cmd =~/V/
else p 'error'
end
end
+ @idx[:html][@q]=@idx[:html][@q] + '</p>'
end
end
end
+ @idx[:sst][@o]=@idx[:sst][@o] + " #{Mx[:id_o]}~0;0:0;x#{@x}#{Mx[:id_c]}"
+ @x +=1
end
end
end
+ print "\n" if @md.cmd =~/V/
+ @idx
end
- def screen_html(the_idx)
- @file_index_all << %{\n <link rel="stylesheet" href="../_sisu/css/html.css" type="text/css" />}
+ def screen_print(the_idx)
the_idx.each do |i|
i.each do |x|
if x.class == String
- @file_index_all << %{\n<p class="book_index_lev1"><b>#{x}</b>, }
- #@file_index_all << %{<br />\n<b>#{x}</b>, }
- print %{<br />\n<b>#{x}</b>, }
+ print "\n" + x + ', '
elsif x.class == Array
p 'array error? -->'
print x
@@ -219,36 +249,28 @@ module SiSU_book_index
if x['a1'].class == Array
x['a1'].each do |a|
if a[:range]
- @file_index_all << %{<a href="#{a[:seg]}.html##{a[:ocn]}">#{a[:range]}</a>, }
- print %{<a href="#{a[:seg]}.html##{a[:ocn]}">#{a[:range]}</a>, }
+ print a[:range] + ', '
elsif a[:ocn]
- @file_index_all << %{<a href="#{a[:seg]}.html##{a[:ocn]}">#{a[:ocn]}</a>, }
- print %{<a href="#{a[:seg]}.html##{a[:ocn]}">#{a[:ocn]}</a>, }
+ print a[:ocn] + ', '
else p 'error'
end
end
- @file_index_all << '</p>'
end
if x['b1']
m=x['b1']
m=m.sort
m.each do |k,y|
if k !~/a1/
- @file_index_all << %{\n<p class="book_index_lev2">#{k}, }
- #@file_index_all << %{<br />\n\t#{k}, }
- print %{<br />\n\t#{k}, }
+ print "\n\t" + k + ', '
#p y
y.each do |z|
if z[:range]
- @file_index_all << %{<a href="#{z[:seg]}.html##{z[:ocn]}">#{z[:range]}</a>, }
- print %{<a href="#{z[:seg]}.html##{z[:ocn]}">#{z[:range]}</a>, }
+ print z[:range] + ', '
elsif z[:ocn]
- @file_index_all << %{<a href="#{z[:seg]}.html##{z[:ocn]}">#{z[:ocn]}</a>, }
- print %{<a href="#{z[:seg]}.html##{z[:ocn]}">#{z[:ocn]}</a>, }
+ print z[:ocn] + ', '
else p 'error'
end
end
- @file_index_all << '</p>'
end
end
end
@@ -256,49 +278,18 @@ module SiSU_book_index
end
end
end
- def screen_sisu_markup(the_idx)
- the_idx.each do |i|
- i.each do |x|
- if x.class == String
- print %{\n\n#{Mx[:fa_bold_o]}#{x}#{Mx[:fa_bold_c]}, }
- #print %{\n\n#{Mx[:gr_o]}\n#{Mx[:fa_bold_o]}#{x}#{Mx[:fa_bold_c]}, }
- #print "\n" + x + ', '
- elsif x.class == Array
- p 'array error? -->'
- print x
- elsif x.class == Hash
- if x['a1'].class == Array
- x['a1'].each do |a|
- if a[:range]
- print %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{a[:seg]}.html##{a[:ocn]}, }
- elsif a[:ocn]
- print %{#{Mx[:lnk_o]}#{a[:ocn]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{a[:seg]}.html##{a[:ocn]}, }
- else p 'error'
- end
- end
- end
- if x['b1']
- m=x['b1']
- m=m.sort
- m.each do |k,y|
- if k !~/a1/
- print %{\n #{k}, }
- #print "\n\t" + k + ', '
- y.each do |z|
- if z[:range]
- print %{#{Mx[:lnk_o]}#{z[:range]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{z[:seg]}.html##{z[:ocn]}, }
- elsif z[:ocn]
- print %{#{Mx[:lnk_o]}#{z[:ocn]}#{Mx[:lnk_c]}#{@env.url.root}/#{@md.fnb}/#{z[:seg]}.html##{z[:ocn]}, }
- else p 'error'
- end
- end
- puts " #{Mx[:id_o]}~0;0:0;u0#{Mx[:id_c]}"
- end
- end
- end
+ def clean_and_insert_index(data,sisu_markup_idx)
+ tuned_file=[]
+ data.each do |para|
+ para.gsub!(/\n*#{@rgx_idx}/m,'')
+ tuned_file << para
+ if para =~/#{Mx[:br_endnotes]}/ and sisu_markup_idx
+ sisu_markup_idx.each do |idx|
+ tuned_file << idx
end
end
end
+ tuned_file
end
def clean_index(data)
tuned_file=[]