diff options
author | Ralph Amissah <ralph@amissah.com> | 2014-07-01 00:54:37 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2014-07-01 00:54:39 -0400 |
commit | f74de438d030629eec66eeb1f7275ed62bc5c370 (patch) | |
tree | 2762210469f80149d12e2185677d2e4911523f68 /lib | |
parent | v5 v6: ao, doc objects, layout group open & close, identify, is_for (diff) |
v5 v6: ao, segment numbering, fixed width, leading zeros
* alphanumeric sorting
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sisu/v5/ao_doc_str.rb | 53 | ||||
-rw-r--r-- | lib/sisu/v5/ao_numbering.rb | 55 | ||||
-rw-r--r-- | lib/sisu/v5/constants.rb | 1 | ||||
-rw-r--r-- | lib/sisu/v6/ao_doc_str.rb | 53 | ||||
-rw-r--r-- | lib/sisu/v6/ao_numbering.rb | 55 | ||||
-rw-r--r-- | lib/sisu/v6/constants.rb | 1 |
6 files changed, 160 insertions, 58 deletions
diff --git a/lib/sisu/v5/ao_doc_str.rb b/lib/sisu/v5/ao_doc_str.rb index 5b93819e..931e51d3 100644 --- a/lib/sisu/v5/ao_doc_str.rb +++ b/lib/sisu/v5/ao_doc_str.rb @@ -506,8 +506,9 @@ module SiSU_AO_DocumentStructureExtract tags: tags, quote: quotes?, } - SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + t_o=SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) end + t_o=SiSU_AO_DocumentStructureExtract::Structure.new(@md).structure_markup(t_o) #must happen earlier, node info etc. require end elsif @@flag[:code]==:off if t_o =~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{|```[ ]+code(?:\.[a-z][0-9a-z_]+)?)/ @@ -1146,66 +1147,74 @@ module SiSU_AO_DocumentStructureExtract end end class Structure # this must happen early - def initialize(md,dob) - @md,@dob=md,dob + def initialize(md) + @md=md end - def structure - structure_markup - @dob + def structure(data) + data.compact.each do |dob| + structure_markup(dob) + end end - def structure_markup #build structure where structure provided only in meta header - @dob=if @dob.is==:para \ - && (((@dob.hang !~/[1-9]/) && (@dob.indent !~/[1-9]/)) \ - || (@dob.hang != @dob.indent)) \ - and not @dob.bullet_ - @dob=case @dob.obj + def structure_markup(dob) #build structure where structure provided only in meta header + dob=if dob.is==:para \ + && (((dob.hang !~/[1-9]/) && (dob.indent !~/[1-9]/)) \ + || (dob.hang != dob.indent)) \ + and not dob.bullet_ + dob=case dob.obj when /^#{@md.lv0}/ h={ + is: :heading, lv: 'A', ln: 0, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv1}/ h={ + is: :heading, lv: 'B', ln: 1, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv2}/ h={ + is: :heading, lv: 'C', ln: 2, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv3}/ h={ + is: :heading, lv: 'D', ln: 3, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv4}/ h={ + is: :heading, lv: '1', ln: 4, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv5}/ h={ + is: :heading, lv: '2', ln: 5, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv6}/ h={ + is: :heading, lv: '3', ln: 6, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) - else @dob + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) + else dob end - else @dob + else dob end - @dob + dob end end class OCN diff --git a/lib/sisu/v5/ao_numbering.rb b/lib/sisu/v5/ao_numbering.rb index cd631796..c4b6558f 100644 --- a/lib/sisu/v5/ao_numbering.rb +++ b/lib/sisu/v5/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) @@ -152,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 \ @@ -280,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 @@ -314,8 +353,10 @@ 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= + auto_seg_name(possible_seg_name) possible_seg_name=possible_seg_name. gsub(/(?:[:,-]|\W)/,'.'). gsub(/\.$/,'') @@ -339,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 diff --git a/lib/sisu/v5/constants.rb b/lib/sisu/v5/constants.rb index 42ab53a3..6b44ec68 100644 --- a/lib/sisu/v5/constants.rb +++ b/lib/sisu/v5/constants.rb @@ -104,6 +104,7 @@ Xx={ html_relative1: '※', } Mx={ + auto_seg_prefix: 's', ocn_id_char: 'o', note: 'note_', note_ref: 'noteref_', diff --git a/lib/sisu/v6/ao_doc_str.rb b/lib/sisu/v6/ao_doc_str.rb index 0c07eee7..2a96abb7 100644 --- a/lib/sisu/v6/ao_doc_str.rb +++ b/lib/sisu/v6/ao_doc_str.rb @@ -506,8 +506,9 @@ module SiSU_AO_DocumentStructureExtract tags: tags, quote: quotes?, } - SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + t_o=SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) end + t_o=SiSU_AO_DocumentStructureExtract::Structure.new(@md).structure_markup(t_o) #must happen earlier, node info etc. require end elsif @@flag[:code]==:off if t_o =~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{|```[ ]+code(?:\.[a-z][0-9a-z_]+)?)/ @@ -1146,66 +1147,74 @@ module SiSU_AO_DocumentStructureExtract end end class Structure # this must happen early - def initialize(md,dob) - @md,@dob=md,dob + def initialize(md) + @md=md end - def structure - structure_markup - @dob + def structure(data) + data.compact.each do |dob| + structure_markup(dob) + end end - def structure_markup #build structure where structure provided only in meta header - @dob=if @dob.is==:para \ - && (((@dob.hang !~/[1-9]/) && (@dob.indent !~/[1-9]/)) \ - || (@dob.hang != @dob.indent)) \ - and not @dob.bullet_ - @dob=case @dob.obj + def structure_markup(dob) #build structure where structure provided only in meta header + dob=if dob.is==:para \ + && (((dob.hang !~/[1-9]/) && (dob.indent !~/[1-9]/)) \ + || (dob.hang != dob.indent)) \ + and not dob.bullet_ + dob=case dob.obj when /^#{@md.lv0}/ h={ + is: :heading, lv: 'A', ln: 0, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv1}/ h={ + is: :heading, lv: 'B', ln: 1, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv2}/ h={ + is: :heading, lv: 'C', ln: 2, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv3}/ h={ + is: :heading, lv: 'D', ln: 3, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv4}/ h={ + is: :heading, lv: '1', ln: 4, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv5}/ h={ + is: :heading, lv: '2', ln: 5, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) when /^#{@md.lv6}/ h={ + is: :heading, lv: '3', ln: 6, } - SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) - else @dob + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) + else dob end - else @dob + else dob end - @dob + dob end end class OCN diff --git a/lib/sisu/v6/ao_numbering.rb b/lib/sisu/v6/ao_numbering.rb index 791f5bfc..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) @@ -152,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 \ @@ -280,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 @@ -314,8 +353,10 @@ 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= + auto_seg_name(possible_seg_name) possible_seg_name=possible_seg_name. gsub(/(?:[:,-]|\W)/,'.'). gsub(/\.$/,'') @@ -339,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 diff --git a/lib/sisu/v6/constants.rb b/lib/sisu/v6/constants.rb index 43fff554..487d96a0 100644 --- a/lib/sisu/v6/constants.rb +++ b/lib/sisu/v6/constants.rb @@ -104,6 +104,7 @@ Xx={ html_relative1: '※', } Mx={ + auto_seg_prefix: 's', ocn_id_char: 'o', note: 'note_', note_ref: 'noteref_', |