aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v6/ao_numbering.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2014-07-01 01:00:30 -0400
committerRalph Amissah <ralph@amissah.com>2014-07-01 01:00:30 -0400
commitf3832f0acc5b335fc820287ce2530435ad651202 (patch)
treeecd2004aecd2b706316291a98645ed98a5a25a75 /lib/sisu/v6/ao_numbering.rb
parentdebian/changelog (5.4.2-1) (diff)
parentv5 v6: sysenv, developer _CONSTRUCTION_ZONE warning setup modified (diff)
Merge tag 'sisu_5.4.3' into debian/sid
SiSU 5.4.3
Diffstat (limited to 'lib/sisu/v6/ao_numbering.rb')
-rw-r--r--lib/sisu/v6/ao_numbering.rb98
1 files changed, 81 insertions, 17 deletions
diff --git a/lib/sisu/v6/ao_numbering.rb b/lib/sisu/v6/ao_numbering.rb
index 0dbb1a71..d6faf3a6 100644
--- a/lib/sisu/v6/ao_numbering.rb
+++ b/lib/sisu/v6/ao_numbering.rb
@@ -63,10 +63,23 @@
module SiSU_AO_Numbering
class Numbering
attr_accessor :obj,:osp,:ocn,:lv,:name,:index,:comment
+ @@segments_count=0
def initialize(md,data)
@md,@data=md,data
@obj=@type=@ocn=@lv=@name=@index=@comment=nil
end
+ def number_of_segments?
+ if @@segments_count==0
+ @data.each do |dob|
+ if dob.is == :heading \
+ and dob.lv == '1'
+ @@segments_count += 1
+ end
+ end
+ @@segments_count
+ else @@segments_count
+ end
+ end
def numbering_song
data=@data
data=number_plaintext_para(data)
@@ -121,7 +134,8 @@ module SiSU_AO_Numbering
dob
end
def heading_tag_clean(heading_tag)
- heading_tag=heading_tag.gsub(/[ ]+/,'_').
+ heading_tag=heading_tag.
+ gsub(/[ ]+/,'_').
gsub(/["']/,'').
gsub(/[\/]/,'-').
gsub(/#{Mx[:fa_bold_o]}|#{Mx[:fa_bold_c]}/,'').
@@ -151,7 +165,6 @@ module SiSU_AO_Numbering
data=data.compact
data.each do |dob| #@md.seg_names << [additions to segment names]
title_no=nil
- dob=SiSU_AO_DocumentStructureExtract::Structure.new(@md,dob).structure_markup #must happen earlier, node info etc. require
if dob.is ==:heading \
&& dob.autonum_ \
and defined? @md.make.num_top \
@@ -279,6 +292,33 @@ module SiSU_AO_Numbering
end
@tuned_file=@tuned_file.flatten
end
+ def leading_zeros_fixed_width_number(possible_seg_name)
+ if possible_seg_name =~/^([\d]+?\.|[\d]+)$/m #!~/[.,:-]+/
+ possible_seg_name=possible_seg_name.
+ gsub(/\.$/,'')
+ nl=possible_seg_name.to_s.length
+ zero='0'
+ zeros_fixed_width=number_of_segments?.to_s.length
+ zero_width=(zeros_fixed_width - nl)
+ zero_width == 0 \
+ ? Mx[:auto_seg_prefix] +
+ possible_seg_name.to_s
+ : Mx[:auto_seg_prefix] +
+ zero*zero_width +
+ possible_seg_name.to_s
+ end
+ end
+ def auto_seg_name(possible_seg_name)
+ if possible_seg_name =~/^([\d]+?\.|[\d]+)$/m #!~/[.,:-]+/
+ leading_zeros_fixed_width_number(possible_seg_name)
+ elsif possible_seg_name =~/^[\d.,:-]+$/m
+ possible_seg_name=possible_seg_name.
+ gsub(/(?:[:,-]|\W)/,'.').
+ gsub(/\.$/,'')
+ #Mx[:auto_seg_prefix] + possible_seg_name
+ else possible_seg_name
+ end
+ end
def name_para_seg_filename(data) #segment naming, remaining
# paragraph name/numbering rules
# manual naming overrides, manual naming may be
@@ -313,9 +353,12 @@ module SiSU_AO_Numbering
@md.set_heading_seg=true
end
if dob.name !~/^\S+/ \
- and dob.obj =~/^\s*(?:\S+\s+)?([\d.,:-]+)/m #heading starts with a recognised numeric or word followed by a recognised numerical construct, use that as name
+ and dob.obj =~/^\s*(?:\S+\s+)?([\d.,:-]+)/m #heading starts with a recognised numeric or word followed by a recognised numeric construct, use that as name
possible_seg_name=$1
- possible_seg_name=possible_seg_name.gsub(/(?:[:,-]|\W)/,'.').
+ possible_seg_name=
+ auto_seg_name(possible_seg_name)
+ possible_seg_name=possible_seg_name.
+ gsub(/(?:[:,-]|\W)/,'.').
gsub(/\.$/,'')
if @md.seg_names.is_a?(Array) \
and not @md.seg_names.include?(possible_seg_name)
@@ -337,13 +380,13 @@ module SiSU_AO_Numbering
end
if dob.ln==4 \
and not dob.name #if still no segment name, provide a numerical one
- pf='_' #pg='' #may use e.g. '' or '~' or '_'
- segn_auto="#{pf}#{art_filename_auto.to_s}"
+ possible_seg_name=
+ auto_seg_name(art_filename_auto)
if @md.seg_names.is_a?(Array) \
- and not @md.seg_names.include?(segn_auto)
- dob.name=segn_auto
+ and not @md.seg_names.include?(possible_seg_name)
+ dob.name=possible_seg_name
dob.tags=set_tags(dob.tags,dob.name)
- @md.seg_names << segn_auto
+ @md.seg_names << possible_seg_name
else puts 'segment name (numbering) error'
end
art_filename_auto+=1
@@ -363,11 +406,17 @@ module SiSU_AO_Numbering
m=dob.ln.to_s
dob_tmp=[]
if @md.pagenew.inspect =~/#{m}/
- dob_tmp << SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) << dob
+ dob_tmp <<
+ SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) <<
+ dob
elsif @md.pagebreak.inspect =~/#{m}/
- dob_tmp << SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) << dob
+ dob_tmp <<
+ SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) <<
+ dob
elsif @md.pageline.inspect =~/#{m}/
- dob_tmp << SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) << dob
+ dob_tmp <<
+ SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) <<
+ dob
end
unless dob_tmp.length > 0; dob
else dob_tmp
@@ -381,11 +430,23 @@ module SiSU_AO_Numbering
: @segname
tags["#{dob.ocn}"]={ segname: @segname }
ocn_html_seg[dob.ocn]=if (dob.is==:heading || dob.is==:heading_insert)
- if dob.ln =~/[0-3]/ then { seg: nil, level: dob.ln }
+ if dob.ln =~/[0-3]/
+ {
+ seg: nil,
+ level: dob.ln,
+ }
#elsif dob.ln =~/[4-6]/
- else { seg: @seg, level: dob.ln }
+ else
+ {
+ seg: @seg,
+ level: dob.ln,
+ }
end
- else { seg: @seg, level: nil }
+ else
+ {
+ seg: @seg,
+ level: nil,
+ }
end
end
dob.tags=dob.tags.uniq if defined? dob.tags
@@ -434,7 +495,9 @@ module SiSU_AO_Numbering
and defined? @md.title.full \
and defined? @md.creator \
and @md.creator
- head=@md.title.main ? ([@lv='1',@obj=@md.title.main]) : ([@lv='1',@obj='[no title provided]'])
+ head=@md.title.main \
+ ? ([@lv='1',@obj=@md.title.main])
+ : ([@lv='1',@obj='[no title provided]'])
@tuned_file << head
end
end
@@ -479,7 +542,8 @@ module SiSU_AO_Numbering
unless @md.set_header_title
if t_o !~/^%{1,2}\s/m \
and t_o !~/\A\s*\Z/m
- @tuned_file << "#{Mx[:meta_o]}title#{Mx[:meta_c]} #{@md.heading_seg_first}"
+ @tuned_file <<
+ "#{Mx[:meta_o]}title#{Mx[:meta_c]} #{@md.heading_seg_first}"
@md.title.main=@md.heading_seg_first
@md.set_header_title=true
end