diff options
author | Ralph Amissah <ralph@amissah.com> | 2012-12-12 14:58:58 -0500 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2012-12-12 14:58:58 -0500 |
commit | 1beb5aa3c376dbef89bc33024216650529ef7262 (patch) | |
tree | 1682500089c14fd49bcf52a3a001e291fadd5f75 /lib/sisu/v3/param.rb | |
parent | debian/changelog (3.3.2-1) (diff) | |
parent | v3: 3.3.3 version & changelog, dates touched (diff) |
Merge tag 'sisu_3.3.3' into debian/sid
Diffstat (limited to 'lib/sisu/v3/param.rb')
-rw-r--r-- | lib/sisu/v3/param.rb | 122 |
1 files changed, 68 insertions, 54 deletions
diff --git a/lib/sisu/v3/param.rb b/lib/sisu/v3/param.rb index f6084aab..bffba529 100644 --- a/lib/sisu/v3/param.rb +++ b/lib/sisu/v3/param.rb @@ -165,10 +165,11 @@ module SiSU_Param end def validate_length(s,l,n) #s=(s.length <= l) ? s : nil - s=if s.class==String \ + s=if s.is_a?(String) \ and s.length <= l s - elsif s.class==NilClass; nil + elsif s.is_a?(NilClass) + nil elsif s.class !=String STDERR.puts "#{n} is #{s.class}: programming error, String expected #{__FILE__}:#{__LINE__}" s @@ -226,6 +227,13 @@ module SiSU_Param if x =~/^%\s/ #ignore comment elsif x =~/:(\S+?):\s+(.+)/ a,b=/:(\S+?):\s+(.+)\Z/m.match(x)[1,2] + b=if b =~/\n/m + (b =~/;\n/m) \ + ? (b.split(/;\s*\n\s*/).join(';')) + : (b.split(/\s*\n\s*/).join(' ')) + else + b + end elsif i == 0 a='main' b=x @@ -307,7 +315,7 @@ module SiSU_Param names=@h['editor'] \ ? name_format(@h['editor']) : nil - s=(names.class==Hash) \ + s=(names.is_a?(Hash)) \ ? names[:name_str] : nil s=if s @@ -320,7 +328,7 @@ module SiSU_Param names=@h['editor'] \ ? name_format(@h['editor']) : nil - (names.class==Hash) \ + (names.is_a?(Hash)) \ ? names[:name_a_h] : nil end @@ -328,7 +336,7 @@ module SiSU_Param names=@h['contributor'] \ ? name_format(@h['contributor']) : nil - s=(names.class==Hash) \ + s=(names.is_a?(Hash)) \ ? names[:name_str] : nil s=if s @@ -341,7 +349,7 @@ module SiSU_Param names=@h['contributor'] \ ? name_format(@h['contributor']) : nil - (names.class==Hash) \ + (names.is_a?(Hash)) \ ? names[:name_a_h] : nil end @@ -349,7 +357,7 @@ module SiSU_Param names=@h['illustrator'] \ ? name_format(@h['illustrator']) : nil - s=(names.class==Hash) \ + s=(names.is_a?(Hash)) \ ? names[:name_str] : nil s=if s @@ -362,7 +370,7 @@ module SiSU_Param names=@h['illustrator'] \ ? name_format(@h['illustrator']) : nil - (names.class==Hash) \ + (names.is_a?(Hash)) \ ? names[:name_a_h] : nil end @@ -370,7 +378,7 @@ module SiSU_Param names=@h['photographer'] \ ? name_format(@h['photographer']) : nil - s=(names.class==Hash) \ + s=(names.is_a?(Hash)) \ ? names[:name_str] : nil s=if s @@ -383,7 +391,7 @@ module SiSU_Param names=@h['photographer'] \ ? name_format(@h['photographer']) : nil - (names.class==Hash) \ + (names.is_a?(Hash)) \ ? names[:name_a_h] : nil end @@ -391,7 +399,7 @@ module SiSU_Param names=@h['translator'] \ ? name_format(@h['translator']) : nil - s=(names.class==Hash) \ + s=(names.is_a?(Hash)) \ ? names[:name_str] : nil s=if s @@ -404,7 +412,7 @@ module SiSU_Param names=@h['translator'] \ ? name_format(@h['translator']) : nil - (names.class==Hash) \ + (names.is_a?(Hash)) \ ? names[:name_a_h] : nil end @@ -412,7 +420,7 @@ module SiSU_Param names=@h['audio'] \ ? name_format(@h['audio']) : nil - s=(names.class==Hash) \ + s=(names.is_a?(Hash)) \ ? names[:name_str] : nil s=if s @@ -425,7 +433,7 @@ module SiSU_Param names=@h['audio'] \ ? name_format(@h['audio']) : nil - (names.class==Hash) \ + (names.is_a?(Hash)) \ ? names[:name_a_h] : nil end @@ -433,7 +441,7 @@ module SiSU_Param names=@h['digitized_by'] \ ? name_format(@h['digitized_by']) : nil - s=(names.class==Hash) \ + s=(names.is_a?(Hash)) \ ? names[:name_str] : nil s=if s @@ -446,7 +454,7 @@ module SiSU_Param names=@h['digitized_by'] \ ? name_format(@h['digitized_by']) : nil - (names.class==Hash) \ + (names.is_a?(Hash)) \ ? names[:name_a_h] : nil end @@ -454,7 +462,7 @@ module SiSU_Param names=@h['prepared_by'] \ ? name_format(@h['prepared_by']) : nil - s=(names.class==Hash) \ + s=(names.is_a?(Hash)) \ ? names[:name_str] : nil s=if s @@ -468,7 +476,7 @@ module SiSU_Param ? name_format(@h['prepared_by']) : nil names=name_format(@h['prepared_by']) - (names.class==Hash) \ + (names.is_a?(Hash)) \ ? names[:name_a_h] : nil end @@ -540,7 +548,7 @@ module SiSU_Param (str =~/https?:\/\/\S+$/) ? ' ;' : ';' end def all - s=if @h['all']; @h['all'] + s=if @h['all'] then @h['all'] else s='' if defined? copyright.text \ @@ -553,36 +561,36 @@ module SiSU_Param and copyright.translation \ and not copyright.translation.empty? v=sep(copyright.translation) - s +='<br> translation ' + copyright.translation + v + s +='\\\\ translation ' + copyright.translation + v end if defined? copyright.illustrations \ and copyright.illustrations \ and not copyright.illustrations.empty? v=sep(copyright.illustrations) - s +='<br> illustrations ' + copyright.illustrations + v + s +='\\\\ illustrations ' + copyright.illustrations + v end if defined? copyright.photographs \ and copyright.photographs \ and not copyright.photographs.empty? v=sep(copyright.photographs) - s +='<br> photographs ' + copyright.photographs + v + s +='\\\\ photographs ' + copyright.photographs + v end if defined? copyright.digitization \ and copyright.digitization \ and not copyright.digitization.empty? v=sep(copyright.digitization) - s +='<br> digitization ' + copyright.digitization + v + s +='\\\\ digitization ' + copyright.digitization + v end if defined? copyright.audio \ and copyright.audio \ and not copyright.audio.empty? v=sep(copyright.audio) - s +='<br> audio ' + copyright.audio + v + s +='\\\\ audio ' + copyright.audio + v end if defined? copyright.license \ and copyright.license \ and not copyright.license.empty? - s +='<br> License: ' + copyright.license + s +='\\\\ License: ' + copyright.license end if s.empty? SiSU_Screen::Ansi.new(@opt.cmd,'WARNING Document Rights information missing; provide @rights: :copyright:').warn unless @opt.cmd =~/q/ @@ -597,7 +605,7 @@ module SiSU_Param self end def classify - a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m) + a=@s.split(/(\n%\s.+?$|[ ]*)(?:\n[ ]*(?=:)|\Z)/m) @h=build_hash(a) def coverage s=@h['coverage'] @@ -797,9 +805,9 @@ module SiSU_Param end end def emphasis - if @h['emphasis'] =~/bold/; 'bold' - elsif @h['emphasis'] =~/italics?/; 'italics' - elsif @h['emphasis'] =~/under(?:line|score)/; 'underscore' + if @h['emphasis'] =~/bold/ then 'bold' + elsif @h['emphasis'] =~/italics?/ then 'italics' + elsif @h['emphasis'] =~/under(?:line|score)/ then 'underscore' else nil end end @@ -811,8 +819,8 @@ module SiSU_Param matches='' w.each do |x| c=(x[1] =~/[i],/) ? :i : :s - matches=matches + x[0].gsub(/([${}])/,'\\\\\1') + '|' - arr_hash << { + matches=matches + x[0].gsub(/([${}])/,'\\\\\1') + '|' + arr_hash << { match: x[0].gsub(/([${}])/,'\\\\\1'), replace: x[2], case_s: c @@ -1024,7 +1032,6 @@ module SiSU_Param end def links a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m) - a end def notes a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m) @@ -1185,7 +1192,7 @@ module SiSU_Param SiSU_Screen::Ansi.new(@opt.cmd,'No SiSU markup version provided').warn if @opt.cmd =~/[VM]/ end else - mv=if defined? @markup_version.determined and not @markup_version.determined.nil? + mv=if @markup_version.determined.is_a?(Float) x=@markup_version.determined "markup version determined #{x}" else '' @@ -1229,13 +1236,13 @@ module SiSU_Param @notes=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).notes when /^@links:\s+(.+?)\Z/m #% * header metadata - links doc_links=SiSU_Param::Parameters::Md.new($1.strip,@opt,@env).links - count=1 + a_idx=0 @links=[] doc_links.each do |doc_link| if doc_link=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/ - @links[count]={} - @links[count][:say],@links[count][:url]=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(doc_link)[1,2] - count +=1 + @links[a_idx]={} + @links[a_idx][:say],@links[a_idx][:url]=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(doc_link)[1,2] + a_idx +=1 end end @lnk=@links @@ -1330,7 +1337,7 @@ module SiSU_Param if @markup.nil? \ or @markup.empty? @markup=@markup_version.determined.to_s - elsif @markup !~/0\.38/; @markup=@markup.strip + "; #{@markup_version.determined}" + elsif @markup !~/0\.38/ then @markup=@markup.strip + "; #{@markup_version.determined}" end if not defined? @title.full.nil? tf=para[/^:A~\S*(.+)$/m,1] @@ -1358,7 +1365,8 @@ module SiSU_Param if para =~/~\{|\^~ |~\^|\{.+?\[[1-6]\]\}\S+?\.ss[tm]/m @flag_auto_endnotes,@flag_endnotes=true,true end - if para =~/^(?:table\{|\{table)/i; @flag_tables=true + if para =~/^(?:table\{|\{table)/i + @flag_tables=true end end if para =~/^:?A~/ @@ -1395,6 +1403,12 @@ module SiSU_Param @sem_tag=true if para=~/[:;]\{.+?\}[:;][a-z+]/ #refix later end end #% here endeth the document loop + unless @make + if @opt.cmd =~/[VM]/ + SiSU_Screen::Ansi.new(@opt.cmd,'@make:','header absent').warn + end + @make=SiSU_Param::Parameters::Md.new('@make: ',@opt,@env).make + end if @ec[:image].length > 0 @ec[:image]=@ec[:image].flatten.uniq @ec[:image].delete_if {|x| x =~/https?:\/\// } @@ -1404,29 +1418,29 @@ module SiSU_Param @ec[:multimedia]=@ec[:multimedia].uniq.flatten.sort unless @rights if defined? @creator.author \ - and @creator.author \ + and @creator.author.is_a?(String) \ and defined? @date.published \ - and @date.published + and @date.published.is_a?(String) @rights=SiSU_Param::Parameters::MdDefault.new.rights(@creator.author,@date.published) elsif defined? @creator.author \ - and @creator.author + and @creator.author.is_a?(String) @rights=SiSU_Param::Parameters::MdDefault.new.rights("[#{@creator.author}]",'') end end if defined? @classify.topic_register \ - and not @classify.topic_register.nil? \ + and @classify.topic_register.is_a?(String) \ and @classify.topic_register.length >3 topic_register=@classify.topic_register - u=topic_register.scan(/[^;]+/) + u=topic_register.scan(/[^;]+/m).sort v=[] u.each do |l| - v << l.scan(/[^:]+/) + v << l.scan(/[^:]+/m) end v.each do |m| - m[-1]=m[-1].scan(/[^|]+/) if m[-1] =~/[|]/ + m[-1]=m[-1].scan(/[^|]+/m) if m[-1] =~/[|]/m @topic_register_array << m end - @topic_register_array=@topic_register_array.sort + @topic_register_array end if @i18n @i18n=@i18n.uniq @@ -1453,9 +1467,9 @@ module SiSU_Param # gsub(/:?C/,'3'). # gsub(/:?B/,'2'). # gsub(/:?A/,'1') - translate=if translate =~/^\d+$/; translate.to_i - else translate - end + translate=(translate =~/^\d+$/) \ + ? translate.to_i + : translate else nil end end @@ -1489,7 +1503,7 @@ module SiSU_Param @dgst_skin=skin ? (@sys.md5(skin)) : nil end end - @publisher ||= "#@@publisher (this copy)" + @publisher ||= "#{@@publisher} (this copy)" fn_set_lang=SiSU_Env::StandardiseLanguage.new(@opt.lng).language unless @language[:code] \ and @language[:name] @@ -1506,9 +1520,9 @@ module SiSU_Param # @flv.each do |l| # lang=SiSU_Env::StandardiseLanguage.new.file_to_language(l) # c={ a: '', b: '', c: '' } -# if @fnl[:pre] =~/\S/; c[:a]="#{lang[:c]}." -# elsif @fnl[:mid] =~/\S/; c[:b]=".#{lang[:c]}" -# elsif @fnl[:post] =~/\S/; c[:c]=".#{lang[:c]}" +# if @fnl[:pre] =~/\S/ then c[:a]="#{lang[:c]}." +# elsif @fnl[:mid] =~/\S/ then c[:b]=".#{lang[:c]}" +# elsif @fnl[:post] =~/\S/ then c[:c]=".#{lang[:c]}" # end # @lang << [lang[:n],"#{c[:a]}sisu_manifest#{c[:b]}.html#{c[:c]}"] # end if @flv |