From adf811ce6c6513e4db1fb2ddf67019607a1012ff Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 15 Jan 2015 22:32:08 -0500 Subject: d: po4a_shelf, shelf current po4a, change tack --- data/doc/sisu/CHANGELOG_v6 | 2 + lib/sisu/develop/hub_actions.rb | 8 +- lib/sisu/develop/hub_options.rb | 15 +- lib/sisu/develop/po4a.rb | 1217 -------------------------------- lib/sisu/develop/po4a_set.rb | 297 -------- lib/sisu/develop/src_po4a_shelf.rb | 1217 ++++++++++++++++++++++++++++++++ lib/sisu/develop/src_po4a_shelf_set.rb | 297 ++++++++ 7 files changed, 1526 insertions(+), 1527 deletions(-) delete mode 100644 lib/sisu/develop/po4a.rb delete mode 100644 lib/sisu/develop/po4a_set.rb create mode 100644 lib/sisu/develop/src_po4a_shelf.rb create mode 100644 lib/sisu/develop/src_po4a_shelf_set.rb diff --git a/data/doc/sisu/CHANGELOG_v6 b/data/doc/sisu/CHANGELOG_v6 index 22b0ad9c..06773a97 100644 --- a/data/doc/sisu/CHANGELOG_v6 +++ b/data/doc/sisu/CHANGELOG_v6 @@ -91,6 +91,8 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_6.4.0.orig.tar.xz * po4a, reinstate possibility to initialize po4a management of translated marked up documents, i.e. to place translated versions of a sisu document under po4a management (provide po4a.cfg file) + NOTE: shelf, abandon, change tack (for now at least) + explore a different way * utils_composite, composite documents (.ssm) extract the list of insert files diff --git a/lib/sisu/develop/hub_actions.rb b/lib/sisu/develop/hub_actions.rb index 68f0aef9..44834cba 100644 --- a/lib/sisu/develop/hub_actions.rb +++ b/lib/sisu/develop/hub_actions.rb @@ -707,18 +707,18 @@ module SiSU_Hub_Actions end end end - if @opt.act[:po4a][:set]==:on #% --po4a, -P + if @opt.act[:po4a_shelf][:set]==:on #% --po4a-shelf if @opt.f_pths.length > 0 - require_relative 'po4a' + require_relative 'src_po4a_shelf' begin SiSU_Hub_Loops::OptionLoopFiles.new(@opt). loop_files_on_given_option do - SiSU_Po4a::Source.new(@opt).read # po4a.rb + SiSU_Po4a::Source.new(@opt).read # src_po4a_shelf.rb end ensure end else - msg='po4a request requires sisu markup files' + msg='src_po4a_shelf request requires sisu markup files' if (@opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan). diff --git a/lib/sisu/develop/hub_options.rb b/lib/sisu/develop/hub_options.rb index 1ea96af8..c3f31a88 100644 --- a/lib/sisu/develop/hub_options.rb +++ b/lib/sisu/develop/hub_options.rb @@ -614,7 +614,7 @@ module SiSU_Commandline if ch =~/N/ then select_arr << '--digests' ch=ch.gsub(/[N]/,'') end - if ch =~/P/ then select_arr << '--po4a' + if ch =~/P/ then select_arr << '--po4a-shelf' ch=ch.gsub(/[P]/,'') end if ch =~/d/ then select_arr << '--sqlite' @@ -1301,8 +1301,11 @@ module SiSU_Commandline =~/"--harvest"/) \ ? { bool: true, set: :on } : { bool: false, set: :na } - act[:po4a]=if (select_arr.inspect \ - =~/"--po4a"|"--pot?"/) + act[:po4a_shelf]=(select_arr.inspect \ + =~/"--po4a-shelf"|"--pot?-shelf"/) \ + ? { bool: true, set: :on } + : { bool: false, set: :na } + if act[:po4a_shelf][:set]==:on act[:po4a_lang_trans]=if select_arr.inspect \ =~/"--trans-([a-z]{2}):((?:(?:[a-z]{2}\b),?)+)/ lng_src,lng_trn=$1,$2.split(',') @@ -1321,18 +1324,12 @@ module SiSU_Commandline else { bool: false, set: :na } end - { bool: true, set: :on } else act[:po4a_lang_trans]= \ { bool: false, set: :na } act[:po4a_lang_init]= \ { bool: false, set: :na } - { bool: false, set: :na } end - #act[:po4a]=(select_arr.inspect \ - #=~/"--po4a"|"--pot?"/) \ - #? { bool: true, set: :on } - #: { bool: false, set: :na } act[:git]=(select_arr.inspect \ =~/"--git"/) \ ? { bool: true, set: :on } diff --git a/lib/sisu/develop/po4a.rb b/lib/sisu/develop/po4a.rb deleted file mode 100644 index 285132a5..00000000 --- a/lib/sisu/develop/po4a.rb +++ /dev/null @@ -1,1217 +0,0 @@ -# encoding: utf-8 -=begin - -* Name: SiSU - -** Description: documents, structuring, processing, publishing, search -*** pot file generation - -** Author: Ralph Amissah - - - -** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah, - All Rights Reserved. - -** License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) Ralph Amissah - - This program is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - this program. If not, see . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - -** SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - -** Hompages: - - - -** Git - - - -=end -module SiSU_Po4a - require_relative 'ao' # ao.rb - require_relative 'se' # se.rb - include SiSU_Env - require_relative 'ao_composite' # ao_composite.rb - require_relative 'shared_metadata' # shared_metadata.rb - require_relative 'po4a_set' # po4a_set.rb - include SiSU_Param - require_relative 'object_munge' # object_munge.rb - require_relative 'utils_composite' # utils_composite.rb - class Source - include SiSU_Object_Munge - @@opt_src,@@opt_trn,@@opt_src_,@@opt_trn_,@@md_src,@@md_trn= - nil, nil, nil, nil, nil, nil - @@auto_translation_ = :go - def initialize(opt,fn=nil) - @opt,@fn=opt,fn - #unless @opt.fns =~/(.+?\.(?:-|ssm\.)?sst)$/ - # puts "#{@opt.fns} not a processed file type" - #end - file_arr=SiSU_Info_Env::InfoEnv.new.source_file_processing_array(@opt.fns) - SiSU_Param::Parameters::Instructions.new(file_arr,@opt).extract - r=Px[:lng_lst_rgx].gsub(/\|en\|/,'|') - @lang_regx=%r{(?:#{r})} - if opt.fns =~/\S+?~#{@lang_regx}\.ss[mti]/ \ - and opt.f_pth[:lng]!=@opt.lng_base - @@opt_src_=false - @@opt_trn=opt - @@md_trn=SiSU_Param::Parameters.new(opt).get - else - @@opt_src_=true - @@opt_src=opt - @@md_src=SiSU_Param::Parameters.new(opt).get - end - end - def wrap_width_set(md,env) - if defined? md.make.plaintext_wrap \ - and md.make.plaintext_wrap - md.make.plaintext_wrap - elsif defined? env.plaintext_wrap \ - and env.plaintext_wrap - env.plaintext_wrap - else 78 - end - end - def process_file(md,env,file,wrap_width,fn) - unless @opt.act[:quiet][:set]==:on - tool=(@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? "#{env.program.text_editor} #{file.output_path.pot.dir}/" - : @opt.fns - (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? SiSU_Screen::Ansi.new( - @opt.act[:color_state][:set], - 'Pot po4a', - tool - ).green_hi_blue - : SiSU_Screen::Ansi.new( - @opt.act[:color_state][:set], - 'Pot po4a', - tool - ).green_title_hi - if (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new( - @opt.act[:color_state][:set], - @opt.fns, - file.output_path.pot.dir - ).flow - end - end - if @opt.fns =~/\S+?~#{@lang_regx}\.ss[mti]/ \ - or @opt.f_pth[:lng] !=@opt.lng_base - opt_lang_trn_fn=fn - @ao_arr_lang_trans= - SiSU_AO::Source.new(@opt,opt_lang_trn_fn,:po4a).get # ao file drawn here - opt_lang_src_fn=(fn =~/\S+?~\S{2}(?:_\S{2})?\.ss[mti]/) \ - ? (fn.gsub(/(\S+?)~\S{2}(?:_\S{2})?(\.ss[mti])/,'\1\2')) #check i - : fn - transdir,srcdir=Dir.pwd,Dir.pwd - if Dir.pwd.to_s =~/\/#{@lang_regx}$/ - transdir=Dir.pwd - srcdir=transdir. - gsub(/\/#{@lang_regx}$/, - "/#{@opt.lng_base}") - if FileTest.directory?(srcdir) - Dir.chdir(srcdir) - end - else nil - end - if FileTest.file?("#{srcdir}/#{opt_lang_src_fn}") - @ao_arr_lang_src= - SiSU_AO::Source.new( - @@opt_src, - opt_lang_src_fn, - :po4a - ).get # ao file drawn here - else - puts "no identified source document" - exit - end - Dir.chdir(transdir) if transdir - else - @ao_arr_lang_src= - SiSU_AO::Source.new( - @opt, - fn, - :po4a - ).get # ao file drawn here - @ao_arr_lang_trans=nil - end - SiSU_Po4a::Source::Scroll.new( - fn, - @ao_arr_lang_src, - @ao_arr_lang_trans, - @@md_src, - @@md_trn, - wrap_width - ).songsheet - end - def read - begin - src={} - src[:pth]=@opt.f_pth[:pth] - src[:files]=if @opt.fns =~ /\.(?:(?:-|ssm\.)sst|ssm)$/ - @opt.fns=@opt.fns.gsub(/\.ssm\.sst$/,'.ssm') - SiSU_Assemble::CompositeFileList.new(@opt).read - else - [@opt.fns] - end - md=SiSU_Param::Parameters.new(@opt).get - env=SiSU_Env::InfoEnv.new(@opt.fns) - file=SiSU_Env::FileOp.new(md) - Po4aCfg.new(@opt,file).po4a_cfg - wrap_width=wrap_width_set(md,env) - src[:files].each do |fn| - process_file(md,env,file,wrap_width,fn) - end - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - private - class Scroll 0 \ - and not @@endnotes_ - @pot[:body] << br - wrap_endnotes(notes_s,notes_t) - elsif @@endnotes[:para] \ - and @@endnotes_ - @pot[:body] << br*2 - end - end - def para(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document - util=nil - wrapped=if dob_src.indent =~/[1-9]/ \ - and dob_src.indent == dob_src.hang - s_mark=desc=orig=trans='' - if dob_src.bullet_ - mark="_#{dob_src.indent}* " - d="#{dob_src.is.to_s}: indent #{dob_src.indent}, bullet" - instruct=s_mark='' - if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# markup for indented bullet text is at the start of the line/object, } \ - + %{an underscore followed by the indent level and an asterisk "#{mark}"} - s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} - end - desc="#{d}#{s_mark}#{instruct}" - else - mark="_#{dob_src.indent} " - d="#{dob_src.is.to_s}: indent #{dob_src.indent}" - instruct=s_mark='' - if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# markup for indented text is at the start of the line/object, } \ - + %{an underscore followed by the indent level "#{mark}"} - s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} - end - desc="#{d}#{s_mark}#{instruct}" - end - orig="#{s_mark}#{dob_src.obj}" - trans=((dob_trn=='') \ - || (dob_src.obj == dob_trn.obj)) \ - ? '' - : "#{s_mark}#{dob_trn.obj}" - if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ - and trans.empty? \ - and auto_translate? - trans=auto_translation(dob_src.obj,:src) - end - util=pot_structure_wrap(desc,orig,trans) - elsif dob_src.hang =~/[0-9]/ \ - and dob_src.indent != dob_src.hang - s_mark=desc=orig=trans='' - mark="_#{dob_src.hang}_#{dob_src.indent} " - d="#{dob_src.is.to_s}: hang #{dob_src.hang} indent #{dob_src.indent}" - instruct=s_mark='' - if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# markup for indented text with a first line indented } \ - + %{to a different level from the rest of the paragraph, } \ - + %{is at the start of the line/object, } \ - + %{an underscore and the first indent level } \ - + %{a second underscore and the indent level for the rest of the paragraph, "#{mark1}"} - s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} - end - desc="#{d}#{s_mark}#{instruct}" - orig="#{s_mark}#{dob_src.obj}" - trans=((dob_trn=='') \ - || (dob_src.obj == dob_trn.obj)) \ - ? '' - : "#{s_mark}#{dob_trn.obj}" - if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ - and trans.empty? \ - and auto_translate? - trans=auto_translation(dob_src.obj,:src) - end - util=pot_structure_wrap(desc,orig,trans) - else - s_mark=desc=orig=trans='' - if dob_src.bullet_ - mark='_* ' - d="#{dob_src.is.to_s}: bullet" - instruct=s_mark='' - if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# markup for indented text is at the start of the line/object, } \ - + %{an underscore followed by an asterisk "#{mark}"} - s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} - end - desc="#{d}#{s_mark}#{instruct}" - orig="#{s_mark}#{dob_src.obj}" - trans=((dob_trn=='') \ - || (dob_src.obj == dob_trn.obj)) \ - ? '' - : "#{s_mark}#{dob_trn.obj}" - if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ - and trans.empty? \ - and auto_translate? - trans=auto_translation(dob_src.obj,:src) - end - else - mark='' - d=dob_src.is.to_s - instruct=%{\n# regular paragraph, no special markup} - if @md.opt.act[:maintenance][:set]==:on - instruct="\n# " - s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} - end - desc="#{d}#{s_mark}#{instruct}" - orig=dob_src.obj - trans=((dob_trn=='') \ - || (dob_src.obj == dob_trn.obj)) \ - ? '' - : "#{s_mark}#{dob_trn.obj}" - if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ - and trans.empty? \ - and auto_translate? - trans=auto_translation(dob_src.obj,:src) - end - end - util=pot_structure_wrap(desc,orig,trans) - end - wrapped=util.line_wrap - @pot[:body] << wrapped << br # main text, contents, body KEEP - if @@endnotes[:para] \ - and notes_s.length > 0 \ - and not @@endnotes_ - @pot[:body] << br - wrap_endnotes(notes_s,notes_t) - elsif @@endnotes[:para] \ - and @@endnotes_ - @pot[:body] << br*2 - end - end - def block(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document - mark="block{\\n\\n...\\n\\n}block" - d=dob_src.is.to_s - instruct=s_mark='' - if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# block text is a text block with an opening and closing marker, } \ - + %{the content of which may be wrapped} - s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} - end - desc="#{d}#{s_mark}#{instruct}" - orig=dob_src.obj - trans=((dob_trn=='') \ - || (dob_src.obj == dob_trn.obj)) \ - ? '' - : "#{s_mark}#{dob_trn.obj}" - if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ - and trans.empty? \ - and auto_translate? - trans=auto_translation(dob_src.obj,:src) - end - util=pot_structure_wrap(desc,orig,trans) - unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << br - end - def group(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document - mark="group{\\n\\n...\\n\\n}group" - d=dob_src.is.to_s - instruct=s_mark='' - if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# group text is a text block with an opening and closing marker, } \ - + %{the content of which may be wrapped} - s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} - end - desc="#{d}#{s_mark}#{instruct}" - orig=dob_src.obj - trans=((dob_trn=='') \ - || (dob_src.obj == dob_trn.obj)) \ - ? '' - : "#{s_mark}#{dob_trn.obj}" - if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ - and trans.empty? \ - and auto_translate? - trans=auto_translation(dob_src.obj,:src) - end - util=pot_structure_wrap(desc,orig,trans) - unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << br - end - def verse(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document - mark="poem{\n\nverse\n\nverse\n\n...\n\n}poem" - d=dob_src.is.to_s - instruct=s_mark='' - if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# verse are part of the text block described as a poem, } \ - + %{the first verse is preceeded by an opening marker, } \ - + %{and the last verse by a closing marker, } \ - + %{the content of which should remain unwrapped} - s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} - end - desc="#{d}#{s_mark}#{instruct}" - orig=dob_src.obj - trans=(dob_trn=='') ? '' : dob_trn.obj - util=pot_structure_wrap(desc,orig,trans) - unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << br - end - def code(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document - mark="code{\\n\\n...\\n\\n}code" - d=dob_src.is.to_s - instruct=s_mark='' - if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# codeblocks are a text block with an opening and closing marker, } \ - + %{the content of which should remain unwrapped} - s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} - end - desc="#{d}#{s_mark}#{instruct}" - orig=dob_src.obj - trans=(dob_trn=='') ? '' : dob_trn.obj - util=pot_structure_wrap(desc,orig,trans) - unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << br - end - def table(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document - mark="table{\\n\\n...\\n\\n}table" - d=dob_src.is.to_s - instruct=s_mark='' - if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# tables are a text block with an opening and closing marker, } \ - + %{the content of which should remain unwrapped} - s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} - end - desc="#{d}#{s_mark}#{instruct}" - orig=dob_src.obj - orig=orig.gsub(/#{Mx[:tc_c]}/,"\n") - trans=(dob_trn=='') ? '' : dob_trn.obj - trans=trans.gsub(/#{Mx[:tc_c]}/,"\n") - util=pot_structure_wrap(desc,orig,trans) - unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << br - end - def idx_markup(idx) - struct=['={'] - idx.sort.each do |x| - x.each_with_index do |y,i0| - case y - when String - struct << ';' unless struct[-1] =~/=\{/ - struct << y - if x[i0+1].class == Hash \ - and x[i0+1][:sub].length > 0 - struct << ':' - end - when Hash - if y[:plus].to_i > 0 - struct << '+' + y[:plus].to_s - end - if y[:sub].length > 0 - y[:sub].each_with_index do |z,i1| - z.each_with_index do |a,i2| - #p a - if z.length > 0 - struct << a[0] - if a[1][:plus].to_i > 0 - struct << '+' + a[1][:plus].to_s - end - if (i1 + 1) < y[:sub].length - struct << '|' - end - end - end - end - end - end - end - end - struct << '}' - #puts struct.join - struct.join - end - def idx(dob_src='',dob_trn='') #% used for book index but broken as original markup lost, already abstracted, fix - mark="={ ... }" - instruct=s_mark='' - if @md.opt.act[:maintenance][:set]==:on - instruct=%{\n# the book index should be attached unwrapped to the preceding text block } \ - + %{(there should be a new line, but no empty line)} - s_mark="\n# " + %{"\\n#{mark}\\n\\n"} - end - d='book-idx' - desc="#{d}#{s_mark}#{instruct}" - orig=pot_structure.idx_markup(dob_src.idx) #'={' + dob_src.idx + '}' - trans=if defined? dob_trn.idx \ - and not dob_trn.idx.nil? \ - and not dob_trn.idx.empty? - pot_structure.idx_markup(dob_trn.idx) #'={' + dob_trn.idx + '}' - else '' - end - util=pot_structure_wrap(desc,orig,trans) - unwrapped=util.no_line_wrap_block - @pot[:body] << unwrapped << br - end - self - end - def pot_markup(data_src,data_trn) - #@endnotes,@copen,@pot_contents_close=Array.new(3){[]} - a_l=if data_trn - a_l=(data_src.length >= data_trn.length) \ - ? data_src.length - : data_trn.length - else - data_src.length - end - s,t=0,0 - if @md.fns =~ /\.(?:(?:-|ssm\.)?sst|ssm)$/ - (data_trn.nil?) \ - ? pot_metadata_src - : pot_metadata_src_trn - end - 0.upto(a_l-1) do |i| - if data_trn - unless data_src[s] \ - and data_trn[t] - break - end - if data_src[s].of == :comment \ - and data_trn[t].of == :comment \ - and (data_src[s].is == data_trn[t].is) - s+=1;t+=1 - next - end - if ((data_src[s].is == :comment) \ - || (data_trn[t].is == :comment)) \ - and (data_src[s].is != data_trn[t].is) - if data_src[s].is == :comment - if @md.opt.act[:maintenance][:set]==:on - puts "src (comment):\n\t" \ - + data_src[s].obj - end - s+=1 - #next if data_src[s].is == :comment - elsif data_trn[t].is == :comment - if @md.opt.act[:maintenance][:set]==:on - puts "trans (comment):\n\t" \ - + data_trn[t].obj - end - t+=1 - #next if data_trn[t].is == :comment - end - end - if ((defined? data_src[s].ocn) \ - && (data_src[s].ocn.is_a?(Fixnum))) \ - and ((defined? data_trn[t].ocn) \ - && (data_trn[t].ocn.is_a?(Fixnum))) \ - and (data_src[s].ocn == data_trn[t].ocn) - @m_s,@m_t=s,t - elsif ((defined? data_src[s].ocn) \ - && (data_src[s].ocn.is_a?(Fixnum))) \ - and ((defined? data_trn[t].ocn) \ - && (data_trn[t].ocn.is_a?(Fixnum))) \ - and (data_src[s].ocn != data_trn[t].ocn) - p '--- OCN ---' - p 'mis-match' - p data_src[s].ocn - p data_src[s].obj - p data_trn[t].ocn - p data_trn[t].obj - p '---' - p 'previous match' - p data_src[@m_s].ocn - p data_src[@m_s].obj - p data_trn[@m_t].ocn - p data_trn[@m_t].obj - exit - elsif (((defined? data_src[s].ocn) \ - && (defined? data_trn[t].ocn)) \ - and data_src[s].ocn.class != data_trn[t].ocn.class) - p '--- OCN class ---' - p 'mis-match' - p data_src[s].ocn if defined? data_src[s].ocn - p data_src[s].obj - p data_trn[t].ocn if defined? data_trn[t].ocn - p data_trn[t].obj - #p '---' - #p 'previous match' - #p data_src[@m_s].ocn - #p data_src[@m_s].obj - #p data_trn[@m_t].ocn - #p data_trn[@m_t].obj - #elsif (defined? data_src[s].ocn != defined? data_trn[t].ocn) \ - #and (data_src[s].ocn.nil? != data_trn[t].ocn.nil?) - # p '--- missing OCN? ---' - # p 'mis-match' - # p data_src[s].ocn if defined? data_src[s].ocn - # p data_src[s].obj - # p data_trn[t].ocn if defined? data_trn[t].ocn - # p data_trn[t].obj - else - end - end - notes_s,notes_t='','' - data_src[s],notes_s=markup(data_src[s]) - if data_trn - data_trn[t],notes_t=markup(data_trn[t]) - #data_src[s],data_trn[t]=pot_data(data_src[s],notes_s,data_trn[t],notes_t) - pot_data(data_src[s],notes_s,data_trn[t],notes_t) - else - #data_src[s],nul=pot_data(data_src[s],notes_s) - pot_data(data_src[s],notes_s) - end - s+=1;t+=1 - end - @pot #watch - end - def pot_data(dob_src='',notes_s='',dob_trn='',notes_t='') - if dob_src.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ - if defined? dob_src.ocn \ - and dob_src.ocn.to_s =~/\d+/ - paranum=dob_src.ocn.to_s - @p_num=SiSU_Po4aUtils::ParagraphNumber.new(paranum) - end - case dob_src.is - when :heading - pot_structure.heading(dob_src,notes_s,dob_trn,notes_t) - when :para - pot_structure.para(dob_src,notes_s,dob_trn,notes_t) - when :group - pot_structure.group(dob_src,notes_s,dob_trn,notes_t) - when :block - pot_structure.block(dob_src,notes_s,dob_trn,notes_t) - when :verse - pot_structure.verse(dob_src,notes_s,dob_trn,notes_t) - when :code - pot_structure.code(dob_src,notes_s,dob_trn,notes_t) - when :table - pot_structure.table(dob_src,notes_s,dob_trn,notes_t) - end - if defined? dob_src.idx \ - and not dob_src.idx.nil? \ - and not dob_src.idx.empty? - pot_structure.idx(dob_src,dob_trn) - end - dob_src='' if (dob_src.obj =~// \ - and dob_src.obj =~/^(-\{{2}~\d+|)/) # -endnote - if dob_src ## Clean Prepared Text - dob_src.obj=dob_src.obj.gsub(//,' '). - gsub(/<:\S+>/,' ') if dob_src ## Clean Prepared Text - end - end - #[dob_src,dob_trn] - end - def markup(dob) - dob,notes=objects.textface_marks_po4a(dob,:separate) - [dob,notes] - end - def publish(fn,pot) - content=[] - content << pot[:open] - content << pot[:head] - content << pot[:metadata] - content << pot[:body] - content << @@endnotes[:end] if @@endnotes_ - Output.new(fn,content,@md,@process).po4a - @@endnotes={ para: [], end: [] } - end - end - class Po4aCfg - include SiSU_Composite_Doc_Utils # composite doc, .ssm, extract all related insert files, array of filenames test - def initialize(opt,file) - @opt,@file=opt,file - end - def po4a_cfg_filename - 'po4a.cfg' - end - def dir - def pwd - Dir.pwd - end - def po4a_ - 'po4a/' # '' - end - def pot - po4a_ + 'pot' - end - def po - po4a_ + 'po' - end - self - end - def po4a_cfg_file - File.open("#{Dir.pwd}/#{po4a_cfg_filename}",'w') - end - def language - def sisu_languages_available - Px[:lng_lst] - end - def translation_languages_selected - @opt.act[:po4a_lang_trans][:trn] \ - ? @opt.act[:po4a_lang_trans][:trn] - : [] - end - def translation_languages_available - translation_languages_selected & sisu_languages_available - end - def source_language_selected_str - @opt.act[:po4a_lang_trans][:src] \ - ? @opt.act[:po4a_lang_trans][:src] - : 'en' - end - def translation_languages_available_str - translation_languages_available.join(' ') - end - def translation_languages_selected_str - @opt.act[:po4a_lang_trans][:trn].join(' ') - end - self - end - def po4a_cfg - doc_import_list=composite_and_imported_filenames_array(@opt.fno) - po4a_cfg_arr=[] - po4a_cfg_arr \ - << "[po4a_langs] #{language.translation_languages_available_str}" - po4a_cfg_arr \ - << "[po4a_paths] #{dir.pot}/$master.pot $lang:#{dir.po}/$lang/$master.po" - doc_import_list.each do |file_src| - file_src_fn= - file_src.gsub(/#{language.source_language_selected_str}\//,'') - po4a_cfg_arr \ - << "[type: text] #{file_src} $lang:$lang/#{file_src_fn}" - end - file=@file.write_file.po4a_cfg - po4a_cfg_arr.each do |txt| - puts txt - file << txt << "\n" - end - file.close - end - end - class Output 0 - para.each do |line| - if line - line=line.gsub(/\s+$/m,''). - gsub(/^\A[ ]*\Z/m,'') - if line=~/^\A[ ]*\Z/m - emptyline+=1 - else emptyline=0 - end - file_pot.puts line if emptyline < 2 #remove extra line spaces (fix upstream) - end - end - else file_pot.puts para #unix plaintext # /^([*=-]|\.){5}/ - end - end - file_pot.close - SiSU_Po4aUtils::PotNumber.new.reset - po4a_git - end - def po4a_git - unless @md.opt.act[:maintenance][:set]==:on - require_relative 'git' # git.rb - git=SiSU_Git::Source.new(@md.opt,@process) - unless FileTest.directory?(@file.output_path.pot_git.dir) - git.create_file_structure_git - end - if @md.opt.f_pth[:lng] == @md.opt.lng_base - FileUtils::cp( - @file.place_file.pot.dir, - @file.output_path.pot_git.dir - ) - else # naive, work on --> - FileUtils::cp( - @file.place_file.po.dir, - @file.output_path.po_git.dir - ) #unless FileTest.file?(@file.place_file.po_git.dir) - end - git.read - end - end - end - end -end -__END__ -!\|#\|&*\|-\|/\|_\|{\|}\|~\|&# - -tables are problematic, difficult to reconstitute instruction, check - -metadata, move to top? and work on - -footnotes, different types, asterisk, also do you want to have separate -paragraphs, or breaks within one block? - -where no ocn appropriately use ~# or -# or indeed 1~name- - -comments in document, what to do about them, not sure they are currently -retained in dal, could be quite valuable to keep - -Translate Shell -http://www.soimort.org/translate-shell/ -translate.google.com diff --git a/lib/sisu/develop/po4a_set.rb b/lib/sisu/develop/po4a_set.rb deleted file mode 100644 index d56175fe..00000000 --- a/lib/sisu/develop/po4a_set.rb +++ /dev/null @@ -1,297 +0,0 @@ -# encoding: utf-8 -=begin - -* Name: SiSU - -** Description: documents, structuring, processing, publishing, search -*** po4a - -** Author: Ralph Amissah - - - -** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah, - All Rights Reserved. - -** License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) Ralph Amissah - - This program is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - this program. If not, see . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - -** SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - -** Hompages: - - - -** Git - - - -=end -module SiSU_Po4aUtils - class Wrap - def initialize(md,orig='',trans='',is_desc='',n_char_max=76,n_indent=0,n_hang=nil) - @md,@orig,@trans,@is_desc,@n_char_max,@n_indent= - md, orig, trans, is_desc, n_char_max, n_indent - @n_char_max_extend = n_char_max - @br="\n" - @n_hang=n_hang ? n_hang : @n_indent - @po4a_identify_type='type: SiSU doc' - #@po4a_identify_type='type: Plain text' - end - def line_wrap - space=' ' - spaces_indent,spaces_hang= - "#{@br}#{space*@n_indent}",space*@n_hang - pot,i=[],0 - pot_array=(@trans.empty?) ? [@orig] : [@orig,@trans] - pot_array.each do |pa| - line=0 - out=[] - out[line]='' - @oldword='' #REMOVE @oldword - pa=pa.gsub(/
/,'
'). - gsub(/#{Mx[:br_nl]}/,"\n\n") - words=pa.scan(/\n\n|\\\\\\|
|\S+/m) - while words != '' - word=words.shift - if not word - out[line] unless out[line].empty? #check - break - elsif word =~/\n\n/ - word="\n" - @n_char_max_extend = @n_char_max + out[line].length - line=line - elsif (out[line].length + word.length) > (@n_char_max_extend - @n_indent) \ - and out[line] =~/\S+/ - @n_char_max_extend = @n_char_max - out[line].squeeze!(' ') - line += 1 - end - if word - out[line]=if out[line] \ - and out[line] !~/\S+$/m - "#{out[line]}#{word}" - elsif out[line] \ - and out[line] =~/\S+/ - "#{out[line]} #{word}" - else "#{word.strip}" - end - end - @oldword=word if word =~/\S+/ - end - x=out.join(spaces_indent).gsub(/\A\n+/m,'').insert(0,spaces_hang) - z=[] - x.split(/\n/).each do |y| - y=y.gsub(/"/,'\"') - y=%{"#{y}"} - z << y - end - pot[i]=z.join("\n") - i +=1 - pot - end - trans=(pot.length == 2) ? pot[1] : '' - po_str=<dc_content}] - else nil - end - end - def header(tag,tag_content,type='',attrib='') #this will break stuff and must be tested thoroughly 20060825 - @tag,@tag_content,@type,@attrib=tag,tag_content,type,attrib - def label #element - @tag - end - def type - @type - end - def text - @tag_content - end - def info #element text - @tag_content - end - def attribute - @attrib - end - def element - @tag - end - def attrib - @attrib - end - def el - @tag - end - self - end - def start_is_match - case @p - when /^#{Mx[:meta_o]}(title)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,@md.title.full,'meta','dc') #dc 1 - when /^#{Mx[:meta_o]}(creator|author)#{Mx[:meta_c]}\s*(.+?)$/ then header('creator',$2,'meta','dc') #dc 2 - when /^#{Mx[:meta_o]}(subject)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 3 - when /^#{Mx[:meta_o]}(description)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 4 - when /^#{Mx[:meta_o]}(publisher)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 5 - when /^#{Mx[:meta_o]}(contributor)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 6 - when /^#{Mx[:meta_o]}(date)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 7 - when /^#{Mx[:meta_o]}(date\.created)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.issued)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.available)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.valid)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.modified)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(type)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 8 - when /^#{Mx[:meta_o]}(format)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 9 - when /^#{Mx[:meta_o]}(identifier)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 10 - when /^#{Mx[:meta_o]}(source)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 11 - when /^#{Mx[:meta_o]}(language)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 12 - when /^#{Mx[:meta_o]}(relation)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 13 - when /^#{Mx[:meta_o]}(coverage)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 14 - when /^#{Mx[:meta_o]}(rights)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 15 - when /^#{Mx[:meta_o]}(keywords)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(copyright)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(translator|translated_by)#{Mx[:meta_c]}\s*(.+?)$/ then header('translator',$2) - when /^#{Mx[:meta_o]}(illustrator|illustrated_by)#{Mx[:meta_c]}\s*(.+?)$/ then header('illustrator',$2) - when /^#{Mx[:meta_o]}(prepared_by)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(digitized_by)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(comments?)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(abstract)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(tags?)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(catalogue)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_loc)#{Mx[:meta_c]}\s*(.+?)$/ then header('classify_loc',$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_dewey)#{Mx[:meta_c]}\s*(.+?)$/ then header('classify_dewey',$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_pg)#{Mx[:meta_c]}\s*(.+?)$/ then header('classify_pg',$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_isbn)#{Mx[:meta_c]}\s*(.+?)$/ then header('classify_isbn',$2,'meta','extra') - when /^#{Mx[:meta_o]}(toc|structure)#{Mx[:meta_c]}\s*(.+?)$/ then header('structure',$2,'process','instruct') - when /^#{Mx[:meta_o]}(level|page|markup)#{Mx[:meta_c]}\s*(.+?)$/ then header('markup',$2,'process','instruct') - when /^#{Mx[:meta_o]}(bold)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(italics|itali[sz]e)#{Mx[:meta_c]}\s*(.+?)$/ then header('italicize',$2,'process','instruct') - when /^#{Mx[:meta_o]}(vocabulary|wordlist)#{Mx[:meta_c]}\s*(.+?)$/ then header('vocabulary',$2,'process','instruct') - when /^#{Mx[:meta_o]}(css|stylesheet)#{Mx[:meta_c]}\s*(.+?)$/ then header('css',$2,'process','instruct') - when /^#{Mx[:meta_o]}(links)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(prefix)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') #add a & b - when /^#{Mx[:meta_o]}(suffix)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(information)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(contact)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(rcs|cvs)#{Mx[:meta_c]}\s*(.+?)$/ then header('version',$2,'process','instruct') - else nil - end - end - def dublin - (@p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/) \ - ? start_is_match - : nil - end - def meta - (@p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/) \ - ? start_is_match - : nil - end - end - class ParagraphNumber - def initialize(paranum) - @paranum=/(\d+)/m.match(paranum)[1] - end - def display - @paranum.gsub(/(\d+)/,'#\1') - end - end - class PotNumber - @@n=0 - def initialize - @@n +=2 - end - def num - @@n - end - def reset - @@n=0 - end - end -end -__END__ diff --git a/lib/sisu/develop/src_po4a_shelf.rb b/lib/sisu/develop/src_po4a_shelf.rb new file mode 100644 index 00000000..dee6818f --- /dev/null +++ b/lib/sisu/develop/src_po4a_shelf.rb @@ -0,0 +1,1217 @@ +# encoding: utf-8 +=begin + +* Name: SiSU + +** Description: documents, structuring, processing, publishing, search +*** pot file generation + +** Author: Ralph Amissah + + + +** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah, + All Rights Reserved. + +** License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + +** SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + +** Hompages: + + + +** Git + + + +=end +module SiSU_Po4a + require_relative 'ao' # ao.rb + require_relative 'se' # se.rb + include SiSU_Env + require_relative 'ao_composite' # ao_composite.rb + require_relative 'shared_metadata' # shared_metadata.rb + require_relative 'src_po4a_shelf_set' # src_po4a_shelf_set.rb + include SiSU_Param + require_relative 'object_munge' # object_munge.rb + require_relative 'utils_composite' # utils_composite.rb + class Source + include SiSU_Object_Munge + @@opt_src,@@opt_trn,@@opt_src_,@@opt_trn_,@@md_src,@@md_trn= + nil, nil, nil, nil, nil, nil + @@auto_translation_ = :go + def initialize(opt,fn=nil) + @opt,@fn=opt,fn + #unless @opt.fns =~/(.+?\.(?:-|ssm\.)?sst)$/ + # puts "#{@opt.fns} not a processed file type" + #end + file_arr=SiSU_Info_Env::InfoEnv.new.source_file_processing_array(@opt.fns) + SiSU_Param::Parameters::Instructions.new(file_arr,@opt).extract + r=Px[:lng_lst_rgx].gsub(/\|en\|/,'|') + @lang_regx=%r{(?:#{r})} + if opt.fns =~/\S+?~#{@lang_regx}\.ss[mti]/ \ + and opt.f_pth[:lng]!=@opt.lng_base + @@opt_src_=false + @@opt_trn=opt + @@md_trn=SiSU_Param::Parameters.new(opt).get + else + @@opt_src_=true + @@opt_src=opt + @@md_src=SiSU_Param::Parameters.new(opt).get + end + end + def wrap_width_set(md,env) + if defined? md.make.plaintext_wrap \ + and md.make.plaintext_wrap + md.make.plaintext_wrap + elsif defined? env.plaintext_wrap \ + and env.plaintext_wrap + env.plaintext_wrap + else 78 + end + end + def process_file(md,env,file,wrap_width,fn) + unless @opt.act[:quiet][:set]==:on + tool=(@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? "#{env.program.text_editor} #{file.output_path.pot.dir}/" + : @opt.fns + (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'Pot po4a', + tool + ).green_hi_blue + : SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'Pot po4a', + tool + ).green_title_hi + if (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + @opt.fns, + file.output_path.pot.dir + ).flow + end + end + if @opt.fns =~/\S+?~#{@lang_regx}\.ss[mti]/ \ + or @opt.f_pth[:lng] !=@opt.lng_base + opt_lang_trn_fn=fn + @ao_arr_lang_trans= + SiSU_AO::Source.new(@opt,opt_lang_trn_fn,:po4a).get # ao file drawn here + opt_lang_src_fn=(fn =~/\S+?~\S{2}(?:_\S{2})?\.ss[mti]/) \ + ? (fn.gsub(/(\S+?)~\S{2}(?:_\S{2})?(\.ss[mti])/,'\1\2')) #check i + : fn + transdir,srcdir=Dir.pwd,Dir.pwd + if Dir.pwd.to_s =~/\/#{@lang_regx}$/ + transdir=Dir.pwd + srcdir=transdir. + gsub(/\/#{@lang_regx}$/, + "/#{@opt.lng_base}") + if FileTest.directory?(srcdir) + Dir.chdir(srcdir) + end + else nil + end + if FileTest.file?("#{srcdir}/#{opt_lang_src_fn}") + @ao_arr_lang_src= + SiSU_AO::Source.new( + @@opt_src, + opt_lang_src_fn, + :po4a + ).get # ao file drawn here + else + puts "no identified source document" + exit + end + Dir.chdir(transdir) if transdir + else + @ao_arr_lang_src= + SiSU_AO::Source.new( + @opt, + fn, + :po4a + ).get # ao file drawn here + @ao_arr_lang_trans=nil + end + SiSU_Po4a::Source::Scroll.new( + fn, + @ao_arr_lang_src, + @ao_arr_lang_trans, + @@md_src, + @@md_trn, + wrap_width + ).songsheet + end + def read + begin + src={} + src[:pth]=@opt.f_pth[:pth] + src[:files]=if @opt.fns =~ /\.(?:(?:-|ssm\.)sst|ssm)$/ + @opt.fns=@opt.fns.gsub(/\.ssm\.sst$/,'.ssm') + SiSU_Assemble::CompositeFileList.new(@opt).read + else + [@opt.fns] + end + md=SiSU_Param::Parameters.new(@opt).get + env=SiSU_Env::InfoEnv.new(@opt.fns) + file=SiSU_Env::FileOp.new(md) + Po4aCfg.new(@opt,file).po4a_cfg + wrap_width=wrap_width_set(md,env) + src[:files].each do |fn| + process_file(md,env,file,wrap_width,fn) + end + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class Scroll 0 \ + and not @@endnotes_ + @pot[:body] << br + wrap_endnotes(notes_s,notes_t) + elsif @@endnotes[:para] \ + and @@endnotes_ + @pot[:body] << br*2 + end + end + def para(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document + util=nil + wrapped=if dob_src.indent =~/[1-9]/ \ + and dob_src.indent == dob_src.hang + s_mark=desc=orig=trans='' + if dob_src.bullet_ + mark="_#{dob_src.indent}* " + d="#{dob_src.is.to_s}: indent #{dob_src.indent}, bullet" + instruct=s_mark='' + if @md.opt.act[:maintenance][:set]==:on + instruct=%{\n# markup for indented bullet text is at the start of the line/object, } \ + + %{an underscore followed by the indent level and an asterisk "#{mark}"} + s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} + end + desc="#{d}#{s_mark}#{instruct}" + else + mark="_#{dob_src.indent} " + d="#{dob_src.is.to_s}: indent #{dob_src.indent}" + instruct=s_mark='' + if @md.opt.act[:maintenance][:set]==:on + instruct=%{\n# markup for indented text is at the start of the line/object, } \ + + %{an underscore followed by the indent level "#{mark}"} + s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} + end + desc="#{d}#{s_mark}#{instruct}" + end + orig="#{s_mark}#{dob_src.obj}" + trans=((dob_trn=='') \ + || (dob_src.obj == dob_trn.obj)) \ + ? '' + : "#{s_mark}#{dob_trn.obj}" + if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ + and trans.empty? \ + and auto_translate? + trans=auto_translation(dob_src.obj,:src) + end + util=pot_structure_wrap(desc,orig,trans) + elsif dob_src.hang =~/[0-9]/ \ + and dob_src.indent != dob_src.hang + s_mark=desc=orig=trans='' + mark="_#{dob_src.hang}_#{dob_src.indent} " + d="#{dob_src.is.to_s}: hang #{dob_src.hang} indent #{dob_src.indent}" + instruct=s_mark='' + if @md.opt.act[:maintenance][:set]==:on + instruct=%{\n# markup for indented text with a first line indented } \ + + %{to a different level from the rest of the paragraph, } \ + + %{is at the start of the line/object, } \ + + %{an underscore and the first indent level } \ + + %{a second underscore and the indent level for the rest of the paragraph, "#{mark1}"} + s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} + end + desc="#{d}#{s_mark}#{instruct}" + orig="#{s_mark}#{dob_src.obj}" + trans=((dob_trn=='') \ + || (dob_src.obj == dob_trn.obj)) \ + ? '' + : "#{s_mark}#{dob_trn.obj}" + if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ + and trans.empty? \ + and auto_translate? + trans=auto_translation(dob_src.obj,:src) + end + util=pot_structure_wrap(desc,orig,trans) + else + s_mark=desc=orig=trans='' + if dob_src.bullet_ + mark='_* ' + d="#{dob_src.is.to_s}: bullet" + instruct=s_mark='' + if @md.opt.act[:maintenance][:set]==:on + instruct=%{\n# markup for indented text is at the start of the line/object, } \ + + %{an underscore followed by an asterisk "#{mark}"} + s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} + end + desc="#{d}#{s_mark}#{instruct}" + orig="#{s_mark}#{dob_src.obj}" + trans=((dob_trn=='') \ + || (dob_src.obj == dob_trn.obj)) \ + ? '' + : "#{s_mark}#{dob_trn.obj}" + if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ + and trans.empty? \ + and auto_translate? + trans=auto_translation(dob_src.obj,:src) + end + else + mark='' + d=dob_src.is.to_s + instruct=%{\n# regular paragraph, no special markup} + if @md.opt.act[:maintenance][:set]==:on + instruct="\n# " + s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"} + end + desc="#{d}#{s_mark}#{instruct}" + orig=dob_src.obj + trans=((dob_trn=='') \ + || (dob_src.obj == dob_trn.obj)) \ + ? '' + : "#{s_mark}#{dob_trn.obj}" + if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ + and trans.empty? \ + and auto_translate? + trans=auto_translation(dob_src.obj,:src) + end + end + util=pot_structure_wrap(desc,orig,trans) + end + wrapped=util.line_wrap + @pot[:body] << wrapped << br # main text, contents, body KEEP + if @@endnotes[:para] \ + and notes_s.length > 0 \ + and not @@endnotes_ + @pot[:body] << br + wrap_endnotes(notes_s,notes_t) + elsif @@endnotes[:para] \ + and @@endnotes_ + @pot[:body] << br*2 + end + end + def block(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document + mark="block{\\n\\n...\\n\\n}block" + d=dob_src.is.to_s + instruct=s_mark='' + if @md.opt.act[:maintenance][:set]==:on + instruct=%{\n# block text is a text block with an opening and closing marker, } \ + + %{the content of which may be wrapped} + s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} + end + desc="#{d}#{s_mark}#{instruct}" + orig=dob_src.obj + trans=((dob_trn=='') \ + || (dob_src.obj == dob_trn.obj)) \ + ? '' + : "#{s_mark}#{dob_trn.obj}" + if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ + and trans.empty? \ + and auto_translate? + trans=auto_translation(dob_src.obj,:src) + end + util=pot_structure_wrap(desc,orig,trans) + unwrapped=util.no_line_wrap_block + @pot[:body] << unwrapped << br + end + def group(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document + mark="group{\\n\\n...\\n\\n}group" + d=dob_src.is.to_s + instruct=s_mark='' + if @md.opt.act[:maintenance][:set]==:on + instruct=%{\n# group text is a text block with an opening and closing marker, } \ + + %{the content of which may be wrapped} + s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} + end + desc="#{d}#{s_mark}#{instruct}" + orig=dob_src.obj + trans=((dob_trn=='') \ + || (dob_src.obj == dob_trn.obj)) \ + ? '' + : "#{s_mark}#{dob_trn.obj}" + if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \ + and trans.empty? \ + and auto_translate? + trans=auto_translation(dob_src.obj,:src) + end + util=pot_structure_wrap(desc,orig,trans) + unwrapped=util.no_line_wrap_block + @pot[:body] << unwrapped << br + end + def verse(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document + mark="poem{\n\nverse\n\nverse\n\n...\n\n}poem" + d=dob_src.is.to_s + instruct=s_mark='' + if @md.opt.act[:maintenance][:set]==:on + instruct=%{\n# verse are part of the text block described as a poem, } \ + + %{the first verse is preceeded by an opening marker, } \ + + %{and the last verse by a closing marker, } \ + + %{the content of which should remain unwrapped} + s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} + end + desc="#{d}#{s_mark}#{instruct}" + orig=dob_src.obj + trans=(dob_trn=='') ? '' : dob_trn.obj + util=pot_structure_wrap(desc,orig,trans) + unwrapped=util.no_line_wrap_block + @pot[:body] << unwrapped << br + end + def code(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document + mark="code{\\n\\n...\\n\\n}code" + d=dob_src.is.to_s + instruct=s_mark='' + if @md.opt.act[:maintenance][:set]==:on + instruct=%{\n# codeblocks are a text block with an opening and closing marker, } \ + + %{the content of which should remain unwrapped} + s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} + end + desc="#{d}#{s_mark}#{instruct}" + orig=dob_src.obj + trans=(dob_trn=='') ? '' : dob_trn.obj + util=pot_structure_wrap(desc,orig,trans) + unwrapped=util.no_line_wrap_block + @pot[:body] << unwrapped << br + end + def table(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document + mark="table{\\n\\n...\\n\\n}table" + d=dob_src.is.to_s + instruct=s_mark='' + if @md.opt.act[:maintenance][:set]==:on + instruct=%{\n# tables are a text block with an opening and closing marker, } \ + + %{the content of which should remain unwrapped} + s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"} + end + desc="#{d}#{s_mark}#{instruct}" + orig=dob_src.obj + orig=orig.gsub(/#{Mx[:tc_c]}/,"\n") + trans=(dob_trn=='') ? '' : dob_trn.obj + trans=trans.gsub(/#{Mx[:tc_c]}/,"\n") + util=pot_structure_wrap(desc,orig,trans) + unwrapped=util.no_line_wrap_block + @pot[:body] << unwrapped << br + end + def idx_markup(idx) + struct=['={'] + idx.sort.each do |x| + x.each_with_index do |y,i0| + case y + when String + struct << ';' unless struct[-1] =~/=\{/ + struct << y + if x[i0+1].class == Hash \ + and x[i0+1][:sub].length > 0 + struct << ':' + end + when Hash + if y[:plus].to_i > 0 + struct << '+' + y[:plus].to_s + end + if y[:sub].length > 0 + y[:sub].each_with_index do |z,i1| + z.each_with_index do |a,i2| + #p a + if z.length > 0 + struct << a[0] + if a[1][:plus].to_i > 0 + struct << '+' + a[1][:plus].to_s + end + if (i1 + 1) < y[:sub].length + struct << '|' + end + end + end + end + end + end + end + end + struct << '}' + #puts struct.join + struct.join + end + def idx(dob_src='',dob_trn='') #% used for book index but broken as original markup lost, already abstracted, fix + mark="={ ... }" + instruct=s_mark='' + if @md.opt.act[:maintenance][:set]==:on + instruct=%{\n# the book index should be attached unwrapped to the preceding text block } \ + + %{(there should be a new line, but no empty line)} + s_mark="\n# " + %{"\\n#{mark}\\n\\n"} + end + d='book-idx' + desc="#{d}#{s_mark}#{instruct}" + orig=pot_structure.idx_markup(dob_src.idx) #'={' + dob_src.idx + '}' + trans=if defined? dob_trn.idx \ + and not dob_trn.idx.nil? \ + and not dob_trn.idx.empty? + pot_structure.idx_markup(dob_trn.idx) #'={' + dob_trn.idx + '}' + else '' + end + util=pot_structure_wrap(desc,orig,trans) + unwrapped=util.no_line_wrap_block + @pot[:body] << unwrapped << br + end + self + end + def pot_markup(data_src,data_trn) + #@endnotes,@copen,@pot_contents_close=Array.new(3){[]} + a_l=if data_trn + a_l=(data_src.length >= data_trn.length) \ + ? data_src.length + : data_trn.length + else + data_src.length + end + s,t=0,0 + if @md.fns =~ /\.(?:(?:-|ssm\.)?sst|ssm)$/ + (data_trn.nil?) \ + ? pot_metadata_src + : pot_metadata_src_trn + end + 0.upto(a_l-1) do |i| + if data_trn + unless data_src[s] \ + and data_trn[t] + break + end + if data_src[s].of == :comment \ + and data_trn[t].of == :comment \ + and (data_src[s].is == data_trn[t].is) + s+=1;t+=1 + next + end + if ((data_src[s].is == :comment) \ + || (data_trn[t].is == :comment)) \ + and (data_src[s].is != data_trn[t].is) + if data_src[s].is == :comment + if @md.opt.act[:maintenance][:set]==:on + puts "src (comment):\n\t" \ + + data_src[s].obj + end + s+=1 + #next if data_src[s].is == :comment + elsif data_trn[t].is == :comment + if @md.opt.act[:maintenance][:set]==:on + puts "trans (comment):\n\t" \ + + data_trn[t].obj + end + t+=1 + #next if data_trn[t].is == :comment + end + end + if ((defined? data_src[s].ocn) \ + && (data_src[s].ocn.is_a?(Fixnum))) \ + and ((defined? data_trn[t].ocn) \ + && (data_trn[t].ocn.is_a?(Fixnum))) \ + and (data_src[s].ocn == data_trn[t].ocn) + @m_s,@m_t=s,t + elsif ((defined? data_src[s].ocn) \ + && (data_src[s].ocn.is_a?(Fixnum))) \ + and ((defined? data_trn[t].ocn) \ + && (data_trn[t].ocn.is_a?(Fixnum))) \ + and (data_src[s].ocn != data_trn[t].ocn) + p '--- OCN ---' + p 'mis-match' + p data_src[s].ocn + p data_src[s].obj + p data_trn[t].ocn + p data_trn[t].obj + p '---' + p 'previous match' + p data_src[@m_s].ocn + p data_src[@m_s].obj + p data_trn[@m_t].ocn + p data_trn[@m_t].obj + exit + elsif (((defined? data_src[s].ocn) \ + && (defined? data_trn[t].ocn)) \ + and data_src[s].ocn.class != data_trn[t].ocn.class) + p '--- OCN class ---' + p 'mis-match' + p data_src[s].ocn if defined? data_src[s].ocn + p data_src[s].obj + p data_trn[t].ocn if defined? data_trn[t].ocn + p data_trn[t].obj + #p '---' + #p 'previous match' + #p data_src[@m_s].ocn + #p data_src[@m_s].obj + #p data_trn[@m_t].ocn + #p data_trn[@m_t].obj + #elsif (defined? data_src[s].ocn != defined? data_trn[t].ocn) \ + #and (data_src[s].ocn.nil? != data_trn[t].ocn.nil?) + # p '--- missing OCN? ---' + # p 'mis-match' + # p data_src[s].ocn if defined? data_src[s].ocn + # p data_src[s].obj + # p data_trn[t].ocn if defined? data_trn[t].ocn + # p data_trn[t].obj + else + end + end + notes_s,notes_t='','' + data_src[s],notes_s=markup(data_src[s]) + if data_trn + data_trn[t],notes_t=markup(data_trn[t]) + #data_src[s],data_trn[t]=pot_data(data_src[s],notes_s,data_trn[t],notes_t) + pot_data(data_src[s],notes_s,data_trn[t],notes_t) + else + #data_src[s],nul=pot_data(data_src[s],notes_s) + pot_data(data_src[s],notes_s) + end + s+=1;t+=1 + end + @pot #watch + end + def pot_data(dob_src='',notes_s='',dob_trn='',notes_t='') + if dob_src.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + if defined? dob_src.ocn \ + and dob_src.ocn.to_s =~/\d+/ + paranum=dob_src.ocn.to_s + @p_num=SiSU_Po4aUtils::ParagraphNumber.new(paranum) + end + case dob_src.is + when :heading + pot_structure.heading(dob_src,notes_s,dob_trn,notes_t) + when :para + pot_structure.para(dob_src,notes_s,dob_trn,notes_t) + when :group + pot_structure.group(dob_src,notes_s,dob_trn,notes_t) + when :block + pot_structure.block(dob_src,notes_s,dob_trn,notes_t) + when :verse + pot_structure.verse(dob_src,notes_s,dob_trn,notes_t) + when :code + pot_structure.code(dob_src,notes_s,dob_trn,notes_t) + when :table + pot_structure.table(dob_src,notes_s,dob_trn,notes_t) + end + if defined? dob_src.idx \ + and not dob_src.idx.nil? \ + and not dob_src.idx.empty? + pot_structure.idx(dob_src,dob_trn) + end + dob_src='' if (dob_src.obj =~/
/ \ + and dob_src.obj =~/^(-\{{2}~\d+|)/) # -endnote + if dob_src ## Clean Prepared Text + dob_src.obj=dob_src.obj.gsub(//,' '). + gsub(/<:\S+>/,' ') if dob_src ## Clean Prepared Text + end + end + #[dob_src,dob_trn] + end + def markup(dob) + dob,notes=objects.textface_marks_po4a(dob,:separate) + [dob,notes] + end + def publish(fn,pot) + content=[] + content << pot[:open] + content << pot[:head] + content << pot[:metadata] + content << pot[:body] + content << @@endnotes[:end] if @@endnotes_ + Output.new(fn,content,@md,@process).po4a + @@endnotes={ para: [], end: [] } + end + end + class Po4aCfg + include SiSU_Composite_Doc_Utils # composite doc, .ssm, extract all related insert files, array of filenames test + def initialize(opt,file) + @opt,@file=opt,file + end + def po4a_cfg_filename + 'po4a.cfg' + end + def dir + def pwd + Dir.pwd + end + def po4a_ + 'po4a/' # '' + end + def pot + po4a_ + 'pot' + end + def po + po4a_ + 'po' + end + self + end + def po4a_cfg_file + File.open("#{Dir.pwd}/#{po4a_cfg_filename}",'w') + end + def language + def sisu_languages_available + Px[:lng_lst] + end + def translation_languages_selected + @opt.act[:po4a_lang_trans][:trn] \ + ? @opt.act[:po4a_lang_trans][:trn] + : [] + end + def translation_languages_selected_that_are_available + translation_languages_selected & sisu_languages_available + end + def source_language_selected_str + @opt.act[:po4a_lang_trans][:src] \ + ? @opt.act[:po4a_lang_trans][:src] + : 'en' + end + def translation_languages_selected_that_are_available_str + translation_languages_selected_that_are_available.join(' ') + end + def translation_languages_selected_str + @opt.act[:po4a_lang_trans][:trn].join(' ') + end + self + end + def po4a_cfg + doc_import_list=composite_and_imported_filenames_array(@opt.fno) + po4a_cfg_arr=[] + po4a_cfg_arr \ + << "[po4a_langs] #{language.translation_languages_selected_that_are_available_str}" + po4a_cfg_arr \ + << "[po4a_paths] #{dir.pot}/$master.pot $lang:#{dir.po}/$lang/$master.po" + doc_import_list.each do |file_src| + file_src_fn= + file_src.gsub(/#{language.source_language_selected_str}\//,'') + po4a_cfg_arr \ + << "[type: text] #{file_src} $lang:$lang/#{file_src_fn}" + end + file=@file.write_file.po4a_cfg + po4a_cfg_arr.each do |txt| + puts txt + file << txt << "\n" + end + file.close + end + end + class Output 0 + para.each do |line| + if line + line=line.gsub(/\s+$/m,''). + gsub(/^\A[ ]*\Z/m,'') + if line=~/^\A[ ]*\Z/m + emptyline+=1 + else emptyline=0 + end + file_pot.puts line if emptyline < 2 #remove extra line spaces (fix upstream) + end + end + else file_pot.puts para #unix plaintext # /^([*=-]|\.){5}/ + end + end + file_pot.close + SiSU_Po4aUtils::PotNumber.new.reset + po4a_git + end + def po4a_git + unless @md.opt.act[:maintenance][:set]==:on + require_relative 'git' # git.rb + git=SiSU_Git::Source.new(@md.opt,@process) + unless FileTest.directory?(@file.output_path.pot_git.dir) + git.create_file_structure_git + end + if @md.opt.f_pth[:lng] == @md.opt.lng_base + FileUtils::cp( + @file.place_file.pot.dir, + @file.output_path.pot_git.dir + ) + else # naive, work on --> + FileUtils::cp( + @file.place_file.po.dir, + @file.output_path.po_git.dir + ) #unless FileTest.file?(@file.place_file.po_git.dir) + end + git.read + end + end + end + end +end +__END__ +!\|#\|&*\|-\|/\|_\|{\|}\|~\|&# + +tables are problematic, difficult to reconstitute instruction, check + +metadata, move to top? and work on + +footnotes, different types, asterisk, also do you want to have separate +paragraphs, or breaks within one block? + +where no ocn appropriately use ~# or -# or indeed 1~name- + +comments in document, what to do about them, not sure they are currently +retained in dal, could be quite valuable to keep + +Translate Shell +http://www.soimort.org/translate-shell/ +translate.google.com diff --git a/lib/sisu/develop/src_po4a_shelf_set.rb b/lib/sisu/develop/src_po4a_shelf_set.rb new file mode 100644 index 00000000..a281060d --- /dev/null +++ b/lib/sisu/develop/src_po4a_shelf_set.rb @@ -0,0 +1,297 @@ +# encoding: utf-8 +=begin + +* Name: SiSU + +** Description: documents, structuring, processing, publishing, search +*** po4a + +** Author: Ralph Amissah + + + +** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah, + All Rights Reserved. + +** License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + +** SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + +** Hompages: + + + +** Git + + + +=end +module SiSU_Po4aUtils + class Wrap + def initialize(md,orig='',trans='',is_desc='',n_char_max=76,n_indent=0,n_hang=nil) + @md,@orig,@trans,@is_desc,@n_char_max,@n_indent= + md, orig, trans, is_desc, n_char_max, n_indent + @n_char_max_extend = n_char_max + @br="\n" + @n_hang=n_hang ? n_hang : @n_indent + @po4a_identify_type='type: SiSU doc' + #@po4a_identify_type='type: Plain text' + end + def line_wrap + space=' ' + spaces_indent,spaces_hang= + "#{@br}#{space*@n_indent}",space*@n_hang + pot,i=[],0 + pot_array=(@trans.empty?) ? [@orig] : [@orig,@trans] + pot_array.each do |pa| + line=0 + out=[] + out[line]='' + @oldword='' #REMOVE @oldword + pa=pa.gsub(/
/,'
'). + gsub(/#{Mx[:br_nl]}/,"\n\n") + words=pa.scan(/\n\n|\\\\\\|
|\S+/m) + while words != '' + word=words.shift + if not word + out[line] unless out[line].empty? #check + break + elsif word =~/\n\n/ + word="\n" + @n_char_max_extend = @n_char_max + out[line].length + line=line + elsif (out[line].length + word.length) > (@n_char_max_extend - @n_indent) \ + and out[line] =~/\S+/ + @n_char_max_extend = @n_char_max + out[line].squeeze!(' ') + line += 1 + end + if word + out[line]=if out[line] \ + and out[line] !~/\S+$/m + "#{out[line]}#{word}" + elsif out[line] \ + and out[line] =~/\S+/ + "#{out[line]} #{word}" + else "#{word.strip}" + end + end + @oldword=word if word =~/\S+/ + end + x=out.join(spaces_indent).gsub(/\A\n+/m,'').insert(0,spaces_hang) + z=[] + x.split(/\n/).each do |y| + y=y.gsub(/"/,'\"') + y=%{"#{y}"} + z << y + end + pot[i]=z.join("\n") + i +=1 + pot + end + trans=(pot.length == 2) ? pot[1] : '' + po_str=<dc_content}] + else nil + end + end + def header(tag,tag_content,type='',attrib='') #this will break stuff and must be tested thoroughly 20060825 + @tag,@tag_content,@type,@attrib=tag,tag_content,type,attrib + def label #element + @tag + end + def type + @type + end + def text + @tag_content + end + def info #element text + @tag_content + end + def attribute + @attrib + end + def element + @tag + end + def attrib + @attrib + end + def el + @tag + end + self + end + def start_is_match + case @p + when /^#{Mx[:meta_o]}(title)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,@md.title.full,'meta','dc') #dc 1 + when /^#{Mx[:meta_o]}(creator|author)#{Mx[:meta_c]}\s*(.+?)$/ then header('creator',$2,'meta','dc') #dc 2 + when /^#{Mx[:meta_o]}(subject)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 3 + when /^#{Mx[:meta_o]}(description)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 4 + when /^#{Mx[:meta_o]}(publisher)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 5 + when /^#{Mx[:meta_o]}(contributor)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 6 + when /^#{Mx[:meta_o]}(date)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 7 + when /^#{Mx[:meta_o]}(date\.created)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.issued)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.available)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.valid)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.modified)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(type)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 8 + when /^#{Mx[:meta_o]}(format)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 9 + when /^#{Mx[:meta_o]}(identifier)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 10 + when /^#{Mx[:meta_o]}(source)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 11 + when /^#{Mx[:meta_o]}(language)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 12 + when /^#{Mx[:meta_o]}(relation)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 13 + when /^#{Mx[:meta_o]}(coverage)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 14 + when /^#{Mx[:meta_o]}(rights)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','dc') #dc 15 + when /^#{Mx[:meta_o]}(keywords)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(copyright)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(translator|translated_by)#{Mx[:meta_c]}\s*(.+?)$/ then header('translator',$2) + when /^#{Mx[:meta_o]}(illustrator|illustrated_by)#{Mx[:meta_c]}\s*(.+?)$/ then header('illustrator',$2) + when /^#{Mx[:meta_o]}(prepared_by)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(digitized_by)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(comments?)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(abstract)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(tags?)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(catalogue)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_loc)#{Mx[:meta_c]}\s*(.+?)$/ then header('classify_loc',$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_dewey)#{Mx[:meta_c]}\s*(.+?)$/ then header('classify_dewey',$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_pg)#{Mx[:meta_c]}\s*(.+?)$/ then header('classify_pg',$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_isbn)#{Mx[:meta_c]}\s*(.+?)$/ then header('classify_isbn',$2,'meta','extra') + when /^#{Mx[:meta_o]}(toc|structure)#{Mx[:meta_c]}\s*(.+?)$/ then header('structure',$2,'process','instruct') + when /^#{Mx[:meta_o]}(level|page|markup)#{Mx[:meta_c]}\s*(.+?)$/ then header('markup',$2,'process','instruct') + when /^#{Mx[:meta_o]}(bold)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(italics|itali[sz]e)#{Mx[:meta_c]}\s*(.+?)$/ then header('italicize',$2,'process','instruct') + when /^#{Mx[:meta_o]}(vocabulary|wordlist)#{Mx[:meta_c]}\s*(.+?)$/ then header('vocabulary',$2,'process','instruct') + when /^#{Mx[:meta_o]}(css|stylesheet)#{Mx[:meta_c]}\s*(.+?)$/ then header('css',$2,'process','instruct') + when /^#{Mx[:meta_o]}(links)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(prefix)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') #add a & b + when /^#{Mx[:meta_o]}(suffix)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(information)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(contact)#{Mx[:meta_c]}\s*(.+?)$/ then header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(rcs|cvs)#{Mx[:meta_c]}\s*(.+?)$/ then header('version',$2,'process','instruct') + else nil + end + end + def dublin + (@p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/) \ + ? start_is_match + : nil + end + def meta + (@p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/) \ + ? start_is_match + : nil + end + end + class ParagraphNumber + def initialize(paranum) + @paranum=/(\d+)/m.match(paranum)[1] + end + def display + @paranum.gsub(/(\d+)/,'#\1') + end + end + class PotNumber + @@n=0 + def initialize + @@n +=2 + end + def num + @@n + end + def reset + @@n=0 + end + end +end +__END__ -- cgit v1.2.3