aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2008-09-08 23:09:37 -0400
committerRalph Amissah <ralph@amissah.com>2008-09-08 23:09:37 -0400
commit1529e474fd5c8a67679438e8f2cea5cd6d26db3d (patch)
tree423bcd4766b309f928f1f41da079cfc26aa0879a /lib
parentdal, several modules split into separate files (diff)
book index, sample html file and to screen sisu markup sample added (-M flag)
Diffstat (limited to 'lib')
-rw-r--r--lib/sisu/v0/css.rb12
-rw-r--r--lib/sisu/v0/dal.rb2
-rw-r--r--lib/sisu/v0/dal_idx.rb144
-rw-r--r--lib/sisu/v0/sysenv.rb3
4 files changed, 143 insertions, 18 deletions
diff --git a/lib/sisu/v0/css.rb b/lib/sisu/v0/css.rb
index b5b08698..ec71c4f3 100644
--- a/lib/sisu/v0/css.rb
+++ b/lib/sisu/v0/css.rb
@@ -358,6 +358,18 @@ WOK
margin-top: 1px;
margin-bottom: 3px;
}
+ p.book_index_lev1 {
+ line-height: 100%;
+ margin-top: 4px;
+ margin-bottom: 1px;
+ }
+ p.book_index_lev2 {
+ line-height: 100%;
+ text-align: left;
+ margin-left: 3em;
+ margin-top: 1px;
+ margin-bottom: 3px;
+ }
p.quickref {
font-size: 10px;
diff --git a/lib/sisu/v0/dal.rb b/lib/sisu/v0/dal.rb
index d091284d..a00d307b 100644
--- a/lib/sisu/v0/dal.rb
+++ b/lib/sisu/v0/dal.rb
@@ -209,7 +209,7 @@ module SiSU_DAL
data=SiSU_images::Images.new(@md,data).images
data=SiSU_document_structure::Tables.new(@md,data).tables
data=SiSU_numbering::Numbering.new(@md,data).numbering_song
- data=SiSU_book_index::Book_index.new(data).indexing_song if @md.book_index
+ data=SiSU_book_index::Book_index.new(@md,data,@env).indexing_song if @md.book_index
data=SiSU_endnotes::Endnotes.new(@md,data,endnote_array).endnotes
data=SiSU_hash::Object_digest.new(@md,data,@env).object_digest
meta=SiSU_metadata::Metadata.new(@md,data).metadata
diff --git a/lib/sisu/v0/dal_idx.rb b/lib/sisu/v0/dal_idx.rb
index 607686a3..26fc66b6 100644
--- a/lib/sisu/v0/dal_idx.rb
+++ b/lib/sisu/v0/dal_idx.rb
@@ -61,14 +61,21 @@
=end
module SiSU_book_index
class Book_index
- def initialize(data)
- @data=data
- end
- def indexing_song
+ def initialize(md,data,env=nil)
+ @md,@data,@env=md,data,env
@rgx_idx=/#{Mx[:idx_o]}(?:.+?)#{Mx[:idx_c]}\s*/
#@rgx_idx=/\s*#{Mx[:idx_o]}(?:.+?)#{Mx[:idx_c]}\s*/
@rgx_idx_ocn_init=/#{Mx[:idx_o]}(.+?)#{Mx[:idx_c]}\s*#{Mx[:id_o]}~(\d+)\S+?#{Mx[:id_c]}/
+ @rgx_idx_ocn_seg=/(.+?)~(\d+)~(\S+)/
@rgx_idx_ocn=/(.+?)~(\d+)/
+ @rxp_lv1=/^#{Mx[:lv_o]}1:/
+ @rxp_lv2=/^#{Mx[:lv_o]}2:/
+ @rxp_lv3=/^#{Mx[:lv_o]}3:/
+ @rxp_seg=/^#{Mx[:lv_o]}4:(\S+?)#{Mx[:lv_c]}/
+ @rxp_to=Regexp.new("#{Mx[:id_o]}~(\\d+);(?:[oh]|[0-6]:)\\d+;\\w\\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}|#{Mx[:id_o]}\S+?#{Mx[:id_c]}$")
+ @env ||=SiSU_Env::Info_env.new(@md.fns)
+ end
+ def indexing_song
@data=extract_book_index(@data)
@data=clean_index(@data)
@data
@@ -77,7 +84,9 @@ module SiSU_book_index
tuned_file=[]
idx_array=[]
data.each do |para|
- idx_array << @rgx_idx_ocn_init.match(para)[0].gsub(@rgx_idx_ocn_init,'\1~\2') if para =~ @rgx_idx_ocn_init
+ if para =~@rxp_seg; @seg=para[@rxp_seg,1]
+ end
+ 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|
@@ -85,23 +94,32 @@ module SiSU_book_index
#end
idx_array=construct_idx_array(idx_array) if idx_array.length > 0
if idx_array.length > 0
- the_idx=construct_book_index(idx_array)
- screen_print(the_idx)
+ 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)
+ end
end
tuned_file
end
def construct_idx_array(idx_array)
idx_lst=[]
idx_array.each do |idx|
- idx_list,ocn=@rgx_idx_ocn.match(idx)[1,2]
+ idx_list,ocn,seg=@rgx_idx_ocn_seg.match(idx)[1..3]
idx_lst <<=if idx_list =~/;/
g=idx_list.scan(/[^;]+/)
idxl=[]
g.each do |i|
- idxl << { :rough_idx => i, :ocn => ocn }
+ idxl << { :rough_idx => i, :ocn => ocn, :seg => seg }
end
idxl
- else { :rough_idx => idx_list, :ocn => ocn }
+ else { :rough_idx => idx_list, :ocn => ocn, :seg => seg }
end
end
idx_lst.flatten!
@@ -122,20 +140,20 @@ module SiSU_book_index
x=if idx_lst.length == 1 or idx_lst[0] == i
@the_idx[use]['a1']=[] unless @the_idx[use]['a1'] and defined? @the_idx[use]['a1']
x=if r
- @the_idx[use]['a1'] << { :ocn => idx[:ocn], :range => "#{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}" }
+ @the_idx[use]['a1'] << { :ocn => idx[:ocn], :range => "#{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}", :seg => idx[:seg] }
"#{i} #{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}"
else
- @the_idx[use]['a1'] << { :ocn => idx[:ocn] }
+ @the_idx[use]['a1'] << { :ocn => idx[:ocn], :seg => idx[:seg] }
"#{i} #{idx[:ocn]}"
end
else
@the_idx[use]['b1']={} unless @the_idx[use]['b1'] and defined? @the_idx[use]['b1']
@the_idx[use]['b1'][i]=[] unless @the_idx[use]['b1'][i] and defined? @the_idx[use]['b1'][i]
x=if r
- @the_idx[use]['b1'][i] << { :ocn => idx[:ocn], :range => "#{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}" }
+ @the_idx[use]['b1'][i] << { :ocn => idx[:ocn], :range => "#{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}", :seg => idx[:seg] }
"#{idx_lst[0]}:#{i} #{idx[:ocn]}-#{idx[:ocn].to_i+r.to_i}"
else
- @the_idx[use]['b1'][i] << { :ocn => idx[:ocn] }
+ @the_idx[use]['b1'][i] << { :ocn => idx[:ocn], :seg => idx[:seg] }
"#{idx_lst[0]}:#{i} #{idx[:ocn]}"
end
end
@@ -186,6 +204,102 @@ module SiSU_book_index
end
end
end
+ def screen_html(the_idx)
+ @file_index_all << %{\n <link rel="stylesheet" href="../_sisu/css/html.css" type="text/css" />}
+ 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>, }
+ 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]
+ @file_index_all << %{<a href="#{a[:seg]}.html##{a[:ocn]}">#{a[:range]}</a>, }
+ print %{<a href="#{a[:seg]}.html##{a[:ocn]}">#{a[:range]}</a>, }
+ 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>, }
+ 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}, }
+ #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>, }
+ 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>, }
+ else p 'error'
+ end
+ end
+ @file_index_all << '</p>'
+ end
+ end
+ end
+ end
+ 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
+ end
+ end
+ end
+ end
def clean_index(data)
tuned_file=[]
data.each do |para|
@@ -196,6 +310,4 @@ module SiSU_book_index
end
end
end
-
__END__
-
diff --git a/lib/sisu/v0/sysenv.rb b/lib/sisu/v0/sysenv.rb
index ed0012e2..93e6ea8e 100644
--- a/lib/sisu/v0/sysenv.rb
+++ b/lib/sisu/v0/sysenv.rb
@@ -518,7 +518,8 @@ module SiSU_Env
:sxs => filename(code,@fnb,'.sxs.xml'),
:sxd => filename(code,@fnb,'.sxd.xml'),
:sxn => filename(code,@fnb,'.sxn.xml'),
- :sisupod => filename(nil,@fnz,'')
+ :sisupod => filename(nil,@fnz,''),
+ :book_index => filename(code,'book_index','.html'),
}
@fn
end