From 6811ac91f21a434fc7d967c11e1b20f33918c6ea Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 19 Mar 2012 22:07:29 -0400 Subject: v3: 3.2 branch is main (v3dv --> v3); dev (v3dv) branch directories removed * v3dv (3.2) "merged" into v3 (previously 3.1) (& removed) * conf/sisu/v3dv --> conf/sisu/v3 * data/sisu/v3dv --> data/sisu/v3 * lib/sisu/v3dv --> lib/sisu/v3 * bin/sisu* (v3dv references changed to v3) * (--dev modifier (superfluous for the time being) runs main v3 branch) --- lib/sisu/v3/dal_numbering.rb | 121 ++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 58 deletions(-) (limited to 'lib/sisu/v3/dal_numbering.rb') diff --git a/lib/sisu/v3/dal_numbering.rb b/lib/sisu/v3/dal_numbering.rb index 4b12793f..f5a09ef6 100644 --- a/lib/sisu/v3/dal_numbering.rb +++ b/lib/sisu/v3/dal_numbering.rb @@ -56,7 +56,7 @@ ** Description: system environment, resource control and configuration details =end -module SiSU_numbering +module SiSU_DAL_Numbering class Numbering attr_accessor :obj,:osp,:ocn,:lv,:name,:index,:comment def initialize(md,data) @@ -77,12 +77,15 @@ module SiSU_numbering def number_plaintext_para(data) @tuned_file=[] data.each do |dob| - if dob.of !~/(?:block|comment|layout)/ and dob.ocn_ #and dob.obj !~ /#{Mx[:gr_o]}Th|#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}/ #FIX - dob.obj.gsub!(/(.+)\n/,'\1 ') #messy, but idea is that tables should retain breaks + if (dob.of !=:block \ + && dob.of !=:comment \ + && dob.of !=:layout) \ + && dob.ocn_ #and dob.obj !~ /#{Mx[:gr_o]}Th|#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}/ #FIX + dob.obj=dob.obj.gsub(/(.+)\n/,'\1 ') #messy, but idea is that tables should retain breaks end unless dob.obj.class==Array - dob.obj.gsub!(/^\s+/,'') - dob.obj.gsub!(/\s$/,"\n") + dob.obj=dob.obj.gsub(/^\s+/,''). + gsub(/\s$/,"\n") end @tuned_file << dob end @@ -90,37 +93,35 @@ module SiSU_numbering end def number_sub_heading(dob,num,title_no) unless dob.obj =~/\d+\.|(?:chapter|article|section|clause)\s+\d+/i #name selection arbitrary, fix - case dob.name - when /-/; dob.obj.gsub!(/^/,"#{title_no} ") - when /^#/; dob.obj.gsub!(/^/,"#{title_no} ") - when /^[a-z_\.]+/ - dob.obj.gsub!(/^/,"#{title_no} ") + dob.obj=case dob.name + when /-/; dob.obj.gsub(/^/,"#{title_no} ") + when /^#/; dob.obj.gsub(/^/,"#{title_no} ") + when /^[a-z_\.]+/; dob.obj.gsub(/^/,"#{title_no} ") else dob.name=title_no if dob.name=~/^$/ #where title contains title number - dob.obj.gsub!(/^/,"#{title_no} ") if title_no =~/\d+/ #main, where title number is to be provided #watch changed placement + dob.obj.gsub(/^/,"#{title_no} ") if title_no =~/\d+/ #main, where title number is to be provided #watch changed placement end if @md.toc_lev_limit \ and @md.toc_lev_limit < num - dob.obj.gsub!(/^/,'!_ ') #bold line, watch + dob.obj=dob.obj.gsub(/^/,'!_ ') #bold line, watch end end dob end def heading_tag_clean(heading_tag) - heading_tag.gsub!(/[ ]+/,'_') - heading_tag.gsub!(/["']/,'') - heading_tag.gsub!(/[\/]/,'-') - heading_tag.gsub!(/#{Mx[:fa_bold_o]}|#{Mx[:fa_bold_c]}/,'') - heading_tag.gsub!(/#{Mx[:fa_italics_o]}|#{Mx[:fa_italics_c]}/,'') - heading_tag.gsub!(/#{Mx[:fa_underscore_o]}|#{Mx[:fa_underscore_c]}/,'') - heading_tag.gsub!(/#{Mx[:fa_cite_o]}|#{Mx[:fa_cite_c]}/,'') - heading_tag.gsub!(/#{Mx[:fa_insert_o]}|#{Mx[:fa_insert_c]}/,'') - heading_tag.gsub!(/#{Mx[:fa_strike_o]}|#{Mx[:fa_strike_c]}/,'') - heading_tag.gsub!(/#{Mx[:fa_superscript_o]}|#{Mx[:fa_superscript_c]}/,'') - heading_tag.gsub!(/#{Mx[:fa_subscript_o]}|#{Mx[:fa_subscript_c]}/,'') - heading_tag.gsub!(/#{Mx[:fa_hilite_o]}|#{Mx[:fa_hilite_c]}/,'') - heading_tag.gsub!(/#{Mx[:gl_bullet]}/,'') - heading_tag + heading_tag=heading_tag.gsub(/[ ]+/,'_'). + gsub(/["']/,''). + gsub(/[\/]/,'-'). + gsub(/#{Mx[:fa_bold_o]}|#{Mx[:fa_bold_c]}/,''). + gsub(/#{Mx[:fa_italics_o]}|#{Mx[:fa_italics_c]}/,''). + gsub(/#{Mx[:fa_underscore_o]}|#{Mx[:fa_underscore_c]}/,''). + gsub(/#{Mx[:fa_cite_o]}|#{Mx[:fa_cite_c]}/,''). + gsub(/#{Mx[:fa_insert_o]}|#{Mx[:fa_insert_c]}/,''). + gsub(/#{Mx[:fa_strike_o]}|#{Mx[:fa_strike_c]}/,''). + gsub(/#{Mx[:fa_superscript_o]}|#{Mx[:fa_superscript_c]}/,''). + gsub(/#{Mx[:fa_subscript_o]}|#{Mx[:fa_subscript_c]}/,''). + gsub(/#{Mx[:fa_hilite_o]}|#{Mx[:fa_hilite_c]}/,''). + gsub(/#{Mx[:gl_bullet]}/,'') end def auto_number_heading_ie_title(data) #also does some segment naming @tuned_file=[] @@ -135,20 +136,20 @@ module SiSU_numbering no1=num_top; no2=(num_top + 1); no3=(num_top + 2); no4=(num_top + 3) end t_not=0 - data.compact! chapter_number_counter=0 + data=data.compact data.each do |dob| #@md.seg_names << [additions to segment names] title_no=nil - dob=SiSU_document_structure_extract::Structure.new(@md,dob).structure_markup #must happen earlier, node info etc. require - if dob.is =='heading' \ - and dob.autonum_ \ + dob=SiSU_DAL_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 \ and @md.make.num_top !~/^$/ if dob.lv=='1' \ and dob.obj =~/^#\s|\s#(?:\s|$)/ chapter_number_counter +=1 - dob.obj.gsub!(/^#\s/,"#{chapter_number_counter} ") - dob.obj.gsub!(/#([:,]?\s|[.]?$)/,"#{chapter_number_counter}\\1") + dob.obj=dob.obj.gsub(/^#\s/,"#{chapter_number_counter} "). + gsub(/#([:,]?\s|[.]?$)/,"#{chapter_number_counter}\\1") end if dob.ln==no1 @subnumber=1 @@ -168,15 +169,15 @@ module SiSU_numbering tag=dob.obj.gsub(/(Article|Clause|Section|Chapter)\s+/,"\\1_#{title_no}").downcase tag=heading_tag_clean(tag) dob.tags=[tag,dob.tags].flatten if tag !~/^\d+$/ #check whether will work across file types with stop signs - (dob.obj =~/(Article|Clause|Section)\s+/) \ - ? (dob.obj.gsub!(/(Article|Clause|Section)\s+/,"\\1 #{title_no} ")) - : (dob.obj.gsub!(/^/,"#{title_no}. ")) #fix stop later + dob.obj=(dob.obj =~/(Article|Clause|Section)\s+/) \ + ? (dob.obj.gsub(/(Article|Clause|Section)\s+/,"\\1 #{title_no} ")) + : (dob.obj.gsub(/^/,"#{title_no}. ")) #fix stop later end if dob.ln !=no1 \ and dob.obj =~/^[\d.]+\s/ #fix -> if the title starts with a numbering scheme, do not auto-number, review dob.name ="#{title_no}" if not dob.name dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs - dob.obj.gsub!(/^/,"#{title_no}. ") + dob.obj=dob.obj.gsub(/^/,"#{title_no}. ") end @md.seg_names << title_no end @@ -184,7 +185,7 @@ module SiSU_numbering and dob.name!~/^[a-z_\.]+$/ \ and dob.obj !~/[A-Z]\.?\s/ #bug -> tmp fix, excludes A. B. C. lettering, but not roman numerals, is arbitrary, review required # not fixed, work on dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs - dob.obj.gsub!(/^/i,"#{title_no}. ") + dob.obj=dob.obj.gsub(/^/i,"#{title_no}. ") end end if dob.ln==no1 #watch because here you change dob.name @@ -207,7 +208,7 @@ module SiSU_numbering dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs dob.name.gsub(/^([a-z_\.]+)-$/,'\1') end - elsif dob.is =='heading' \ + elsif dob.is ==:heading \ and dob.autonum_ \ and @md.markup =~/num_extract/ #AS DANGEROUS force enable with document, note already does this type of numbering for cisg, locate and coordinate logic, is currently misplaced in code, chengwei inspired 2004w23/4 #here lies a bug, as is nil when run from -Dv --update, FIX @@ -229,11 +230,11 @@ module SiSU_numbering @tuned_file=@tuned_file.flatten end def ocn(data) #and auto segment numbering increment - @tuned_file=SiSU_document_structure_extract::OCN.new(@md,data).ocn + @tuned_file=SiSU_DAL_DocumentStructureExtract::OCN.new(@md,data).ocn @tuned_file end def xml(data) - @tuned_file=SiSU_document_structure_extract::XML.new(@md,data).dom + @tuned_file=SiSU_DAL_DocumentStructureExtract::XML.new(@md,data).dom @tuned_file end def minor_numbering(data) #and auto segment numbering increment @@ -241,20 +242,23 @@ module SiSU_numbering number_small,letter_small=0,0 letter=%w( 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 ) data.each do |dob| - if dob.of =~/heading|para|block/ - if dob.is =='heading' \ + if dob.of ==:heading \ + || dob.of ==:heading_insert \ + || dob.of ==:para \ + || dob.of ==:block + if dob.is ==:heading \ and dob.ln.to_s=~/^[1-9]/ #% sub-number system, (baby numbering) reset with any change of major number (more obviously should be placed in number titles, but that is conditionally executed, check and move later) number_small,letter_small=0,0 - elsif dob.is =~/para/ + elsif dob.is ==:para if dob.obj =~/^#[ 1]/ \ and dob.obj !~/^#\s+(?:~#)?$/ letter_small=0 number_small=0 if dob.obj =~ /^#1/ number_small+=1 - dob.obj.gsub!(/^#[ 1]/,"#{number_small}. ") #change 2004 + dob.obj=dob.obj.gsub(/^#[ 1]/,"#{number_small}. ") end if dob.obj =~/^_# / - dob.obj.gsub!(/^_# /,"#{letter[letter_small]}. ") #change 2004 + dob.obj=dob.obj.gsub(/^_# /,"#{letter[letter_small]}. ") dob.indent='1' letter_small+=1 end @@ -287,8 +291,8 @@ module SiSU_numbering end ocn_html_seg=[] data.each do |dob| - if dob.is=='heading' \ - and dob.ln \ + if dob.is==:heading \ + && dob.ln \ and dob.ln.to_s =~/^[456]/ if dob.ln==4 \ and not dob.name \ @@ -298,8 +302,8 @@ module SiSU_numbering 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 possible_seg_name=$1 - possible_seg_name.gsub!(/(?:[:,-]|\W)/,'.') - possible_seg_name.gsub!(/\.$/,'') + possible_seg_name=possible_seg_name.gsub(/(?:[:,-]|\W)/,'.'). + gsub(/\.$/,'') if not @md.seg_names.nil? \ and not @md.seg_names.include?(possible_seg_name) dob.name=possible_seg_name @@ -334,18 +338,19 @@ module SiSU_numbering puts "e r r o r -\t#{__FILE__}::#{__LINE__}\n#{dob.inspect}" end end - if dob.is =~/heading/ \ - and dob.ln==4 + if (dob.is ==:heading \ + || dob.is ==:heading_insert) \ + && dob.ln==4 @seg=dob.name end - @tuned_file << if dob.is=='heading' \ - and (@md.pagenew or @md.pagebreak) + @tuned_file << if dob.is==:heading \ + && (@md.pagenew || @md.pagebreak) m=dob.ln.to_s dob_tmp=[] if @md.pagenew.inspect =~/#{m}/ - dob_tmp << SiSU_document_structure::Object_layout.new.break(Hx[:br_page_new]) << dob + dob_tmp << SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) << dob elsif @md.pagebreak.inspect =~/#{m}/ - dob_tmp << SiSU_document_structure::Object_layout.new.break(Hx[:br_page]) << dob + dob_tmp << SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) << dob end para_result=unless dob_tmp.length > 0; dob else dob_tmp @@ -354,11 +359,11 @@ module SiSU_numbering end if defined? dob.ocn \ and dob.ocn - @segname=((dob.is=='heading'|| dob.is=='heading_insert') && dob.ln==4 && (defined? dob.name)) \ + @segname=((dob.is==:heading || dob.is==:heading_insert) && dob.ln==4 && (defined? dob.name)) \ ? (dob.name) : @segname tags["#{dob.ocn}"]={ segname: @segname } - ocn_html_seg[dob.ocn]=if dob.is =~/heading/ + ocn_html_seg[dob.ocn]=if (dob.is==:heading || dob.is==:heading_insert) x=if dob.ln =~/[1-3]/ { seg: nil, level: dob.ln } else #elsif dob.ln =~/[4-6]/ @@ -429,7 +434,7 @@ module SiSU_numbering unless @md.set_heading_seg if defined? dob.ln and dob.ln.to_s !~/^[123]/m \ and dob.obj !~/\A\s*\Z/m \ - and dob.is !='layout' + and dob.is !=:layout @md.set_heading_seg=true head=if @md.title.main ; dob.ln,dob.name,dob.obj=4,'seg',@md.title.main else dob.ln,dob.name,dob.obj=4,'seg','[segment]' -- cgit v1.2.3