From 64e5c9120ffb7a65b96eded0850f481e116f1d3f Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 8 Aug 2014 00:16:16 -0400 Subject: v6: use opt.act, code internals (simplify, cleaner; remove opt.cmd & opt.mod) * v5 dp, indentation changed to retain easy comparison with v6 --- lib/sisu/v6/harvest_topics.rb | 120 +++++++++++++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 30 deletions(-) (limited to 'lib/sisu/v6/harvest_topics.rb') diff --git a/lib/sisu/v6/harvest_topics.rb b/lib/sisu/v6/harvest_topics.rb index c827bbbf..2aa3f6b2 100644 --- a/lib/sisu/v6/harvest_topics.rb +++ b/lib/sisu/v6/harvest_topics.rb @@ -90,11 +90,27 @@ module SiSU_HarvestTopics end lang_hash_file_array.each_pair do |lang,a| idx_array[lang] ||=[] - idx_array=SiSU_HarvestTopics::Harvest.new(@opt,@env,a,filename,name,idx_array,lang).extract_harvest + idx_array=SiSU_HarvestTopics::Harvest.new( + @opt, + @env, + a, + filename, + name, + idx_array, + lang + ).extract_harvest end end - the_hash=SiSU_HarvestTopics::Index.new(@opt,@env,idx_array,@@the_idx_topics).song - SiSU_HarvestTopics::OutputIndex.new(@opt,the_hash).html_print.html_songsheet + the_hash=SiSU_HarvestTopics::Index.new( + @opt, + @env, + idx_array, + @@the_idx_topics + ).song + SiSU_HarvestTopics::OutputIndex.new( + @opt, + the_hash + ).html_print.html_songsheet end end class Mix @@ -104,11 +120,13 @@ module SiSU_HarvestTopics end class Harvest 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 + @opt, @env,@data,@filename,@name,@idx_array,@lang= + opt,env, data, filename, name, idx_array, lang end def extract_harvest - 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 + data, filename, name, idx_array, lang= + @data,@filename,@name,@idx_array,@lang + @idx_lst=@title=@subtitle=@fulltitle=@author=@author_format=nil rgx={} rgx[:author]=/^@creator:(?:[ ]+|.+?:author:[ ]+)(.+?)(?:\||\n)/m rgx[:title]=/^@title:[ ]+(.+)/ @@ -150,10 +168,26 @@ module SiSU_HarvestTopics idxl=[] g.each do |i| i=i.strip - idxl << { filename: filename, file: file, rough_idx: i, title: @fulltitle, author: creator, page: page, lang: lang } + 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, lang: lang } + else { + filename: filename, + file: file, + rough_idx: @idx_list, + title: @fulltitle, + author: creator, + page: page, + lang: lang, + } end else if (@opt.act[:verbose_plus][:set]==:on \ @@ -167,7 +201,8 @@ module SiSU_HarvestTopics end class Index < Mix def initialize(opt,env,idx_array,the_idx) - @opt,@env,@idx_array,@the_idx=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 song @@ -195,7 +230,13 @@ module SiSU_HarvestTopics names += %{#{n}, } end end - { filename: idx[:filename], file: idx[:file], author: names, title: idx[:title], page: idx[:page] } + { + filename: idx[:filename], + file: idx[:file], + author: names, + title: idx[:title], + page: idx[:page] + } end def capital_(txt) txt[0].chr.capitalize + txt[1,txt.length] @@ -471,18 +512,26 @@ module SiSU_HarvestTopics @output[lng] ||={} harvest_pth,file='','' if @env.output_dir_structure.by? == :language - harvest_pth="#{@env.path.webserv}/#{@opt.base_stub}/#{lng}/manifest" - file="#{harvest_pth}/topics.html" + harvest_pth=@env.path.webserv + '/' \ + + @opt.base_stub + '/' \ + + lng + '/' \ + + 'manifest' + file=harvest_pth + '/' + 'topics.html' elsif @env.output_dir_structure.by? == :filetype - harvest_pth="#{@env.path.webserv}/#{@opt.base_stub}/manifest" - file="#{harvest_pth}/topics.#{lng}.html" + harvest_pth=@env.path.webserv + '/' \ + + @opt.base_stub + '/' \ + + 'manifest' + file=harvest_pth + '/' + 'topics.' + lng + '.html' elsif @env.output_dir_structure.by? == :filename - harvest_pth="#{@env.path.webserv}/#{@opt.base_stub}" - file="#{harvest_pth}/topics.#{lng}.html" + harvest_pth=@env.path.webserv + '/' \ + + @opt.base_stub + file=harvest_pth + '/' + 'topics.' + lng + '.html' end - FileUtils::mkdir_p(harvest_pth) unless FileTest.directory?(harvest_pth) + FileUtils::mkdir_p(harvest_pth) \ + unless FileTest.directory?(harvest_pth) fileinfo=(@opt.act[:verbose][:set]==:on \ || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:urls_selected][:set]==:on \ || @opt.act[:maintenance][:set]==:on) \ ? ("file://#{file}") : '' @@ -615,16 +664,17 @@ module SiSU_HarvestTopics @the_idx.keys.each do |lg| if @env.output_dir_structure.by? == :language harvest_pth="../../#{lg}/manifest" - file="#{harvest_pth}/topics.html" + file=harvest_pth + '/' + 'topics.html' elsif @env.output_dir_structure.by? == :filetype harvest_pth='.' - file="#{harvest_pth}/topics.#{lg}.html" + file=harvest_pth + '/' + 'topics.' + lg + '.html' elsif @env.output_dir_structure.by? == :filename harvest_pth='.' - file="#{harvest_pth}/topics.#{lg}.html" + file=harvest_pth + '/topics.' + lg + '.html' end l=ln[lg][:t] - harvest_languages += %{#{l}   } + harvest_languages += + %{#{l}   } end sv=SiSU_Env::InfoVersion.instance.get_version if @env.output_dir_structure.by? == :language @@ -668,7 +718,9 @@ WOK end def html_head @the_idx.keys.each do |lng| - @output[lng][:html_mnt] << html_head_adjust(lng,'maintenance') if @opt.act[:maintenance][:set]==:on + @output[lng][:html_mnt] \ + << html_head_adjust(lng,'maintenance') \ + if @opt.act[:maintenance][:set]==:on @output[lng][:html] << html_head_adjust(lng) end end @@ -682,7 +734,8 @@ WOK end a=a.join @the_idx.keys.each do |lng| - @output[lng][:html_mnt] << a if @opt.act[:maintenance][:set]==:on + @output[lng][:html_mnt] << a \ + if @opt.act[:maintenance][:set]==:on @output[lng][:html] << a end end @@ -700,7 +753,8 @@ WOK WOK @the_idx.keys.each do |lng| - @output[lng][:html_mnt] << a if @output[lng][:html_mnt].is_a?(File) + @output[lng][:html_mnt] << a \ + if @output[lng][:html_mnt].is_a?(File) @output[lng][:html] << a end end @@ -708,12 +762,14 @@ WOK @output[lng][:html] << html end def do_html_maintenance(lng,html) - @output[lng][:html_mnt] << html if @output[lng][:html_mnt].is_a?(File) + @output[lng][:html_mnt] << html \ + if @output[lng][:html_mnt].is_a?(File) end def do_string(lng,attrib,string) html=%{

#{string}

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

#{string}

} @@ -721,7 +777,8 @@ WOK end def do_string_maintenance(lng,attrib,string) html=%{

#{string}

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

#{@letter}

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

#{@letter}

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

#{@letter}

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

#{@letter}

} else break end end @@ -745,7 +804,8 @@ WOK name=string.strip.gsub(/\s+/,'_') html=%{

#{string}

} do_html(lng,html) - do_html_maintenance(lng,html) if @output[lng][:html_mnt].is_a?(File) + do_html_maintenance(lng,html) \ + if @output[lng][:html_mnt].is_a?(File) end def do_array(lng,lv,array) lv+=1 -- cgit v1.2.3