aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v1/harvest_topics.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v1/harvest_topics.rb')
-rw-r--r--lib/sisu/v1/harvest_topics.rb72
1 files changed, 31 insertions, 41 deletions
diff --git a/lib/sisu/v1/harvest_topics.rb b/lib/sisu/v1/harvest_topics.rb
index 1ab62a95..f1274b40 100644
--- a/lib/sisu/v1/harvest_topics.rb
+++ b/lib/sisu/v1/harvest_topics.rb
@@ -79,10 +79,10 @@ module HARVEST_topics
file_array=[]
File.open(filename,'r') do |file|
file.each_line("\n\n") do |line|
- if line =~/^@\S+?: /
- #line=line.gsub(/\n/,' ')
+ if line =~/^@(?:title|subtitle|author|creator|classify|topic_register|date):(?:\s|$)/m
file_array << line
- elsif line =~/^(?:\s*\n|%+ )/
+ elsif line =~/^@\S+?:(?:\s|$)/m \
+ or line =~/^(?:\s*\n|%+ )/
else break
end
end
@@ -105,10 +105,10 @@ module HARVEST_topics
data,filename,idx_array=@data,@filename,@idx_array
@idx_lst,@title,@subtitle,@fulltitle,@author,@author_format=nil,nil,nil,nil,nil,nil
rgx={}
- rgx[:author]=/^@(?:author|creator):\s+(.+)/
+ rgx[:author]=/^@(?:author|creator):(?:[ ]+|.+?:author:[ ]+)(.+?)(?:\||\n)/m
rgx[:title]=/^@title:\s+(.+)/
- rgx[:subtitle]=/^@subtitle:\s+(.+)/
- rgx[:idx]=/^@topic_register:\s+(.+)/
+ rgx[:subtitle]=/^(?:@subtitle:\s+|@title:.+?:subtitle:[ ]+)(.+)/m
+ rgx[:idx]=/^(?:@topic_register:[ ]+|@classify:.+?:topic_register:[ ]+)(.+?)\n/m
data.each do |para|
if para=~ rgx[:idx]
@idx_list=rgx[:idx].match(para)[1]
@@ -124,10 +124,7 @@ module HARVEST_topics
end
break if @title and @subtitle and @author and @idx_lst
end
- @fulltitle=if @subtitle
- @title + ' - ' + @subtitle
- else @title
- end
+ @fulltitle=@subtitle ? (@title + ' - ' + @subtitle) : @title
if @title and @author_format and @idx_list
creator=FORMAT::Author.new(@author_format.strip).author_details
@authors,@authorship=creator[:authors],creator[:authorship]
@@ -196,7 +193,7 @@ module HARVEST_topics
if @@the_idx_topics[lv0].class==NilClass
@@the_idx_topics[lv0]={:md => []}
end
- @lv0=lv0 if lev0.length == 1
+ @lv0=lv0 if lev0.length==1
j=@@the_idx_topics[lv0][:md]
contents(j,idx) if idx_lst_alt.length - 1 == t
end
@@ -207,7 +204,7 @@ module HARVEST_topics
if @@the_idx_topics[@lv0][lv1].class==NilClass
@@the_idx_topics[@lv0][lv1]={:md => []}
end
- @lv1=lv1 if lev1.length == 1
+ @lv1=lv1 if lev1.length==1
j=@@the_idx_topics[@lv0][lv1][:md]
contents(j,idx) if idx_lst_alt.length - 1 == t
end
@@ -218,7 +215,7 @@ module HARVEST_topics
if @@the_idx_topics[@lv0][@lv1][lv2].class==NilClass
@@the_idx_topics[@lv0][@lv1][lv2]={:md => []}
end
- @lv2=lv2 if lev2.length == 1
+ @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
@@ -229,7 +226,7 @@ module HARVEST_topics
if @@the_idx_topics[@lv0][@lv1][@lv2][lv3].class==NilClass
@@the_idx_topics[@lv0][@lv1][@lv2][lv3]={:md => []}
end
- @lv3=lv3 if lev3.length == 1
+ @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
@@ -240,7 +237,7 @@ module HARVEST_topics
if @@the_idx_topics[@lv0][@lv1][@lv2][@lv3][lv4].class==NilClass
@@the_idx_topics[@lv0][@lv1][@lv2][@lv3][lv4]={:md => []}
end
- @lv4=lv4 if lev4.length == 1
+ @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
@@ -269,7 +266,7 @@ module HARVEST_topics
end
def html_file_close
@output[:html].close
- @output[:html_mnt].close if @output[:html_mnt].class == File
+ @output[:html_mnt].close if @output[:html_mnt].class==File
end
def html_print
def html_songsheet
@@ -339,19 +336,19 @@ WOK
</body>
</html>
WOK
- @output[:html_mnt] << a if @output[:html_mnt].class == File
+ @output[:html_mnt] << a if @output[:html_mnt].class==File
@output[:html] << a
end
def do_html(html)
@output[:html] << html
end
def do_html_maintenance(html)
- @output[:html_mnt] << html if @output[:html_mnt].class == File
+ @output[:html_mnt] << html if @output[:html_mnt].class==File
end
def do_string(attrib,string)
html=%{<p class="#{attrib}">#{string}</p>}
do_html(html)
- do_html_maintenance(html) if @output[:html_mnt].class == File
+ do_html_maintenance(html) if @output[:html_mnt].class==File
end
def do_string_default(attrib,string)
html=%{<p class="#{attrib}">#{string}</p>}
@@ -359,7 +356,7 @@ WOK
end
def do_string_maintenance(attrib,string)
html=%{<p class="#{attrib}">#{string}</p>}
- do_html_maintenance(html) if @output[:html_mnt].class == File
+ do_html_maintenance(html) if @output[:html_mnt].class==File
end
def do_string_name(attrib,string)
f=/^(\S)/.match(string)[1]
@@ -367,7 +364,7 @@ WOK
while @letter < f
if @alph.length > 0
@letter=@alph.shift
- if @output[:html_mnt].class == File
+ if @output[:html_mnt].class==File
@output[:html_mnt] << %{\n<p class="letter"><a name="#{@letter}">#{@letter}</a></p><p class="book_index_lev1"><a name="#{@letter.downcase}"></a></p>}
end
@output[:html] << %{\n<p class="letter"><a name="#{@letter}">#{@letter}</a></p><p class="book_index_lev1"><a name="#{@letter.downcase}"></a></p>}
@@ -378,7 +375,7 @@ WOK
name=string.strip.gsub(/\s+/,'_')
html=%{<p class="#{attrib}"><a name="#{name}">#{string}</a></p>}
do_html(html)
- do_html_maintenance(html) if @output[:html_mnt].class == File
+ do_html_maintenance(html) if @output[:html_mnt].class==File
end
def do_array(lv,array)
lv+=1
@@ -391,7 +388,7 @@ WOK
do_string_default(attrib,html)
end
def do_hash_md_maintenance(attrib,hash)
- if @output[:html_mnt].class == File #should not be run for presentation output
+ if @output[:html_mnt].class==File #should not be run for presentation output
html=%{[<a href="#{hash[:file]}.sst">src</a>]&nbsp;&nbsp;<a href="file://#{@env.path.output}/#{hash[:file]}/#{hash[:page]}">#{hash[:title]}</a> - #{hash[:author]}}
do_string_maintenance(attrib,html)
end
@@ -412,10 +409,7 @@ WOK
if key.length > 0
key.sort.each do |m|
attrib="lev#{lv}"
- if lv == 0
- do_string_name(attrib,m)
- else do_string(attrib,m)
- end
+ lv==0 ? do_string_name(attrib,m) : do_string(attrib,m)
do_case(lv,hash[m])
end
end
@@ -423,16 +417,12 @@ WOK
def do_case(lv,a)
y = a.class
case
- when y == String
+ when y==String
attrib="lev#{lv}"
- if lv == 0
- do_string_name(attrib,a)
- else do_string(attrib,a)
- end
- #do_string_name(attrib,a)
- when y == Array
+ lv==0 ? do_string_name(attrib,a) : do_string(attrib,a)
+ when y==Array
do_array(lv,a)
- when y == Hash
+ when y==Hash
do_hash(lv,a)
end
end
@@ -482,11 +472,11 @@ WOK
s=' '*4
y = a.class
case
- when y == String
+ when y==String
do_string(lv,a)
- when y == Array
+ when y==Array
do_array(lv,a)
- when y == Hash
+ when y==Hash
do_hash(lv,a)
end
end
@@ -533,11 +523,11 @@ WOK
s=' '*4
y = a.class
case
- when y == String
+ when y==String
do_string(lv,a)
- when y == Array
+ when y==Array
do_array(lv,a)
- when y == Hash
+ when y==Hash
do_hash(lv,a)
end
end