From a6651effc29a5805599657e3cbeb6c44de62be1e Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 9 Jun 2011 22:12:11 -0400 Subject: v3: harvest, work for alt output structures; for each language * paths to document manifests etc. for the possible output dir structures * author and topic lists for available documents, by availability in each language --- lib/sisu/v3/harvest.rb | 80 +++---- lib/sisu/v3/harvest_authors.rb | 233 ++++++++++++--------- lib/sisu/v3/harvest_topics.rb | 458 ++++++++++++++++++++++++----------------- lib/sisu/v3/hub.rb | 2 +- 4 files changed, 446 insertions(+), 327 deletions(-) (limited to 'lib/sisu') diff --git a/lib/sisu/v3/harvest.rb b/lib/sisu/v3/harvest.rb index aaec9046..47380c2e 100644 --- a/lib/sisu/v3/harvest.rb +++ b/lib/sisu/v3/harvest.rb @@ -58,45 +58,51 @@ ** Description: system environment, resource control and configuration details =end -def help - puts <> ") - end - files.each do |filename| - file_array=[] + puts 'authors:' + idx_array={} + @opt.f_pths.each do |y| + lang_hash_file_array={} + name=y[:f] + filename=y[:pth] + '/' + y[:f] File.open(filename,'r') do |file| file.each_line("\n\n") do |line| if line =~/^@(?:title|creator|date):(?:\s|$)/m - file_array << line + lang_hash_file_array[y[:lng_is]] ||= [] + lang_hash_file_array[y[:lng_is]] << line elsif line =~/^@\S+?:(?:\s|$)/m \ or line =~/^(?:\s*\n|%+ )/ else break end end end - idx_array=HARVEST_authors::Harvest.new(file_array,filename,idx_array).extract_harvest + lang_hash_file_array.each_pair do |lang,a| + idx_array[lang] ||= [] + idx_array=HARVEST_authors::Harvest.new(@opt,@env,a,filename,name,idx_array,lang).extract_harvest + end end the_idx=HARVEST_authors::Index.new(idx_array,@@the_idx_authors).construct_book_author_index HARVEST_authors::Output_index.new(@opt,the_idx).html_print.html_songsheet - harvest_pth="#{@env.path.webserv}/#{@env.stub_md_harvest}" - puts "file://#{harvest_pth}/harvest_authors.html" - puts "file://#{@env.path.pwd}/harvest_authors.html" if @opt.cmd.inspect =~/M/ end end class Harvest - def initialize(data,filename,idx_array) - @data,@filename,@idx_array=data,filename,idx_array + def initialize(opt,env,data,filename,name,idx_array,lang) + @opt,@env,@data,@filename,@name,@idx_array,@lang=opt,env,data,filename,name,idx_array,lang end def extract_harvest - data,filename,idx_array=@data,@filename,@idx_array + data,filename,name,idx_array,lang=@data,@filename,@name,@idx_array,@lang @title,@subtitle,@fulltitle,@author,@author_format,@date=nil,nil,nil,nil,nil,nil @authors=[] rgx={} @@ -123,22 +121,25 @@ module HARVEST_authors break if @title and @subtitle and @author and @date end @fulltitle=@subtitle ? (@title + ' - ' + @subtitle) : @title - if @title and @author_format + if @title \ + and @author_format creator=FORMAT::Author.new(@author_format.strip).author_details @authors,@authorship=creator[:authors],creator[:authorship] - file=if filename=~/~[a-z]{2,3}\.ss[mt]$/ - lang='.' + /~([a-z]{2,3})\.ss[mt]$/.match(filename)[1] - filename.sub(/~[a-z]{2,3}\.ss[mt]$/,'') + file=if name=~/~[a-z]{2,3}\.ss[mt]$/ + name.sub(/~[a-z]{2,3}\.ss[mt]$/,'') else - lang='' - filename.sub(/\.ss[mt]$/,'') + name.sub(/\.ss[mt]$/,'') end - page="sisu_manifest#{lang}.html" - idx_array <<= { filename: filename, file: file, date: @date, title: @fulltitle, author: creator, page: page } + page=if @env.output_dir_structure.by_language_code? + "#{lang}/sisu_manifest.html" + else + "sisu_manifest.#{lang}.html" + end + idx_array[lang] <<= { filename: filename, file: file, date: @date, title: @fulltitle, author: creator, page: page, lang: lang } else #p "missing author field: #{@filename} title: #{@title}; author: #{@author_format}" end - idx_array.flatten! + idx_array[lang].flatten! idx_array end end @@ -152,38 +153,55 @@ module HARVEST_authors end def construct_book_author_index idx_array=@idx_array - idx_array.each do |idx| - idx[:author][:last_first_format_a].each do |author| - author.strip! - if @@the_idx_authors[author].class==NilClass - @@the_idx_authors[author]={ md: [] } + idx_array.each_pair do |lang,idx_array| + @@the_idx_authors[lang] ||= {} + idx_array.each do |idx| + idx[:author][:last_first_format_a].each do |author| + author.strip! + if @@the_idx_authors[lang][author].class==NilClass + @@the_idx_authors[lang][author]={ md: [] } + end + @@the_idx_authors[lang][author][:md] << { filename: idx[:filename], file: idx[:file], author: idx[:author], title: idx[:title], date: idx[:date], page: idx[:page], lang: idx[:lang] } end - @@the_idx_authors[author][:md] << { filename: idx[:filename], file: idx[:file], author: idx[:author], title: idx[:title], date: idx[:date], page: idx[:page] } end end @the_idx=@@the_idx_authors end end class Output_index + require_relative 'i18n' # i18n.rb + require 'fileutils' + include FileUtils def initialize(opt,the_idx) @opt,@the_idx=opt,the_idx @env=SiSU_Env::Info_env.new - @rc=Get_init.instance.sisu_yaml.rc + @rc=SiSU_Env::Get_init.instance.sisu_yaml.rc @alph=%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] @letter=@alph.shift @vz=SiSU_Env::Get_init.instance.skin end def html_file_open - @output={} - harvest_pth="#{@env.path.webserv}/#{@env.stub_md_harvest}" - @output[:html]=File.new("#{harvest_pth}/harvest_authors.html",'w') - @output[:html_mnt]=(@opt.cmd.inspect =~/M/) \ - ? File.new("#{@env.path.pwd}/harvest_authors.html",'w') \ - : nil + @the_idx.keys.each do |lng| + @output ||={} + @output[lng] ||={} + harvest_pth,file='','' + if @env.output_dir_structure.by_language_code? + harvest_pth="#{@env.path.webserv}/#{@opt.base_stub}/#{lng}/manifest" + file="#{harvest_pth}/authors.html" + else + harvest_pth="#{@env.path.webserv}/#{@opt.base_stub}/manifest" + file="#{harvest_pth}/authors.#{lng}.html" + end + mkdir_p(harvest_pth) unless FileTest.directory?(harvest_pth) + puts "file://#{file}" + @output[lng][:html]=File.new(file,'w') + end end def html_file_close - @output[:html].close - @output[:html_mnt].close if @output[:html_mnt].class==File + @the_idx.keys.each do |lng| + @output[lng][:html].close + @output[lng][:html_mnt].close if @output[lng][:html_mnt].class==File + end end def html_print def html_songsheet @@ -194,19 +212,36 @@ module HARVEST_authors html_tail html_file_close end - def html_head_adjust(type='') - css_path=if @env.output_dir_structure.by_language_code? + def html_head_adjust(lng,type='') + css_path,topics='','' + if @env.output_dir_structure.by_language_code? css_path=(type !~/maintenance/) \ ? '../../_sisu/css/harvest.css' \ : 'harvest.css' + topics='topics.html' elsif @env.output_dir_structure.by_filetype? css_path=(type !~/maintenance/) \ ? '../_sisu/css/harvest.css' \ : 'harvest.css' + topics="topics.#{lng}.html" elsif @env.output_dir_structure.by_filename? css_path=(type !~/maintenance/) \ ? '../_sisu/css/harvest.css' \ : 'harvest.css' + topics="topics.#{lng}.html" + end + ln=SiSU_i18n::Languages.new.language.list + harvest_languages='' + @the_idx.keys.each do |lng| + if @env.output_dir_structure.by_language_code? + harvest_pth="../../#{lng}/manifest" + file="#{harvest_pth}/authors.html" + else @env.output_dir_structure.by_filetype? + harvest_pth='.' + file="#{harvest_pth}/authors.#{lng}.html" + end + l=ln[lng][:t] + harvest_languages += %{#{l}   } end sv=SiSU_Env::Info_version.instance.get_version <

SiSU Metadata Harvest - Authors

-

[ HOME ] also see SiSU Metadata Harvest - Topics

+

[ HOME ] also see SiSU Metadata Harvest - Topics

#{@env.widget_static.search_form}


+

#{harvest_languages}

+
WOK end def html_head - @output[:html_mnt] << html_head_adjust('maintenance') if @opt.cmd.inspect =~/M/ - @output[:html] << html_head_adjust + @the_idx.keys.each do |lng| + @output[lng][:html_mnt] << html_head_adjust(lng,'maintenance') if @opt.cmd.inspect =~/M/ + @output[lng][:html] << html_head_adjust(lng) + end end def html_alph a=[] a << '

' @alph.each do |x| - a << ((x =~/[0-9]/) ? '' : %{#{x}, }) + a << ((x =~/[0-9]/) \ + ? '' \ + : %{#{x}, }) + end + a=a.join + @the_idx.keys.each do |lng| + @output[lng][:html_mnt] << a if @opt.cmd.inspect =~/M/ + @output[lng][:html] << a end - @output[:html_mnt] << a.join if @output[:html_mnt].class==File - @output[:html] << a.join end def html_tail - a=[] - a <<< @@ -260,27 +303,25 @@ WOK WOK - @output[:html_mnt] << a if @output[:html_mnt].class==File - @output[:html] << a - end - def do_html(html) - @output[:html_mnt] << html if @output[:html_mnt].class==File - @output[:html] << html + @the_idx.keys.each do |lng| + @output[lng][:html_mnt] << a if @output[lng][:html_mnt].class==File + @output[lng][:html] << a + end end - def do_string(attrib,string) - html=%{

#{string}

} - do_html(html) + def do_html(lng,html) + @output[lng][:html_mnt] << html if @output[lng][:html_mnt].class==File + @output[lng][:html] << html end - def do_string_name(attrib,string) + def do_string_name(lng,attrib,string) f=/^(\S)/.match(string[0])[1] if @letter < f while @letter < f if @alph.length > 0 @letter=@alph.shift - if @output[:html_mnt].class==File - @output[:html_mnt] << %{\n

#{@letter}

} + if @output[lng][:html_mnt].class==File + @output[lng][:html_mnt] << %{\n

#{@letter}

} end - @output[:html] << %{\n

#{@letter}

} + @output[lng][:html] << %{\n

#{@letter}

} else break end end @@ -288,37 +329,35 @@ WOK end def html_body the_idx=@the_idx - the_idx.sort.each do |a| - do_string_name('',a) - name=a[0].sub(/(.+?)(?:,.+|$)/,'\1').gsub(/\s+/,'_') - x = %{

#{a[0]}

} - if @output[:html_mnt].class==File - @output[:html_mnt] << x - end - @output[:html] << x - works=[] - a[1][:md].each do |x| - if @env.output_dir_structure.by_language_code? - manifest_pth="#{@env.path.output}/#{x[:file]}" - manifest_at_local=@env.path.output + '/' + 'en' + '/' + 'manifest/' + x[:file] + '.manifest.html' - manifest_at=x[:file] + '.manifest.html' - elsif @env.output_dir_structure.by_filetype? - #manifest_pth_2="#{@env.path.output}/#{x[:file]}" - manifest_name=x[:file] - manifest_at_local=manifest_name + 'manifest.html' - manifest_at=x[:file] + '.manifest.html' - elsif @env.output_dir_structure.by_filename? - manifest_at_local="#{@env.path.output}/#{x[:file]}/#{x[:page]}" - manifest_at="../#{x[:file]}/#{x[:page]}" + the_idx.each_pair do |lng,lng_array| + lng_array.sort.each do |a| + do_string_name(lng,'',a) + name=a[0].sub(/(.+?)(?:,.+|$)/,'\1').gsub(/\s+/,'_') + x = %{

#{a[0]}

} + if @output[lng][:html_mnt].class==File + @output[lng][:html_mnt] << x + end + @output[lng][:html] << x + works=[] + a[1][:md].each do |x| + if @env.output_dir_structure.by_language_code? + manifest_pth="#{@env.path.output}/#{x[:file]}" + manifest_at=x[:file] + '.html' + elsif @env.output_dir_structure.by_filetype? + manifest_name=x[:file] + manifest_at=x[:file] + '.' + lng + '.html' + elsif @env.output_dir_structure.by_filename? + manifest_at="../#{x[:file]}/#{x[:page]}" + end + work=[ "#{x[:date]} #{x[:title]}", %{

#{x[:date]} #{x[:title]}, #{x[:author][:authors_s]}

} ] + works<<=(@output[lng][:html_mnt].class==File) \ + ? (work.concat([%{

[src]  #{x[:date]} #{x[:title]}, #{x[:author][:authors_s]} -- [#{x[:file]}.sst]

}])) \ + : work + end + works.sort_by {|x| x[0]}.each do |x| + @output[lng][:html] << x[1] + @output[lng][:html_mnt] << x[2] if @output[lng][:html_mnt].class==File end - work=[ "#{x[:date]} #{x[:title]}", %{

#{x[:date]} #{x[:title]}, #{x[:author][:authors_s]}

} ] - works<<=(@output[:html_mnt].class==File) \ - ? (work.concat([%{

[src]  #{x[:date]} #{x[:title]}, #{x[:author][:authors_s]} -- [#{x[:file]}.sst]

}])) \ - : work - end - works.sort_by {|x| x[0]}.each do |x| - @output[:html] << x[1] - @output[:html_mnt] << x[2] if @output[:html_mnt].class==File end end end diff --git a/lib/sisu/v3/harvest_topics.rb b/lib/sisu/v3/harvest_topics.rb index 3ca72326..c3204de9 100644 --- a/lib/sisu/v3/harvest_topics.rb +++ b/lib/sisu/v3/harvest_topics.rb @@ -60,47 +60,46 @@ =end module HARVEST_topics require_relative 'author_format' # author_format.rb + include SiSU_Viz class Songsheet - def initialize(opt) - @opt=opt + @@the_idx_topics={} + def initialize(opt,env) + @opt,@env=opt,env @file_list=opt.files - @env=SiSU_Env::Info_env.new end def songsheet - files,idx_array=[],[] - @file_list.each do |f| - (f =~/.+?\.ss[tm]$/) \ - ? (files << f[/(.+?\.ss[tm])$/,1]) \ - : (print "not .sst or .ssm ? << #{f} >> ") - end - files.each do |filename| - file_array=[] + puts 'topics:' + idx_array={} + @opt.f_pths.each do |y| + lang_hash_file_array={} + name=y[:f] + filename=y[:pth] + '/' + y[:f] File.open(filename,'r') do |file| file.each_line("\n\n") do |line| if line =~/^@(?:title|creator|classify):(?:\s|$)/m - file_array << line + lang_hash_file_array[y[:lng_is]] ||= [] + lang_hash_file_array[y[:lng_is]] << line elsif line =~/^@\S+?:(?:\s|$)/m \ or line =~/^(?:\s*\n|%+ )/ else break end end end - idx_array=HARVEST_topics::Harvest.new(@opt,file_array,filename,idx_array).extract_harvest + lang_hash_file_array.each_pair do |lang,a| + idx_array[lang] ||= [] + idx_array=HARVEST_topics::Harvest.new(@opt,@env,a,filename,name,idx_array,lang).extract_harvest + end end - the_idx=HARVEST_topics::Index.new(idx_array,@@the_idx_topics).construct_book_topic_index - #HARVEST_topics::Output_index.new('',the_idx).screen_print.cycle if @opt.cmd.inspect =~/[VM]/ + the_idx=HARVEST_topics::Index.new(@opt,@env,idx_array,@@the_idx_topics).construct_book_topic_index HARVEST_topics::Output_index.new(@opt,the_idx).html_print.html_songsheet - harvest_pth="#{@env.path.webserv}/#{@env.stub_md_harvest}" - puts "file://#{harvest_pth}/harvest_topics.html" - puts "file://#{@env.path.pwd}/harvest_topics.html" if @opt.cmd.inspect =~/M/ end end class Harvest - def initialize(opt,data,filename,idx_array) - @opt,@data,@filename,@idx_array=opt,data,filename,idx_array + def initialize(opt,env,data,filename,name,idx_array,lang) + @opt,@env,@data,@filename,@name,@idx_array,@lang=opt,env,data,filename,name,idx_array,lang end def extract_harvest - data,filename,idx_array=@data,@filename,@idx_array + data,filename,name,idx_array,lang=@data,@filename,@name,@idx_array,@lang @idx_lst,@title,@subtitle,@fulltitle,@author,@author_format=nil,nil,nil,nil,nil,nil rgx={} rgx[:author]=/^@creator:(?:[ ]+|.+?:author:[ ]+)(.+?)(?:\||\n)/m @@ -128,118 +127,130 @@ module HARVEST_topics and @idx_list creator=FORMAT::Author.new(@author_format.strip).author_details @authors,@authorship=creator[:authors],creator[:authorship] - file=if filename=~/~[a-z]{2,3}\.ss[mt]$/ - lang='.' + /~([a-z]{2,3})\.ss[mt]$/.match(filename)[1] - filename.sub(/~[a-z]{2,3}\.ss[mt]$/,'') + file=if name=~/~[a-z]{2,3}\.ss[mt]$/ + name.sub(/~[a-z]{2,3}\.ss[mt]$/,'') + else + name.sub(/\.ss[mt]$/,'') + end + page=if @env.output_dir_structure.by_language_code? + #fix + end + page=if @env.output_dir_structure.by_language_code? + "#{lang}/sisu_manifest.html" else - lang='' - filename.sub(/\.ss[mt]$/,'') + "sisu_manifest.#{lang}.html" end - page="sisu_manifest#{lang}.html" - idx_array <<=if @idx_list =~/;/ + idx_array[lang] <<=if @idx_list =~/;/ g=@idx_list.scan(/[^;]+/) idxl=[] g.each do |i| i.strip! - idxl << { filename: filename, file: file, rough_idx: i, title: @fulltitle, author: creator, page: page } + idxl << { filename: filename, file: file, rough_idx: i, title: @fulltitle, author: creator, page: page, lang: lang } end idxl - else { filename: filename, file: file, rough_idx: @idx_list, title: @fulltitle, author: creator, page: page } + else { filename: filename, file: file, rough_idx: @idx_list, title: @fulltitle, author: creator, page: page, lang: lang } end else p "missing required field in #{@filename} - [title]: <<#{@title}>>; [author]: <<#{@author_format}>>; [idx]: <<#{@idx_list}>>" if @opt.cmd.inspect =~/[VM]/ end - idx_array.flatten! + idx_array[lang].flatten! idx_array end end class Index - def initialize(idx_array,the_idx) - @idx_array,@the_idx=idx_array,the_idx + def initialize(opt,env,idx_array,the_idx) + @opt,@env,@idx_array,@the_idx=opt,env,idx_array,the_idx @@the_idx_topics=@the_idx end def capital(txt) txt[0].chr.capitalize + txt[1,txt.length] end - def contents(hash,idx) + def contents(lang,hash,idx) names='' idx[:author][:last_first_format_a].each do |n| s=n.sub(/(.+?)(?:,.+|$)/,'\1').gsub(/\s+/,'_') - names += %{#{n}, } + names=if @env.output_dir_structure.by_language_code? + names += %{#{n}, } + else + names += %{#{n}, } + end end hash << { filename: idx[:filename], file: idx[:file], author: names, title: idx[:title], page: idx[:page] } end def construct_book_topic_index idx_array=@idx_array - idx_array.each do |idx| - @lv0,@lv1,@lv2,@lv3,@lv4={},{},{},{},{} - if idx[:rough_idx] - idx_lst=idx[:rough_idx].scan(/[^:]+/) - else - puts "no topic register in: << #{idx[:filename]} >>" - next - end - idx_lst_alt=[] - idx_lst.each {|lev| idx_lst_alt << lev.scan(/[^|]+/)} - depth = idx_lst_alt.length - 1 - range = 0..depth - range.each do |t| - if idx_lst_alt[t] - case t - when 0 - lev0=idx_lst_alt[t] - lev0.each do |lv0| - lv0=capital(lv0) - if @@the_idx_topics[lv0].class==NilClass - @@the_idx_topics[lv0]={ md: [] } + idx_array.each_pair do |lang,idx_array| + @@the_idx_topics[lang] ||= {} + idx_array.each do |idx| + @lv0,@lv1,@lv2,@lv3,@lv4={},{},{},{},{} + if idx[:rough_idx] + idx_lst=idx[:rough_idx].scan(/[^:]+/) + else + puts "no topic register in: << #{idx[:filename]} >>" + next + end + idx_lst_alt=[] + idx_lst.each {|lev| idx_lst_alt << lev.scan(/[^|]+/)} + depth = idx_lst_alt.length - 1 + range = 0..depth + range.each do |t| + if idx_lst_alt[t] + case t + when 0 + lev0=idx_lst_alt[t] + lev0.each do |lv0| + lv0=capital(lv0) + if @@the_idx_topics[lang][lv0].class==NilClass + @@the_idx_topics[lang][lv0]={ md: [] } + end + @lv0=lv0 if lev0.length==1 + j=@@the_idx_topics[lang][lv0][:md] + contents(lang,j,idx) if idx_lst_alt.length - 1 == t end - @lv0=lv0 if lev0.length==1 - j=@@the_idx_topics[lv0][:md] - contents(j,idx) if idx_lst_alt.length - 1 == t - end - when 1 - lev1=idx_lst_alt[t] - lev1.each do |lv1| - lv1=capital(lv1) - if @@the_idx_topics[@lv0][lv1].class==NilClass - @@the_idx_topics[@lv0][lv1]={ md: [] } + when 1 + lev1=idx_lst_alt[t] + lev1.each do |lv1| + lv1=capital(lv1) + if @@the_idx_topics[lang][@lv0][lv1].class==NilClass + @@the_idx_topics[lang][@lv0][lv1]={ md: [] } + end + @lv1=lv1 if lev1.length==1 + j=@@the_idx_topics[lang][@lv0][lv1][:md] + contents(lang,j,idx) if idx_lst_alt.length - 1 == t end - @lv1=lv1 if lev1.length==1 - j=@@the_idx_topics[@lv0][lv1][:md] - contents(j,idx) if idx_lst_alt.length - 1 == t - end - when 2 - lev2=idx_lst_alt[t] - lev2.each do |lv2| - lv2=capital(lv2) - if @@the_idx_topics[@lv0][@lv1][lv2].class==NilClass - @@the_idx_topics[@lv0][@lv1][lv2]={ md: [] } + when 2 + lev2=idx_lst_alt[t] + lev2.each do |lv2| + lv2=capital(lv2) + if @@the_idx_topics[lang][@lv0][@lv1][lv2].class==NilClass + @@the_idx_topics[lang][@lv0][@lv1][lv2]={ md: [] } + end + @lv2=lv2 if lev2.length==1 + j=@@the_idx_topics[lang][@lv0][@lv1][lv2][:md] + contents(lang,j,idx) if idx_lst_alt.length - 1 == t end - @lv2=lv2 if lev2.length==1 - j=@@the_idx_topics[@lv0][@lv1][lv2][:md] - contents(j,idx) if idx_lst_alt.length - 1 == t - end - when 3 - lev3=idx_lst_alt[t] - lev3.each do |lv3| - lv3=capital(lv3) - if @@the_idx_topics[@lv0][@lv1][@lv2][lv3].class==NilClass - @@the_idx_topics[@lv0][@lv1][@lv2][lv3]={ md: [] } + when 3 + lev3=idx_lst_alt[t] + lev3.each do |lv3| + lv3=capital(lv3) + if @@the_idx_topics[lang][@lv0][@lv1][@lv2][lv3].class==NilClass + @@the_idx_topics[lang][@lv0][@lv1][@lv2][lv3]={ md: [] } + end + @lv3=lv3 if lev3.length==1 + j=@@the_idx_topics[lang][@lv0][@lv1][@lv2][lv3][:md] + contents(lang,j,idx) if idx_lst_alt.length - 1 == t end - @lv3=lv3 if lev3.length==1 - j=@@the_idx_topics[@lv0][@lv1][@lv2][lv3][:md] - contents(j,idx) if idx_lst_alt.length - 1 == t - end - when 4 - lev4=idx_lst_alt[t] - lev4.each do |lv4| - lv4=capital(lv4) - if @@the_idx_topics[@lv0][@lv1][@lv2][@lv3][lv4].class==NilClass - @@the_idx_topics[@lv0][@lv1][@lv2][@lv3][lv4]={ md: [] } + when 4 + lev4=idx_lst_alt[t] + lev4.each do |lv4| + lv4=capital(lv4) + if @@the_idx_topics[lang][@lv0][@lv1][@lv2][@lv3][lv4].class==NilClass + @@the_idx_topics[lang][@lv0][@lv1][@lv2][@lv3][lv4]={ md: [] } + end + @lv4=lv4 if lev4.length==1 + j=@@the_idx_topics[lang][@lv0][@lv1][@lv2][@lv3][lv4][:md] + contents(lang,j,idx) if idx_lst_alt.length - 1 == t end - @lv4=lv4 if lev4.length==1 - j=@@the_idx_topics[@lv0][@lv1][@lv2][@lv3][lv4][:md] - contents(j,idx) if idx_lst_alt.length - 1 == t end end end @@ -249,25 +260,42 @@ module HARVEST_topics end end class Output_index + require_relative 'i18n' # i18n.rb + require 'fileutils' + include FileUtils def initialize(opt,the_idx) @opt,@the_idx=opt,the_idx @env=SiSU_Env::Info_env.new - @rc=Get_init.instance.sisu_yaml.rc + @rc=SiSU_Env::Get_init.instance.sisu_yaml.rc @alph=%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] @letter=@alph.shift @vz=SiSU_Env::Get_init.instance.skin end def html_file_open - @output={} - harvest_pth="#{@env.path.webserv}/#{@env.stub_md_harvest}" - @output[:html]=File.new("#{harvest_pth}/harvest_topics.html",'w') - if @opt.cmd.inspect =~/-M/ - @output[:html_mnt]=File.new("#{@env.path.pwd}/harvest_topics.html",'w') + @the_idx.keys.each do |lng| + @output ||={} + @output[lng] ||={} + harvest_pth,file='','' + if @env.output_dir_structure.by_language_code? + harvest_pth="#{@env.path.webserv}/#{@opt.base_stub}/#{lng}/manifest" + file="#{harvest_pth}/topics.html" + else @env.output_dir_structure.by_filetype? + harvest_pth="#{@env.path.webserv}/#{@opt.base_stub}/manifest" + file="#{harvest_pth}/topics.#{lng}.html" + end + mkdir_p(harvest_pth) unless FileTest.directory?(harvest_pth) + puts "file://#{file}" + @output[lng][:html]=File.new(file,'w') + if @opt.cmd.inspect =~/-M/ + @output[lng][:html_mnt]=File.new("#{@env.path.pwd}/topics.html",'w') + end end end def html_file_close - @output[:html].close - @output[:html_mnt].close if @output[:html_mnt].class==File + @the_idx.keys.each do |lng| + @output[lng][:html].close + @output[lng][:html_mnt].close if @output[lng][:html_mnt].class==File + end end def html_print def html_songsheet @@ -278,19 +306,36 @@ module HARVEST_topics html_tail html_file_close end - def html_head_adjust(type='') - css_path=if @env.output_dir_structure.by_language_code? + def html_head_adjust(lng,type='') + css_path,authors='','' + if @env.output_dir_structure.by_language_code? css_path=(type !~/maintenance/) \ ? '../../_sisu/css/harvest.css' \ : 'harvest.css' + authors='authors.html' elsif @env.output_dir_structure.by_filetype? css_path=(type !~/maintenance/) \ ? '../_sisu/css/harvest.css' \ : 'harvest.css' + authors="authors.#{lng}.html" elsif @env.output_dir_structure.by_filename? css_path=(type !~/maintenance/) \ ? '../_sisu/css/harvest.css' \ : 'harvest.css' + authors="authors.#{lng}.html" + end + ln=SiSU_i18n::Languages.new.language.list + harvest_languages='' + @the_idx.keys.each do |lng| + if @env.output_dir_structure.by_language_code? + harvest_pth="../../#{lng}/manifest" + file="#{harvest_pth}/topics.html" + else @env.output_dir_structure.by_filetype? + harvest_pth='.' + file="#{harvest_pth}/topics.#{lng}.html" + end + l=ln[lng][:t] + harvest_languages += %{#{l}   } end sv=SiSU_Env::Info_version.instance.get_version <

SiSU Metadata Harvest - Topics

-

[ HOME ] also see SiSU Metadata Harvest - Authors

+

[ HOME ] also see SiSU Metadata Harvest - Authors

#{@env.widget_static.search_form}


+

#{harvest_languages}

+
WOK end def html_head - @output[:html_mnt] << html_head_adjust('maintenance') if @opt.cmd.inspect =~/M/ - @output[:html] << html_head_adjust + @the_idx.keys.each do |lng| + @output[lng][:html_mnt] << html_head_adjust(lng,'maintenance') if @opt.cmd.inspect =~/M/ + @output[lng][:html] << html_head_adjust(lng) + end end def html_alph a=[] a << '

' @alph.each do |x| - a << (x =~/[0-9]/) \ + a << ((x =~/[0-9]/) \ ? '' \ - : %{#{x}, } + : %{#{x}, }) + end + a=a.join + @the_idx.keys.each do |lng| + @output[lng][:html_mnt] << a if @opt.cmd.inspect =~/M/ + @output[lng][:html] << a end - @output[:html_mnt] << a if @opt.cmd.inspect =~/M/ - @output[:html] << a.join end def html_tail - a=[] - a <<< @@ -346,107 +397,116 @@ WOK WOK - @output[:html_mnt] << a if @output[:html_mnt].class==File - @output[:html] << a + @the_idx.keys.each do |lng| + @output[lng][:html_mnt] << a if @output[lng][:html_mnt].class==File + @output[lng][:html] << a + end end - def do_html(html) - @output[:html] << html + def do_html(lng,html) + @output[lng][:html] << html end - def do_html_maintenance(html) - @output[:html_mnt] << html if @output[:html_mnt].class==File + def do_html_maintenance(lng,html) + @output[lng][:html_mnt] << html if @output[lng][:html_mnt].class==File end - def do_string(attrib,string) + def do_string(lng,attrib,string) html=%{

#{string}

} - do_html(html) - do_html_maintenance(html) if @output[:html_mnt].class==File + do_html(lng,html) + do_html_maintenance(lng,html) if @output[lng][:html_mnt].class==File end - def do_string_default(attrib,string) + def do_string_default(lng,attrib,string) html=%{

#{string}

} - do_html(html) + do_html(lng,html) end - def do_string_maintenance(attrib,string) + def do_string_maintenance(lng,attrib,string) html=%{

#{string}

} - do_html_maintenance(html) if @output[:html_mnt].class==File + do_html_maintenance(lng,html) if @output[lng][:html_mnt].class==File end - def do_string_name(attrib,string) + def do_string_name(lng,attrib,string) f=/^(\S)/.match(string)[1] if @letter < f while @letter < f if @alph.length > 0 @letter=@alph.shift - if @output[:html_mnt].class==File - @output[:html_mnt] << %{\n

#{@letter}

} + if @output[lng][:html_mnt].class==File + @output[lng][:html_mnt] << %{\n

#{@letter}

} end - @output[:html] << %{\n

#{@letter}

} + @output[lng][:html] << %{\n

#{@letter}

} else break end end end name=string.strip.gsub(/\s+/,'_') html=%{

#{string}

} - do_html(html) - do_html_maintenance(html) if @output[:html_mnt].class==File + do_html(lng,html) + do_html_maintenance(lng,html) if @output[lng][:html_mnt].class==File end - def do_array(lv,array) + def do_array(lng,lv,array) lv+=1 array.each do |b| - do_case(lv,b) + do_case(lng,lv,b) end end - def do_hash_md(attrib,hash) + def do_hash_md(lng,attrib,hash) if @env.output_dir_structure.by_language_code? - manifest_at=hash[:file] + '.manifest.html' + manifest_at=hash[:file] + '.html' elsif @env.output_dir_structure.by_filetype? - manifest_at=hash[:file] + '.manifest.html' + manifest_at=hash[:file] + '.' + lng + '.html' elsif @env.output_dir_structure.by_filename? manifest_at="../#{hash[:file]}/#{hash[:page]}" end html=%{#{hash[:title]} - #{hash[:author]}} - do_string_default(attrib,html) + do_string_default(lng,attrib,html) end - def do_hash_md_maintenance(attrib,hash) - if @output[:html_mnt].class==File #should not be run for presentation output + def do_hash_md_maintenance(lng,attrib,hash) + if @output[lng][:html_mnt].class==File #should not be run for presentation output html=%{[src]  #{hash[:title]} - #{hash[:author]}} - do_string_maintenance(attrib,html) + do_string_maintenance(lng,attrib,html) end end - def do_hash(lv,hash) + def do_hash(lng,lv,hash) lv+=1 key=[] hash.each_key do |m| if m == :md - do_case(lv,hash[m]) - elsif m != :title and m != :author and m != :filename and m != :file and m != :rough_idx and m != :page + do_case(lng,lv,hash[m]) + elsif m != :title \ + and m != :author \ + and m != :filename \ + and m != :file \ + and m != :rough_idx \ + and m != :page key << m elsif m == :title - do_hash_md('work',hash) - do_hash_md_maintenance('work',hash) + do_hash_md(lng,'work',hash) + do_hash_md_maintenance(lng,'work',hash) end end if key.length > 0 key.sort.each do |m| attrib="lev#{lv}" - lv==0 ? do_string_name(attrib,m) : do_string(attrib,m) - do_case(lv,hash[m]) + lv==0 ? do_string_name(lng,attrib,m) : do_string(lng,attrib,m) + do_case(lng,lv,hash[m]) end end end - def do_case(lv,a) + def do_case(lng,lv,a) y = a.class case when y==String attrib="lev#{lv}" - lv==0 ? do_string_name(attrib,a) : do_string(attrib,a) + lv==0 ? do_string_name(lng,attrib,a) : do_string(lng,attrib,a) when y==Array - do_array(lv,a) + do_array(lng,lv,a) when y==Hash - do_hash(lv,a) + do_hash(lng,lv,a) end end def html_body the_idx=@the_idx - the_idx.sort.each do |a| - do_case(-1,a) + the_idx.each_pair do |lng,lng_array| + lng_array.sort.each do |a| + do_case(lng,-1,a) + end end end self @@ -456,102 +516,116 @@ WOK s=' '*4 puts s*lv + string end - def do_array(lv,array) + def do_array(lng,lv,array) lv+=1 array.each do |b| - do_case(lv,b) + do_case(lng,lv,b) end end - def do_hash_md(lv,hash) + def do_hash_md(lng,lv,hash) string=hash[:title] + ' - ' + hash[:author] - do_string(lv,string) + do_string(lng,lv,string) end - def do_hash(lv,hash) + def do_hash(lng,lv,hash) lv+=1 key=[] hash.each_key do |m| if m == :md - do_case(lv,hash[m]) - elsif m != :title and m != :author and m != :filename and m != :file and m != :rough_idx and m != :page + do_case(lng,lv,hash[m]) + elsif m != :title \ + and m != :author \ + and m != :filename \ + and m != :file \ + and m != :rough_idx \ + and m != :page key << m elsif m == :title - do_hash_md(lv,hash) + do_hash_md(lng,lv,hash) end end if key.length > 0 key.sort.each do |m| - do_string(lv,m) - do_case(lv,hash[m]) + do_string(lng,lv,m) + do_case(lng,lv,hash[m]) end end end - def do_case(lv,a) + def do_case(lng,lv,a) s=' '*4 y = a.class case when y==String - do_string(lv,a) + do_string(lng,lv,a) when y==Array - do_array(lv,a) + do_array(lng,lv,a) when y==Hash - do_hash(lv,a) + do_hash(lng,lv,a) end end def cycle the_idx=@the_idx - the_idx.each do |a| - do_case(-1,a) + the_idx.keys.each do |lng| + the_idx[lng].each do |a| + do_case(lng,-1,a) + end end end self end def screen_print_unsorted - def do_string(lv,string) + def do_string(lng,lv,string) s=' '*4 puts s*lv + string end - def do_array(lv,array) + def do_array(lng,lv,array) lv+=1 array.each do |b| - do_case(lv,b) + do_case(lng,lv,b) end end - def do_hash_md(lv,hash) + def do_hash_md(lng,lv,hash) string=hash[:title] + ' - ' + hash[:author] - do_string(lv,string) + do_string(lng,lv,string) end - def do_hash(lv,hash) + def do_hash(lng,lv,hash) lv+=1 hash.each_key do |m| if m == :md - do_case(lv,hash[m]) + do_case(lng,lv,hash[m]) else - if m != :title and m != :author and m != :filename and m != :file and m != :rough_idx and m != :page - do_string(lv,m) - do_case(lv,hash[m]) + if m != :title \ + and m != :author \ + and m != :filename \ + and m != :file \ + and m != :rough_idx \ + and m != :page + do_string(lng,lv,m) + do_case(lng,lv,hash[m]) elsif m == :title - do_hash_md(lv,hash) + do_hash_md(lng,lv,hash) else end end end end - def do_case(lv,a) + def do_case(lng,lv,a) s=' '*4 y = a.class case when y==String - do_string(lv,a) + do_string(lng,lv,a) when y==Array - do_array(lv,a) + do_array(lng,lv,a) when y==Hash - do_hash(lv,a) + do_hash(lng,lv,a) end end def cycle the_idx=@the_idx - the_idx.each do |a| - do_case(-1,a) + the_idx.keys.each do |lng| + the_idx[lng].each do |a| + do_case(lng,-1,a) + end end end self diff --git a/lib/sisu/v3/hub.rb b/lib/sisu/v3/hub.rb index 5eac0b03..7b847d4f 100644 --- a/lib/sisu/v3/hub.rb +++ b/lib/sisu/v3/hub.rb @@ -290,13 +290,13 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ end if @opt.act[:harvest] require_relative 'harvest' # harvest.rb + SiSU_Harvest::Source.new(@opt).read # -h -H html.rb elsif @opt.mod.inspect =~/--convert|--to|--from/ require_relative 'sst_convert_markup' # sst_convert_markup.rb elsif @opt.cmd =~/([AabCcDdeFfGgHhIiJjkLMmNnOoPpQqRrSsTtUuVvwWXxYyZ_0-9])/ \ and @opt.cmd =~/^-/ \ and @opt.mod.inspect !~/--(?:sitemaps|query|identify)/ \ or @opt.mod.inspect =~/--(?:(?:sq)?lite|pg(?:sql)?)/ - @@tell=SiSU_Screen::Ansi.new(@opt.cmd) @cX=SiSU_Screen::Ansi.new(@opt.cmd).cX flag=SiSU_Env::Info_processing_flag.new if @opt.cmd =~/[vVM]/ #% version information -- cgit v1.2.3