aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/src.org
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2021-04-02 19:37:00 -0400
committerRalph Amissah <ralph.amissah@gmail.com>2021-04-02 20:03:27 -0400
commit90051a7ea55acb043434b1c2483b878d602246ba (patch)
tree9e803c11a0ac4e37023b3c79f19f5b372d4175ee /org/src.org
parentnix ruby 3.0 (available) (diff)
org mode (ruby code within)
Diffstat (limited to 'org/src.org')
-rw-r--r--org/src.org3437
1 files changed, 3437 insertions, 0 deletions
diff --git a/org/src.org b/org/src.org
new file mode 100644
index 00000000..cb74f8bb
--- /dev/null
+++ b/org/src.org
@@ -0,0 +1,3437 @@
+-*- mode: org -*-
+#+TITLE: sisu src
+#+DESCRIPTION: documents - structuring, various output representations & search
+#+FILETAGS: :sisu:src:
+#+AUTHOR: Ralph Amissah
+#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]]
+#+COPYRIGHT: Copyright (C) 2015 - 2021 Ralph Amissah
+#+LANGUAGE: en
+#+STARTUP: content hideblocks hidestars noindent entitiespretty
+#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t
+#+PROPERTY: header-args :exports code
+#+PROPERTY: header-args+ :noweb yes
+#+PROPERTY: header-args+ :eval no
+#+PROPERTY: header-args+ :results no
+#+PROPERTY: header-args+ :cache no
+#+PROPERTY: header-args+ :padline no
+
+* src_sisupod_make.rb
+
+#+BEGIN_SRC ruby :tangle "../lib/sisu/src_sisupod_make.rb"
+# <<sisu_document_header>>
+module SiSU_Doc
+ require_relative 'src_shared' # scr_shared.rb
+ include SiSU_Source
+ require_relative 'se' # se.rb
+ include SiSU_Env
+ class Source < SiSU_Source::SiSUpodSource
+ require_relative 'utils_response' # utils_response.rb
+ def initialize(opt,build=nil,place=nil)
+ super(opt,build,place)
+ @zipfile=@opt.fno.gsub(/(?:\~\S{2,3})?(\.ss[tm])$/,'\1')
+ unless @opt.act[:quiet][:set]==:on
+ pthinfo="#{@file.output_path.sisupod.dir}/#{@zipfile}.txz"
+ (@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],
+ 'Assemble source for sisu document',
+ "#{@opt.fns} -> file://#{pthinfo}"
+ ).cyan_hi_blue
+ : SiSU_Screen::Ansi.new(
+ @opt.act[:color_state][:set],
+ 'Assemble source for sisu document',
+ pthinfo
+ ).cyan_title_hi
+ end
+ end
+ def sisupod_tar_xz
+ begin
+ FileUtils::mkdir_p(@file.output_path.sisupod.dir) \
+ unless FileTest.directory?(@file.output_path.sisupod.dir)
+ tree=((@opt.act[:verbose][:set]==:on \
+ || @opt.act[:verbose_plus][:set]==:on \
+ || @opt.act[:maintenance][:set]==:on) \
+ && SiSU_Env::SystemCall.new.program_found?('tree')) \
+ ? 'tree sisupod'
+ : ''
+ if FileTest.directory?(@path_pod[:fnb])
+ Dir.chdir(@path_pod[:fnb])
+ system(%{
+ #{tree}
+ tar -cJf #{@zipfile}.txz sisupod
+ #echo "#{@file.place_file.sisupod.dir}"
+ })
+ FileUtils::mv("#{@zipfile}.txz",@file.place_file.sisupod.dir)
+ Dir.chdir(@env.path.pwd)
+ if (@opt.act[:verbose][:set]==:on \
+ || @opt.act[:verbose_plus][:set]==:on \
+ || @opt.act[:maintenance][:set]==:on)
+ SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz").blue_tab
+ end
+ else
+ if (@opt.act[:verbose][:set]==:on \
+ || @opt.act[:verbose_plus][:set]==:on \
+ || @opt.act[:maintenance][:set]==:on)
+ SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz not built").blue_tab
+ end
+ end
+ rescue
+ ensure
+ end
+ end
+ end
+end
+__END__
+question?: should you permit the packing of multiple documents in single .xz ?
+
+ open @opt.fns, parse file
+ extract from file content:
+ images and copy each image from whatever image source to _sisu/sisupod/sisu/_sisu/image
+
+ remove previously existing contents of _/sisu/sisupod &
+ make directory structure:
+
+v3 -->
+ _sisu
+ sisupod
+ doc
+ manifest.txt
+ en/content.sst [file content]
+ fr/content.sst
+ _sisu
+ conf
+ image (ln -s ../../image)
+ audio (ln -s ../../audio)
+ video (ln -s ../../video)
+ image [all images for specific document gathered here]
+ audio
+ video
+
+v2 -->
+ _sisu
+ sisupod
+ content.sst [file content]
+ filename.sst [link to content.sst]
+ _sisu/
+ image/ [all images for specific document gathered here]
+
+sisu
+ _sisu
+ sisurc.yml
+ convert/
+ standard_terms/
+ image
+ processing
+ ao/
+ tex/
+ texinfo/
+ tune/
+ sisupod
+
+special case
+
+composite file (master), e.g.
+SiSU.ssm
+#+END_SRC
+
+* src_sisupod_sstm.rb
+
+#+BEGIN_SRC ruby :tangle "../lib/sisu/src_sisupod_sstm.rb"
+# <<sisu_document_header>>
+module SiSU_Markup
+ require_relative 'src_shared' # src_shared.rb
+ include SiSU_Source
+ require_relative 'se' # se.rb
+ include SiSU_Env
+ class Source_Sisupod < SiSU_Source::SiSUpodSource
+ def initialize(opt,build=nil,place=nil)
+ super(opt,build,place)
+ @opt=opt
+ end
+ def read
+ unless @opt.act[:quiet][:set]==:on
+ (@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],
+ 'Share document markup text source',
+ @opt.fns
+ ).cyan_hi_blue
+ : SiSU_Screen::Ansi.new(
+ @opt.act[:color_state][:set],
+ 'Share document markup text source',
+ @opt.fns
+ ).cyan_title_hi
+ end
+ if FileTest.directory?(@path_pod[:fnb])
+ FileUtils::mkdir_p(@file.output_path.src.dir) \
+ unless FileTest.directory?(@file.output_path.src.dir)
+ v=(@opt.act[:maintenance][:set]==:on) \
+ ? 'v' : ''
+ system(%{
+ rsync -a#{v} #{@path_pod[:fnb]} #{@file.output_path.sisupod.dir}
+ chbk=`pwd`
+ cd #{@file.output_path.sisupod.dir}
+ for I in `find -type d` ; do chmod 755 $I ; done
+ for I in `find -type f` ; do chmod 644 $I ; done
+ cd ${chbk}
+ })
+ else
+ if (@opt.act[:verbose][:set]==:on \
+ || @opt.act[:verbose_plus][:set]==:on \
+ || @opt.act[:maintenance][:set]==:on)
+ SiSU_Screen::Ansi.new(
+ '',
+ "#{@opt.fno} not available"
+ ).blue_tab
+ end
+ end
+ end
+ end
+end
+__END__
+#+END_SRC
+
+* src_kdissert_share.rb
+
+#+BEGIN_SRC ruby :tangle "../lib/sisu/src_kdissert_share.rb"
+# <<sisu_document_header>>
+module SiSU_KdiSource
+ require_relative 'se' # se.rb
+ include SiSU_Env
+ class Source
+ begin
+ require 'fileutils'
+ include FileUtils
+ rescue LoadError
+ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
+ error('fileutils NOT FOUND (LoadError)')
+ end
+ def initialize(opt)
+ @opt=opt
+ @env=SiSU_Env::InfoEnv.new(@opt.fns)
+ @output_path="#{@env.path.output}/#{@opt.fnb}"
+ end
+ def read
+ SiSU_Screen::Ansi.new(
+ @opt.act[:color_state][:set],
+ 'Share Kdissert Source Document!',
+ @opt.fnb
+ ).green_hi_blue unless @opt.act[:quiet][:set]==:on
+ SiSU_Screen::Ansi.new(
+ @opt.act[:color_state][:set],
+ "Copy kdissert file to output directory",
+ "#{@opt.fnb} -> #{@output_path}"
+ ).warn unless @opt.act[:quiet][:set]==:on
+ FileUtils::mkdir_p(@env.path.output) unless FileTest.directory?(@env.path.output)
+ FileUtils::mkdir_p(@output_path) unless FileTest.directory?(@output_path)
+ if FileTest.directory?(@output_path)
+ if @opt.fns =~/\.kdi\._sst$/ \
+ and FileTest.file?(@opt.fnb)
+ FileUtils::cp(@opt.fnb,@output_path)
+ end
+ else
+ SiSU_Screen::Ansi.new(
+ @opt.act[:color_state][:set],
+ "Output directory does not exist",
+ "#{@opt.fnb} -> #{@output_path}"
+ ).warn unless @opt.act[:quiet][:set]==:on
+ exit
+ end
+ end
+ end
+end
+__END__
+#+END_SRC
+
+* src_po4a_share.rb
+
+#+BEGIN_SRC ruby :tangle "../lib/sisu/src_po4a_share.rb"
+# <<sisu_document_header>>
+module SiSU_Languages_Selected
+ require_relative 'utils_response' # utils_response.rb
+ def language
+ def sisu_languages_available
+ Px[:lng_lst]
+ end
+ def source_language_selected_str
+ @opt.act[:po4a_lang][:src] \
+ ? @opt.act[:po4a_lang][:src]
+ : 'en'
+ end
+ def translation_languages_selected
+ @opt.act[:po4a_lang][:trn] \
+ ? @opt.act[:po4a_lang][:trn]
+ : []
+ end
+ def translation_languages_available
+ sisu_languages_available - [source_language_selected_str]
+ end
+ def translation_languages_selected_that_are_available
+ translation_languages_selected & sisu_languages_available
+ 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][:trn].join(' ')
+ end
+ self
+ end
+end
+module SiSU_Po4a_Project
+ class Po4aCfg
+ include SiSU_Composite_Doc_Utils # composite doc, .ssm, extract all related insert files, array of filenames test
+ include SiSU_Response
+ include SiSU_Languages_Selected
+ def initialize(opt,file)
+ @opt,@file=opt,file
+ end
+ def song
+ if @opt.lng==language.source_language_selected_str
+ ans=response?('po4a config file')
+ if ans
+ po4a_cfg
+ end
+ end
+ end
+ def po4a_cfg_filename
+ 'po4a.cfg'
+ end
+ def dir
+ def pwd
+ Dir.pwd
+ end
+ def po4a_
+ 'po4a/' # ''
+ end
+ def pot
+ #po4a_ + 'pot'
+ 'pot'
+ end
+ def po
+ #po4a_ + 'po'
+ 'po'
+ end
+ self
+ end
+ def po4a_cfg_file
+ File.open("#{Dir.pwd}/#{po4a_cfg_filename}",'w')
+ end
+ def po4a_cfg
+ lng=language.source_language_selected_str
+ 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] #{lng}/#{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 Po4aProject
+ include SiSU_Languages_Selected
+ include SiSU_Response
+ def initialize(opt,file)
+ @opt,@file=opt,file
+ end
+ def song
+ make_paths
+ if FileTest.directory?(@file.output_path.po4a.dir)
+ Dir.chdir(@file.output_path.po4a.dir)
+ dirs=Dir['*/']
+ dirs_language=[]
+ dirs.each do |x|
+ dirs_language << x.gsub(/\/$/,'')
+ end
+ dirs_translation = \
+ (language.translation_languages_available & dirs_language)
+ end
+ if (language.translation_languages_available & [@opt.lng]).length == 1
+ puts %{gettext for: #{dirs_translation}
+in #{Dir.pwd}}
+ ans=response?('gettext?')
+ if ans
+ gettext_if_any_build_src_trans_po
+ end
+ end
+ ans=response?('build project?')
+ if ans
+ build_src_master_to_pot_and_po_and_srcs
+ end
+ end
+ def flags
+ def debug
+ '-d -v'
+ end
+ def normal
+ ''
+ end
+ def quiet
+ '-q'
+ end
+ self
+ end
+ def build_src_master_to_pot_and_po_and_srcs
+ if SiSU_Sys_Call::SystemCall.new.po4a
+ pwd=Dir.pwd
+ #cmd='po4a --keep 0 -M UTF-8 --no-backups ' \
+ #+ '--package-name ' \
+ #+ 'sisu-manual' + ' ' \
+ #+ flags.normal + ' ' \
+ #+ filename.po4a_cfg
+ cmd='po4a --keep 0 -M UTF-8' \
+ + flags.normal + ' ' \
+ + @file.base_filename.po4a_cfg
+ Dir.chdir(@file.output_path.po4a.dir)
+ system("
+ cd #{@file.output_path.po4a.dir}
+ #{cmd}
+ cd -
+ "); puts cmd
+ Dir.chdir(pwd)
+ end
+ end
+ def gettext_if_any_build_src_trans_po
+ Dir.chdir(@file.output_path.po4a.dir)
+ dirs=Dir['*/']
+ dirs_language=[]
+ dirs.each do |x|
+ dirs_language << x.gsub(/\/$/,'')
+ end
+ dirs_translation = \
+ (language.translation_languages_available & dirs_language)
+ files_src=Dir.glob("./#{source_language_selected_str}/*.ss[tmi]")
+ dirs_translation.each do |lng|
+ files_src.each do |file|
+ fn=file.gsub(/\.\/#{source_language_selected_str}\//,'')
+ system("
+ po4a-gettextize -f text -M utf-8 \
+ -m ./#{source_language_selected_str}/#{fn} \
+ -l ./#{lng}/#{fn} \
+ -p ./po/#{lng}/#{fn}.po
+ ")
+ puts fn
+ end
+ end
+ end
+ def dir_mk(dir)
+ unless FileTest.directory?(dir)
+ FileUtils::mkdir_p(dir)
+ end
+ end
+ def make_paths
+ dir_mk(@file.output_path.pot.dir)
+ dir_mk(@file.output_path.po.dir)
+ end
+ def clean
+ #rm -f po/*/*.po~
+ #rm -rf ../build
+ FileUtils.rm_f Dir.glob("./#{dir.po}/*/*.po~")
+ end
+ def distclean
+ #rm -f po4a.cfg
+ #rm -rf $(LANGUAGES)
+ FileUtils::rm_f(filename.po4a_cfg)
+ FileUtils::rm_r(language.possible_translations,:force => true)
+ #FileUtils::rm_r(language.translation_languages_selected_that_are_available,:force => true)
+ end
+ end
+ class Po4aDistClean
+ include SiSU_Languages_Selected
+ include SiSU_Response
+ def initialize(opt,file)
+ @opt,@file=opt,file
+ end
+ def song
+ pwd=Dir.pwd
+ if FileTest.directory?(@file.output_path.po4a.dir)
+ Dir.chdir(@file.output_path.po4a.dir)
+ dirs=Dir['*/']
+ dirs_language=[]
+ dirs.each do |x|
+ dirs_language << x.gsub(/\/$/,'')
+ end
+ dirs_translation = \
+ (language.translation_languages_available & dirs_language)
+ if dirs_translation.length > 0
+ puts %{remove language translation directorie(s): #{dirs_translation}
+in #{Dir .pwd}}
+ ans=response?('disclean?')
+ if ans
+ FileUtils::rm_f(@file.base_filename.po4a_cfg)
+ FileUtils::rm_r(dirs_translation,:force => true)
+ #FileUtils::rm_r(language.translation_languages_available,:force => true)
+ end
+ end
+ Dir.chdir(pwd)
+ end
+ end
+ end
+end
+#end
+__END__
+REMOVE
+&#033;\|&#035;\|&&#042;\|&#045;\|&#047;\|&#095;\|&#123;\|&#125;\|&#126;\|&#
+
+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
+#+END_SRC
+
+* src_po4a_shelf.rb
+
+#+BEGIN_SRC ruby :tangle "../lib/sisu/src_po4a_shelf.rb"
+# <<sisu_document_header>>
+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 <Source
+ include SiSU_Po4aUtils
+ @@endnotes={ para: [], end: [] }
+ def initialize(fn,data_src,data_trn,md_src,md_trn,wrap_width)
+ @fn,@data_src,@data_trn,@md_src,@md_trn,@wrap_width=
+ fn, data_src, data_trn, md_src, md_trn, wrap_width
+ @md=(md_trn.nil?) \
+ ? md_src
+ : md_trn
+ @tab="\t"
+ @@endnotes_=(@md.opt.selections.str =~/--endnote/) \
+ ? true
+ : false # --footnote
+ @pot={
+ body: [],
+ open: [],
+ close: [],
+ head: [],
+ metadata: [],
+ tail: []
+ }
+ end
+ def br
+ (@md.opt.selections.str =~/--dos/) ? "\r\n" : "\n" # --unix
+ end
+ def songsheet
+ fn=@fn
+ pot=pot_markup(@data_src,@data_trn)
+ publish(fn,pot)
+ end
+ def pot_structure_wrap(desc,orig,trans,indent=0,hang=0)
+ SiSU_Po4aUtils::Wrap.new(
+ @md,
+ orig,
+ trans,
+ desc,
+ @wrap_width,
+ indent,
+ hang
+ )
+ end
+ def wrap_endnotes(orig_notes='',trn_notes='')
+ nt=@@endnotes_ ? 'endnote' : 'footnote'
+ @fn=0
+ a_l=orig_notes.length
+ 0.upto(a_l-1) do |i|
+ @fn=if orig_notes[i].to_s =~/^\^~([\d*+]+)/ # provides endnote number within paragraph
+ @fn += 1
+ else @fn
+ end
+ d="#{nt} #{@fn}"
+ mark="^~ "
+ instruct=s_mark=''
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct=%{\n# footnotes, the preferred sisu markup for a footnote is~{this is a footnote}~ } \
+ + %{however, for translation a footnote reference marker in the text~^ } \
+ + %{with a set of notes following the paragraph starting on a newline with "^~ this is a footnote", } \
+ + %{is easier to deal with, if possible these should be converted back to~{inline notes}~}
+ s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
+ end
+ desc="#{d}#{s_mark}#{instruct}"
+ orig=(orig_notes[i].to_s =~/^\^~[\d*+]+/) \
+ ? (orig_notes[i].to_s.gsub(/^\^~[\d*+]+/,'^~'))
+ : orig_notes[i].to_s
+ trans=if trn_notes.is_a?(Array) \
+ and trn_notes.length==orig_notes.length
+ (trn_notes[i].to_s =~/^\^~[\d*+]+/) \
+ ? (trn_notes[i].to_s.gsub(/^\^~[\d*+]+/,'^~'))
+ : trn_notes[i].to_s
+ else ''
+ end
+ util=pot_structure_wrap(desc,orig,trans)
+ wrap=util.line_wrap
+ wrap=if wrap =~ /^\s*\^~[\d*+]+\s+.+?\s*\Z/m
+ wrap.gsub(/^\s*(\^~[\d*+]+)\s+(.+?)\s*\Z/m, <<GSUB
+\\1 \\2
+GSUB
+ )
+ else
+ wrap.gsub(/^(.+)\Z/m, <<GSUB
+\\1
+GSUB
+ )
+ end
+ @@endnotes[:para] << wrap
+ @@endnotes[:end] << '' << wrap
+ end
+ @@endnotes[:para].each {|e| @pot[:body] << e << br}
+ @@endnotes[:para]=[]
+ @@endnotes
+ end
+ def pot_metadata_src
+ @po4a_identify_type='type: SiSU doc' #'type: Plain text'
+ meta_src=SiSU_Metadata::Summary.new(@md_src)
+ w=[]
+ w << [
+ "#. #{@po4a_identify_type} - metadata: title",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.metadata_tags.title.main,
+ meta_src.metadata_tags.title.sub,
+ meta_src.metadata_tags.title.edition,
+ meta_src.metadata_tags.title.note,
+ meta_src.metadata_tags.title.short,
+ meta_src.metadata_tags.title.language,
+ meta_src.metadata_tags.title.language_char,
+ 'msgstr ""',
+ ]
+ w << [
+ "#. #{@po4a_identify_type} - metadata: creator",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.metadata_tags.creator.head,
+ meta_src.metadata_tags.creator.author,
+ meta_src.metadata_tags.creator.contributor,
+ meta_src.metadata_tags.creator.illustrator,
+ meta_src.metadata_tags.creator.photographer,
+ meta_src.metadata_tags.creator.translator,
+ meta_src.metadata_tags.creator.audio,
+ meta_src.metadata_tags.creator.digitized_by,
+ meta_src.metadata_tags.creator.prepared_by,
+ 'msgstr ""',
+ ]
+ w << [
+ "#. #{@po4a_identify_type} - metadata: rights",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.metadata_tags.rights.head,
+ meta_src.metadata_tags.rights.copyright.text,
+ meta_src.metadata_tags.rights.copyright.translation,
+ meta_src.metadata_tags.rights.copyright.illustrations,
+ meta_src.metadata_tags.rights.copyright.photographs,
+ meta_src.metadata_tags.rights.copyright.digitization,
+ meta_src.metadata_tags.rights.copyright.audio,
+ meta_src.metadata_tags.rights.license,
+ 'msgstr ""',
+ ]
+ w << [
+ "#. #{@po4a_identify_type} - metadata: classify",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.metadata_tags.classify.head,
+ meta_src.metadata_tags.classify.subject,
+ meta_src.metadata_tags.classify.topic_register,
+ meta_src.metadata_tags.classify.loc,
+ meta_src.metadata_tags.classify.dewey,
+ #meta_src.metadata_tags.notes.relation,
+ #meta_src.metadata_tags.notes.type,
+ #meta_src.metadata_tags.identifier.oclc,
+ #meta_src.metadata_tags.identifier.isbn,
+ 'msgstr ""',
+ ]
+ w << [
+ "#. #{@po4a_identify_type} - metadata: date",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.metadata_tags.date.head,
+ meta_src.metadata_tags.date.added_to_site,
+ meta_src.metadata_tags.date.available,
+ meta_src.metadata_tags.date.created,
+ meta_src.metadata_tags.date.issued,
+ meta_src.metadata_tags.date.modified,
+ meta_src.metadata_tags.date.published,
+ meta_src.metadata_tags.date.valid,
+ 'msgstr ""',
+ ]
+ w << [
+ "#. #{@po4a_identify_type} - processing, make instruction",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.processing_tags.make.language,
+ meta_src.processing_tags.make.headings,
+ meta_src.processing_tags.make.num_top,
+ meta_src.processing_tags.make.breaks,
+ meta_src.processing_tags.make.emphasis,
+ meta_src.processing_tags.make.bold,
+ meta_src.processing_tags.make.italics,
+ meta_src.processing_tags.make.texpdf_font,
+ 'msgstr ""',
+ ]
+ w.each do |y|
+ z=''
+ y.each do |x|
+ if x
+ z += x + "\n" if x =~/^#|^msg(?:id|str)/
+ z += %{"#{x}"\n} if x =~/^@\S+?:(?: |$)/
+ z += %{"#{x}"\n} if x =~/^\s+:\S+?: /
+ end
+ end
+ @pot[:metadata] << z << br
+ #puts z unless z.empty?
+ end
+ end
+ def pot_metadata_src_trn
+ @po4a_identify_type='type: SiSU doc'
+ #@po4a_identify_type='type: Plain text'
+ meta_src=SiSU_Metadata::Summary.new(@md_src)
+ meta_trn=SiSU_Metadata::Summary.new(@md_trn)
+ w=[]
+ w << [
+ "#. #{@po4a_identify_type} - metadata: title",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.metadata_tags.title.main,
+ meta_src.metadata_tags.title.sub,
+ meta_src.metadata_tags.title.edition,
+ meta_src.metadata_tags.title.note,
+ meta_src.metadata_tags.title.short,
+ meta_src.metadata_tags.title.language,
+ meta_src.metadata_tags.title.language_char,
+ 'msgstr ""',
+ meta_trn.metadata_tags.title.main,
+ meta_trn.metadata_tags.title.sub,
+ meta_trn.metadata_tags.title.edition,
+ meta_trn.metadata_tags.title.note,
+ meta_trn.metadata_tags.title.short,
+ meta_trn.metadata_tags.title.language,
+ meta_trn.metadata_tags.title.language_char,
+ ]
+ w << [
+ "#. #{@po4a_identify_type} - metadata: creator",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.metadata_tags.creator.head,
+ meta_src.metadata_tags.creator.author,
+ meta_src.metadata_tags.creator.contributor,
+ meta_src.metadata_tags.creator.illustrator,
+ meta_src.metadata_tags.creator.photographer,
+ meta_src.metadata_tags.creator.translator,
+ meta_src.metadata_tags.creator.audio,
+ meta_src.metadata_tags.creator.digitized_by,
+ meta_src.metadata_tags.creator.prepared_by,
+ 'msgstr ""',
+ meta_trn.metadata_tags.creator.head,
+ meta_trn.metadata_tags.creator.author,
+ meta_trn.metadata_tags.creator.contributor,
+ meta_trn.metadata_tags.creator.illustrator,
+ meta_trn.metadata_tags.creator.photographer,
+ meta_trn.metadata_tags.creator.translator,
+ meta_trn.metadata_tags.creator.audio,
+ meta_trn.metadata_tags.creator.digitized_by,
+ meta_trn.metadata_tags.creator.prepared_by,
+ ]
+ w << [
+ "#. #{@po4a_identify_type} - metadata: rights",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.metadata_tags.rights.head,
+ meta_src.metadata_tags.rights.copyright.text,
+ meta_src.metadata_tags.rights.copyright.translation,
+ meta_src.metadata_tags.rights.copyright.illustrations,
+ meta_src.metadata_tags.rights.copyright.photographs,
+ meta_src.metadata_tags.rights.copyright.digitization,
+ meta_src.metadata_tags.rights.copyright.audio,
+ meta_src.metadata_tags.rights.license,
+ 'msgstr ""',
+ meta_trn.metadata_tags.rights.head,
+ meta_trn.metadata_tags.rights.copyright.text,
+ meta_trn.metadata_tags.rights.copyright.translation,
+ meta_trn.metadata_tags.rights.copyright.illustrations,
+ meta_trn.metadata_tags.rights.copyright.photographs,
+ meta_trn.metadata_tags.rights.copyright.digitization,
+ meta_trn.metadata_tags.rights.copyright.audio,
+ meta_trn.metadata_tags.rights.license,
+ ]
+ w << [
+ "#. #{@po4a_identify_type} - metadata: classify",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.metadata_tags.classify.head,
+ meta_src.metadata_tags.classify.subject,
+ meta_src.metadata_tags.classify.topic_register,
+ meta_src.metadata_tags.classify.loc,
+ meta_src.metadata_tags.classify.dewey,
+ #meta_src.metadata_tags.notes.relation,
+ #meta_src.metadata_tags.notes.type,
+ #meta_src.metadata_tags.identifier.oclc,
+ #meta_src.metadata_tags.identifier.isbn,
+ 'msgstr ""',
+ meta_trn.metadata_tags.classify.head,
+ meta_trn.metadata_tags.classify.subject,
+ meta_trn.metadata_tags.classify.topic_register,
+ meta_trn.metadata_tags.classify.loc,
+ meta_trn.metadata_tags.classify.dewey,
+ #meta_trn.metadata_tags.notes.relation,
+ #meta_trn.metadata_tags.notes.type,
+ #meta_trn.metadata_tags.identifier.oclc,
+ #meta_trn.metadata_tags.identifier.isbn,
+ ]
+ w << [
+ "#. #{@po4a_identify_type} - metadata: date",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.metadata_tags.date.head,
+ meta_src.metadata_tags.date.added_to_site,
+ meta_src.metadata_tags.date.available,
+ meta_src.metadata_tags.date.created,
+ meta_src.metadata_tags.date.issued,
+ meta_src.metadata_tags.date.modified,
+ meta_src.metadata_tags.date.published,
+ meta_src.metadata_tags.date.valid,
+ 'msgstr ""',
+ meta_trn.metadata_tags.date.head,
+ meta_trn.metadata_tags.date.added_to_site,
+ meta_trn.metadata_tags.date.available,
+ meta_trn.metadata_tags.date.created,
+ meta_trn.metadata_tags.date.issued,
+ meta_trn.metadata_tags.date.modified,
+ meta_trn.metadata_tags.date.published,
+ meta_trn.metadata_tags.date.valid,
+ ]
+ w << [
+ "#. #{@po4a_identify_type} - processing, make instruction",
+ "#: en/#{@md.fns}:#{SiSU_Po4aUtils::PotNumber.new.num}",
+ 'msgid ""',
+ meta_src.processing_tags.make.language,
+ meta_src.processing_tags.make.headings,
+ meta_src.processing_tags.make.num_top,
+ meta_src.processing_tags.make.breaks,
+ meta_src.processing_tags.make.emphasis,
+ meta_src.processing_tags.make.bold,
+ meta_src.processing_tags.make.italics,
+ meta_src.processing_tags.make.texpdf_font,
+ 'msgstr ""',
+ meta_trn.processing_tags.make.language,
+ meta_trn.processing_tags.make.headings,
+ meta_trn.processing_tags.make.num_top,
+ meta_trn.processing_tags.make.breaks,
+ meta_trn.processing_tags.make.emphasis,
+ meta_trn.processing_tags.make.bold,
+ meta_trn.processing_tags.make.italics,
+ meta_trn.processing_tags.make.texpdf_font,
+ ]
+ w.each do |y|
+ z=''
+ y.each do |x|
+ if x
+ z += x + "\n" if x =~/^#|^msg(?:id|str)/
+ z += %{"#{x}"\n} if x =~/^@\S+?:(?: |$)/
+ z += %{"#{x}"\n} if x =~/^\s+:\S+?: /
+ end
+ end
+ @pot[:metadata] << z << br
+ #puts z unless z.empty?
+ end
+ end
+ def auto_translate?(set_to=nil)
+ @@auto_translation_=
+ if @md.opt.act[:po4a_lang_trans][:set]==:on
+ set_to \
+ ? set_to
+ : @@auto_translation_
+ else :skip
+ end
+ end
+ def auto_translation(src_txt,markup=:src) # check for an appropriate request flag
+ auto_translate?(:skip)
+ begin
+ src_txt_clean=clean_text(src_txt,markup)
+ src_txt_clean=src_txt_clean.
+ gsub(/\n/,' ').
+ gsub(/"/,'\"').
+ gsub(/([()])/,'\\\\\1')
+ trans=''
+ unless auto_translate? == :skip
+ require 'timeout'
+ Timeout::timeout(60) {
+ trans=`trans -b -no-ansi en:#{@md.opt.f_pth[:lng_is]} #{src_txt_clean}`.strip
+ unless trans.empty?
+ trans + ' {[G.Tr]}http://translate.google.com'
+ end
+ }
+ end
+ trans
+ rescue
+ auto_translate?(:skip)
+ p 'timeout issues with translation, skip remaining'
+ end
+ end
+ def pot_structure
+ def heading(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
+ lv=n=n3=nil
+ lv=dob_src.ln
+ n=lv - 1
+ n3=lv + 2
+ util=nil
+ fn=(dob_src.name=~/[a-z\d]/i) ? dob_src.name : ''
+ mark="#{dob_src.lv}~#{fn} "
+ d="#{dob_src.is.to_s} (level #{dob_src.lv})"
+ instruct=s_mark=''
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct=%{\n# markup for headings is marker at the start of the line/object, } \
+ + %{indicating the heading level, and if provided an associated name tag, } \
+ + %{this heading is "#{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
+ util=pot_structure_wrap(desc,orig,trans)
+ 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 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 =~/<a name="n\d+">/ \
+ and dob_src.obj =~/^(-\{{2}~\d+|<!e[:_]\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 <Source
+ include SiSU_Param
+ include SiSU_Env
+ def initialize(fn,content,md,process=:complete)
+ @fn,@content,@md,@process=fn,content,md,process
+ @file=SiSU_Env::FileOp.new(md,fn)
+ end
+ def po4a #%pot output
+ file_pot=(@md.opt.f_pth[:lng] == @md.opt.lng_base) \
+ ? @file.write_file.pot
+ : @file.write_file.po
+ @sisu=[]
+ emptyline=0
+ @content.each do |para| # this is a hack
+ if para.is_a?(Array) \
+ and para.length > 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__
+&#033;\|&#035;\|&&#042;\|&#045;\|&#047;\|&#095;\|&#123;\|&#125;\|&#126;\|&#
+
+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
+#+END_SRC
+
+* src_po4a_shelf_set.rb
+
+#+BEGIN_SRC ruby :tangle "../lib/sisu/src_po4a_shelf_set.rb"
+# <<sisu_document_header>>
+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(/<br>/,' <br> ').
+ gsub(/#{Mx[:br_nl]}/,"\n\n")
+ words=pa.scan(/\n\n|\\\\\\|<br>|\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=<<WOK
+#. #{@po4a_identify_type} - #{@is_desc}
+#: en/#{@md.fns}:#{PotNumber.new.num}
+msgid ""
+#{pot[0]}
+msgstr ""
+#{trans}
+WOK
+ po_str
+ end
+ def no_line_wrap_block
+ pot,i=[],0
+ pot_array=(@trans.empty?) ? [@orig] : [@orig,@trans]
+ pot_array.each do |pa|
+ z=[]
+ pa.split(/\n\n/).each do |y|
+ y=y.gsub(/"/,'\"')
+ y=%{"#{y}"}
+ z << y if not y.empty?
+ end
+ pot[i]=z.join("\n")
+ i +=1
+ pot
+ end
+ trans=(pot.length == 2) ? pot[1] : ''
+ po_str=<<WOK
+#. #{@po4a_identify_type} - #{@is_desc}
+#: en/#{@md.fns}:#{PotNumber.new.num}
+#, no-wrap
+msgid ""
+#{pot[0]}
+msgstr ""
+#{trans}
+WOK
+ po_str
+ end
+ def line_wrap_indent1
+ @n_indent,@n_hang=2,2
+ line_wrap
+ end
+ def line_wrap_endnote
+ @n_indent,@n_hang=4,2
+ line_wrap
+ end
+ def array_wrap
+ if @orig.is_a?(Array)
+ @arr=[]
+ @orig.each do |line|
+ @arr << SiSU_TextUtils::Wrap.new(line,@n_char_max,@n_indent,@n_hang).line_wrap
+ end
+ end
+ @arr
+ end
+ end
+ class HeaderScan
+ def initialize(md,para)
+ @md,@p=md,para
+ end
+ def extract(tag,tag_content,type,attrib)
+ if dc_tag \
+ and dc_content
+ [dc_tag,dc_content,{dc_tag=>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__
+#+END_SRC
+
+* src_po4a_sst_ao_sst.rb
+
+#+BEGIN_SRC ruby :tangle "../lib/sisu/src_po4a_sst_ao_sst.rb"
+# <<sisu_document_header>>
+module SiSU_SStm_AO_SStm
+ 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_share' # src_po4a_share.rb
+ require_relative 'src_po4a_sst_ao_sst_set' # src_po4a_sst_ao_sst_set.rb
+ include SiSU_Param
+ require_relative 'object_munge' # object_munge.rb
+ require_relative 'utils_composite' # utils_composite.rb
+ require_relative 'utils_response' # utils_response.rb
+ class Source
+ include SiSU_Object_Munge
+ include SiSU_Languages_Selected
+ include SiSU_Response
+ @@md_src,@@md_master=
+ 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.fno)
+ SiSU_Param::Parameters::Instructions.new(file_arr,@opt).extract
+ r=Px[:lng_lst_rgx].gsub(/\|#{language.source_language_selected_str}\|/,'|')
+ @lang_regx=%r{(?:#{r})}
+ @@todo=if source_language_selected_str == opt.f_pth[:lng]
+ :same_file
+ else :compare
+ end
+ if opt.f_pth[:lng]==@opt.lng_base \
+ and opt.f_pth[:lng]==source_language_selected_str
+ @@md_master=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 # 78 use 75
+ 75
+ else 75 #78
+ end
+ end
+ def process_file(md,env,file,wrap_width,fn)
+ if source_language_selected_str == @opt.f_pth[:lng]
+ @@ao_arr_lang_trans=
+ SiSU_AO::Source.new(
+ @opt,
+ fn,
+ :po4a
+ ).get # ao file drawn here
+ end
+ @ao_arr_lang_src=
+ SiSU_AO::Source.new(
+ @opt,
+ fn,
+ :po4a
+ ).get # ao file drawn here
+ SiSU_SStm_AO_SStm::Source::Scroll.new(
+ fn,
+ @ao_arr_lang_src,
+ @@ao_arr_lang_trans,
+ @@md_src,
+ @@md_master,
+ wrap_width
+ ).songsheet
+ end
+ def read_process_src_files
+ 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)
+ lng=/\/([^\/]+)$/.match(src[:pth])[1]
+ if language.source_language_selected_str == lng
+ SiSU_Po4a_Project::Po4aDistClean.new(@opt,file).song
+ end
+ wrap_width=wrap_width_set(md,env)
+ lng = /\/([^\/]+)$/.match(src[:pth])[1]
+ ans=response?('process files?')
+ if ans
+ src[:files].each do |fn|
+ puts "[#{lng}] #{fn}"
+ process_file(md,env,file,wrap_width,fn)
+ end
+ end
+ rescue
+ SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
+ __LINE__.to_s + ':' + __FILE__
+ end
+ ensure
+ end
+ end
+ def read_setup
+ begin
+ md=SiSU_Param::Parameters.new(@opt).get
+ file=SiSU_Env::FileOp.new(md)
+ SiSU_Po4a_Project::Po4aCfg.new(@opt,file).song
+ SiSU_Po4a_Project::Po4aProject.new(@opt,file).song
+ rescue
+ SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
+ __LINE__.to_s + ':' + __FILE__
+ end
+ ensure
+ end
+ end
+ private
+ class Scroll <Source
+ include SiSU_Po4aUtils
+ @@endnotes={ para: [], end: [] }
+ def initialize(fn,data_src,data_master,md_src,md_master,wrap_width)
+ @fn,@data_src,@data_master,@md_src,@md_master,@wrap_width=
+ fn, data_src, data_master, md_src, md_master, wrap_width
+ @md=md_src
+ @tab="\t"
+ @@endnotes_=(@md.opt.selections.str =~/--endnote/) \
+ ? true
+ : false # --footnote
+ @pot={
+ body: [],
+ open: [],
+ close: [],
+ head: [],
+ metadata: [],
+ tail: []
+ }
+ end
+ def br
+ (@md.opt.selections.str =~/--dos/) ? "\r\n" : "\n" # --unix
+ end
+ def songsheet
+ fn=@fn
+ pot=compare_structure_src_trn(@data_src,@data_master,@@todo)
+ publish(fn,pot)
+ end
+ def pot_structure_wrap(orig,trans,indent=0,hang=0)
+ SiSU_Po4aUtils::Wrap.new(
+ @md,
+ orig,
+ trans,
+ @wrap_width,
+ indent,
+ hang
+ )
+ end
+ def wrap_endnotes(orig_notes='',trn_notes='')
+ #nt=@@endnotes_ ? 'endnote' : 'footnote'
+ @fn=0
+ a_l=orig_notes.length
+ 0.upto(a_l-1) do |i|
+ @fn=if orig_notes[i].to_s =~/^\^~([\d*+]+)/ # provides endnote number within paragraph
+ @fn += 1
+ else @fn
+ end
+ #mark="^~ "
+ orig=(orig_notes[i].to_s =~/^\^~[\d*+]+/) \
+ ? (orig_notes[i].to_s.gsub(/^\^~[\d*+]+/,'^~'))
+ : orig_notes[i].to_s
+ trans=if trn_notes.is_a?(Array) \
+ and trn_notes.length==orig_notes.length
+ (trn_notes[i].to_s =~/^\^~[\d*+]+/) \
+ ? (trn_notes[i].to_s.gsub(/^\^~[\d*+]+/,'^~'))
+ : trn_notes[i].to_s
+ else ''
+ end
+ util=pot_structure_wrap(orig,trans)
+ wrap=util.line_wrap
+ wrap=if wrap =~ /^\s*\^~[\d*+]+\s+.+?\s*\Z/m
+ wrap.gsub(/^\s*(\^~[\d*+]+)\s+(.+?)\s*\Z/m, <<GSUB
+\\1 \\2
+GSUB
+ )
+ else
+ wrap.gsub(/^(.+)\Z/m, <<GSUB
+\\1
+GSUB
+ )
+ end
+ @@endnotes[:para] << wrap
+ @@endnotes[:end] << '' << wrap
+ end
+ @@endnotes[:para].each {|e| @pot[:body] << e << br}
+ @@endnotes[:para]=[]
+ @@endnotes
+ end
+ def pot_metadata_src
+ @po4a_identify_type='type: SiSU doc' #'type: Plain text'
+ meta_src=SiSU_Metadata::Summary.new(@md_src)
+ w=[]
+ w << [
+ meta_src.metadata_tags.title.main,
+ meta_src.metadata_tags.title.sub,
+ meta_src.metadata_tags.title.edition,
+ meta_src.metadata_tags.title.note,
+ meta_src.metadata_tags.title.short,
+ meta_src.metadata_tags.title.language,
+ meta_src.metadata_tags.title.language_char,
+ ]
+ w << [
+ meta_src.metadata_tags.creator.head,
+ meta_src.metadata_tags.creator.author,
+ meta_src.metadata_tags.creator.contributor,
+ meta_src.metadata_tags.creator.illustrator,
+ meta_src.metadata_tags.creator.photographer,
+ meta_src.metadata_tags.creator.translator,
+ meta_src.metadata_tags.creator.audio,
+ meta_src.metadata_tags.creator.digitized_by,
+ meta_src.metadata_tags.creator.prepared_by,
+ ]
+ w << [
+ meta_src.metadata_tags.rights.head,
+ meta_src.metadata_tags.rights.copyright.text,
+ meta_src.metadata_tags.rights.copyright.translation,
+ meta_src.metadata_tags.rights.copyright.illustrations,
+ meta_src.metadata_tags.rights.copyright.photographs,
+ meta_src.metadata_tags.rights.copyright.digitization,
+ meta_src.metadata_tags.rights.copyright.audio,
+ meta_src.metadata_tags.rights.license,
+ ]
+ w << [
+ meta_src.metadata_tags.classify.head,
+ meta_src.metadata_tags.classify.subject,
+ meta_src.metadata_tags.classify.topic_register,
+ meta_src.metadata_tags.classify.loc,
+ meta_src.metadata_tags.classify.dewey,
+ ]
+ w << [
+ meta_src.metadata_tags.date.head,
+ meta_src.metadata_tags.date.added_to_site,
+ meta_src.metadata_tags.date.available,
+ meta_src.metadata_tags.date.created,
+ meta_src.metadata_tags.date.issued,
+ meta_src.metadata_tags.date.modified,
+ meta_src.metadata_tags.date.published,
+ meta_src.metadata_tags.date.valid,
+ ]
+ w << [
+ meta_src.processing_tags.make.language,
+ meta_src.processing_tags.make.headings,
+ meta_src.processing_tags.make.num_top,
+ meta_src.processing_tags.make.breaks,
+ meta_src.processing_tags.make.emphasis,
+ meta_src.processing_tags.make.bold,
+ meta_src.processing_tags.make.italics,
+ meta_src.processing_tags.make.texpdf_font,
+ ]
+ w.each do |y|
+ z=''
+ y.each do |x|
+ if x
+ z += x + "\n" if x =~/^#|^msg(?:id|str)/
+ z += %{#{x}\n} if x =~/^@\S+?:(?: |$)/
+ z += %{#{x}\n} if x =~/^\s+:\S+?: /
+ end
+ end
+ @pot[:metadata] << z << br
+ #puts z unless z.empty?
+ end
+ end
+ def pot_metadata_src_trn
+ #@po4a_identify_type='type: Plain text'
+ meta_src=SiSU_Metadata::Summary.new(@md_src)
+ w=[]
+ w << [
+ meta_src.metadata_tags.title.main,
+ meta_src.metadata_tags.title.sub,
+ meta_src.metadata_tags.title.edition,
+ meta_src.metadata_tags.title.note,
+ meta_src.metadata_tags.title.short,
+ meta_src.metadata_tags.title.language,
+ meta_src.metadata_tags.title.language_char,
+ ]
+ w << [
+ meta_src.metadata_tags.creator.head,
+ meta_src.metadata_tags.creator.author,
+ meta_src.metadata_tags.creator.contributor,
+ meta_src.metadata_tags.creator.illustrator,
+ meta_src.metadata_tags.creator.photographer,
+ meta_src.metadata_tags.creator.translator,
+ meta_src.metadata_tags.creator.audio,
+ meta_src.metadata_tags.creator.digitized_by,
+ meta_src.metadata_tags.creator.prepared_by,
+ ]
+ w << [
+ meta_src.metadata_tags.rights.head,
+ meta_src.metadata_tags.rights.copyright.text,
+ meta_src.metadata_tags.rights.copyright.translation,
+ meta_src.metadata_tags.rights.copyright.illustrations,
+ meta_src.metadata_tags.rights.copyright.photographs,
+ meta_src.metadata_tags.rights.copyright.digitization,
+ meta_src.metadata_tags.rights.copyright.audio,
+ meta_src.metadata_tags.rights.license,
+ ]
+ w << [
+ meta_src.metadata_tags.classify.head,
+ meta_src.metadata_tags.classify.subject,
+ meta_src.metadata_tags.classify.topic_register,
+ meta_src.metadata_tags.classify.loc,
+ meta_src.metadata_tags.classify.dewey,
+ ]
+ w << [
+ meta_src.metadata_tags.date.head,
+ meta_src.metadata_tags.date.added_to_site,
+ meta_src.metadata_tags.date.available,
+ meta_src.metadata_tags.date.created,
+ meta_src.metadata_tags.date.issued,
+ meta_src.metadata_tags.date.modified,
+ meta_src.metadata_tags.date.published,
+ meta_src.metadata_tags.date.valid,
+ ]
+ w << [
+ meta_src.processing_tags.make.language,
+ meta_src.processing_tags.make.headings,
+ meta_src.processing_tags.make.num_top,
+ meta_src.processing_tags.make.breaks,
+ meta_src.processing_tags.make.emphasis,
+ meta_src.processing_tags.make.bold,
+ meta_src.processing_tags.make.italics,
+ meta_src.processing_tags.make.texpdf_font,
+ ]
+ w.each do |y|
+ z=''
+ y.each do |x|
+ if x
+ z += x + "\n" if x =~/^#|^msg(?:id|str)/
+ z += %{#{x}\n} if x =~/^@\S+?:(?: |$)/
+ z += %{#{x}\n} if x =~/^\s+:\S+?: /
+ end
+ end
+ @pot[:metadata] << z << br
+ #puts z unless z.empty?
+ end
+ end
+ def auto_translate?(set_to=nil)
+ @@auto_translation_=
+ if @md.opt.act[:po4a_lang_trans][:set]==:on
+ set_to \
+ ? set_to
+ : @@auto_translation_
+ else :skip
+ end
+ end
+ def auto_translation(src_txt,markup=:src) # check for an appropriate request flag
+ auto_translate?(:skip)
+ begin
+ src_txt_clean=clean_text(src_txt,markup)
+ src_txt_clean=src_txt_clean.
+ gsub(/\n/,' ').
+ gsub(/"/,'\"').
+ gsub(/([()])/,'\\\\\1')
+ trans=''
+ unless auto_translate? == :skip
+ require 'timeout'
+ Timeout::timeout(60) {
+ trans=`trans -b -no-ansi en:#{@md.opt.f_pth[:lng_is]} #{src_txt_clean}`.strip
+ unless trans.empty?
+ trans + ' {[G.Tr]}http://translate.google.com'
+ end
+ }
+ end
+ trans
+ rescue
+ auto_translate?(:skip)
+ p 'timeout issues with translation, skip remaining'
+ end
+ end
+ def pot_structure
+ def heading(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
+ lv=n=n3=nil
+ lv=dob_src.ln
+ n=lv - 1
+ n3=lv + 2
+ util=nil
+ fn=(dob_src.name=~/[a-z\d]/i) ? dob_src.name : ''
+ mark="#{dob_src.lv}~#{fn} "
+ orig="#{mark}#{dob_src.obj}"
+ trans=((dob_trn=='') \
+ || (dob_src.obj == dob_trn.obj)) \
+ ? ''
+ : "#{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(orig,trans)
+ 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 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=''
+ mark=if dob_src.bullet_
+ "_#{dob_src.indent}* "
+ else
+ "_#{dob_src.indent} "
+ end
+ orig="#{mark}#{dob_src.obj}"
+ trans=((dob_trn=='') \
+ || (dob_src.obj == dob_trn.obj)) \
+ ? ''
+ : "#{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(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} "
+ orig="#{mark}#{dob_src.obj}"
+ trans=((dob_trn=='') \
+ || (dob_src.obj == dob_trn.obj)) \
+ ? ''
+ : "#{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(orig,trans)
+ else
+ s_mark=desc=orig=trans=''
+ if dob_src.bullet_
+ mark='_* '
+ orig="#{mark}#{dob_src.obj}"
+ trans=((dob_trn=='') \
+ || (dob_src.obj == dob_trn.obj)) \
+ ? ''
+ : "#{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=''
+ orig=dob_src.obj
+ trans=((dob_trn=='') \
+ || (dob_src.obj == dob_trn.obj)) \
+ ? ''
+ : "#{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(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_o ="block{\n\n"
+ mark_c ="\n\n}block"
+ orig="#{mark_o}#{dob_src.obj}#{mark_c}"
+ trans=((dob_trn=='') \
+ || (dob_src.obj == dob_trn.obj)) \
+ ? ''
+ : "#{mark_o}#{dob_trn.obj}#{mark_c}"
+ 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(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_o ="group{\n\n"
+ mark_c ="\n\n}group"
+ orig="#{mark_o}#{dob_src.obj}#{mark_c}"
+ trans=((dob_trn=='') \
+ || (dob_src.obj == dob_trn.obj)) \
+ ? ''
+ : "#{mark_o}#{dob_trn.obj}#{mark_c}"
+ 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(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"
+ 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
+ orig=dob_src.obj
+ trans=(dob_trn=='') \
+ ? ''
+ : dob_trn.obj
+ util=pot_structure_wrap(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_o ="code{\n\n"
+ mark_c ="\n\n}code"
+ orig="#{mark_o}#{dob_src.obj}#{mark_c}"
+ trans=(dob_trn=='') \
+ ? ''
+ : "#{mark_o}#{dob_trn.obj}#{mark_c}"
+ util=pot_structure_wrap(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_o ="table{\n\n"
+ mark_c ="\n\n}table"
+ orig="#{mark_o}#{dob_src.obj}#{mark_c}"
+ orig=orig.gsub(/#{Mx[:tc_c]}/m,"\n")
+ trans=(dob_trn=='') \
+ ? ''
+ : "#{mark_o}#{dob_trn.obj}#{mark_c}"
+ trans=trans.gsub(/#{Mx[:tc_c]}/m,"\n")
+ util=pot_structure_wrap(orig,trans)
+ unwrapped=util.no_line_wrap_block
+ @pot[:body] << unwrapped << br
+ end
+ def idx_markup(idx)
+ struct=['={' + "\n "]
+ idx.sort.each do |x|
+ x.each_with_index do |y,i0|
+ case y
+ when String
+ unless struct[-1] =~/=\{/
+ struct << ' ;' + "\n "
+ end
+ struct << y
+ if x[i0+1].class == Hash \
+ and x[i0+1][:sub].length > 0
+ struct << ' :' + "\n "
+ 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|
+ 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 << "\n" + '}'
+ #puts struct.join
+ struct.join
+ end
+ def idx(dob_src='') #% used for book index but broken as original markup lost, already abstracted, fix
+ orig=pot_structure.idx_markup(dob_src.idx) #'={' + dob_src.idx + '}'
+ util=pot_structure_wrap(orig,'')
+ unwrapped=util.no_line_wrap_block
+ if @pot[:body][-1] == "\n"
+ @pot[:body][-1] = unwrapped #<< br
+ @pot[:body] << br
+ else # expect to catch all above, problem if wraps, must =~/^=\{/
+ @pot[:body] << unwrapped << br # places idx in separate object
+ end
+ end
+ self
+ end
+ def compare_structure_src_trn(data_src,data_trn,todo)
+ #@endnotes,@copen,@pot_contents_close=Array.new(3){[]}
+ a_l= data_src.length
+ s,t=0,0
+ 0.upto(a_l-1) do |i|
+ if todo==:compare
+ 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 if defined? data_src[s].ocn
+ p data_src[s].obj if defined? data_src[s].obj
+ p data_trn[t].ocn if defined? data_trn[t].ocn
+ p data_trn[t].obj if defined? data_trn[t].obj
+ p '---'
+ p 'previous match'
+ p data_src[@m_s].ocn if defined? data_src[@m_s].ocn
+ p data_src[@m_s].obj if defined? data_src[@m_s].obj
+ p data_trn[@m_t].ocn if defined? data_trn[@m_t].ocn
+ p data_trn[@m_t].obj if defined? data_trn[@m_s].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 if defined? data_src[s].obj
+ p data_trn[t].ocn if defined? data_trn[t].ocn
+ p data_trn[t].obj if defined? 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=''
+ data_src[s],notes_s=markup(data_src[s])
+ data_src[s],nul=pot_data(data_src[s],notes_s)
+ s+=1;t+=1
+ end
+ @pot #watch
+ end
+ def pot_data(dob_src='',notes_s)
+ 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)
+ when :para
+ pot_structure.para(dob_src,notes_s)
+ when :group
+ pot_structure.group(dob_src,notes_s)
+ when :block
+ pot_structure.block(dob_src,notes_s)
+ when :verse
+ pot_structure.verse(dob_src,notes_s)
+ when :code
+ pot_structure.code(dob_src,notes_s)
+ when :table
+ pot_structure.table(dob_src,notes_s)
+ end
+ if defined? dob_src.idx \
+ and not dob_src.idx.nil? \
+ and not dob_src.idx.empty?
+ pot_structure.idx(dob_src)
+ end
+ #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 Output <Source
+ include SiSU_Param
+ include SiSU_Env
+ def initialize(fn,content,md,process=:complete)
+ @fn,@content,@md,@process=fn,content,md,process
+ @file=SiSU_Env::FileOp.new(md,fn)
+ end
+ def po4a #%pot output
+ file_pot=@file.write_file.po4a_sst
+ #file_pot=(@md.opt.f_pth[:lng] == @md.opt.lng_base) \
+ #? @file.write_file.pot
+ #: @file.write_file.po
+ @sisu=[]
+ emptyline=0
+ @content.each do |para| # this is a hack
+ if para.is_a?(Array) \
+ and para.length > 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__
+REMOVE
+&#033;\|&#035;\|&&#042;\|&#045;\|&#047;\|&#095;\|&#123;\|&#125;\|&#126;\|&#
+
+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
+#+END_SRC
+
+* src_po4a_sst_ao_sst_set.rb
+
+#+BEGIN_SRC ruby :tangle "../lib/sisu/src_po4a_sst_ao_sst_set.rb"
+# <<sisu_document_header>>
+module SiSU_Po4aUtils
+ class Wrap
+ def initialize(md,orig='',trans='',n_char_max=76,n_indent=0,n_hang=nil)
+ @md,@orig,@trans,@n_char_max,@n_indent=
+ md, orig, trans, 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(/<br>/,' <br> ').
+ gsub(/#{Mx[:br_nl]}/,"\n\n")
+ words=pa.scan(/\n\n|\\\\\\|<br>|\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|
+ z << y
+ end
+ pot[i]=z.join("\n")
+ i +=1
+ pot
+ end
+ trans=(pot.length == 2) ? pot[1] : ''
+ po_str=<<WOK
+#{pot[0]}
+WOK
+#{trans}
+ po_str
+ end
+ def no_line_wrap_block
+ pot,i=[],0
+ pot_array=(@trans.empty?) ? [@orig] : [@orig,@trans]
+ pot_array.each do |pa|
+ z=[]
+ pa.split(/\n\n/).each do |y|
+ z << y if not y.empty?
+ end
+ pot[i]=z.join("\n")
+ i +=1
+ pot
+ end
+ trans=(pot.length == 2) ? pot[1] : ''
+ po_str=<<WOK
+#{pot[0]}
+WOK
+#{trans}
+ po_str
+ end
+ def line_wrap_indent1
+ @n_indent,@n_hang=2,2
+ line_wrap
+ end
+ def line_wrap_endnote
+ @n_indent,@n_hang=4,2
+ line_wrap
+ end
+ def array_wrap
+ if @orig.is_a?(Array)
+ @arr=[]
+ @orig.each do |line|
+ @arr << SiSU_TextUtils::Wrap.new(line,@n_char_max,@n_indent,@n_hang).line_wrap
+ end
+ end
+ @arr
+ end
+ end
+ class HeaderScan
+ def initialize(md,para)
+ @md,@p=md,para
+ end
+ def extract(tag,tag_content,type,attrib)
+ if dc_tag \
+ and dc_content
+ [dc_tag,dc_content,{dc_tag=>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__
+#+END_SRC
+
+* src_po4a_sstm.rb
+
+#+BEGIN_SRC ruby :tangle "../lib/sisu/src_po4a_sstm.rb"
+# <<sisu_document_header>>
+module SiSU_Markup
+ require_relative 'src_shared' # src_shared.rb
+ include SiSU_Source
+ require_relative 'src_po4a_share' # src_po4a_share.rb
+ require_relative 'se' # se.rb
+ include SiSU_Env
+ class Source_Po4a < SiSU_Source::SiSUpodSource
+ def initialize(opt,build=nil,place=nil)
+ super(opt,build,place)
+ @opt=opt
+ md=SiSU_Param::Parameters.new(opt).get
+ @file=SiSU_Env::FileOp.new(md,opt.fno)
+ end
+ def dir_mk(dir)
+ unless FileTest.directory?(dir)
+ FileUtils::mkdir_p(dir)
+ end
+ end
+ def make_paths
+ dir_mk(@file.output_path.pot.dir)
+ dir_mk(@file.output_path.po.dir)
+ end
+ def language
+ def source_language_selected_str
+ @opt.act[:po4a_lang][:src] \
+ ? @opt.act[:po4a_lang][:src]
+ : 'en'
+ end
+ self
+ end
+ def read
+ unless @opt.act[:quiet][:set]==:on
+ (@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],
+ 'Share document markup text source',
+ @opt.fns
+ ).cyan_hi_blue
+ : SiSU_Screen::Ansi.new(
+ @opt.act[:color_state][:set],
+ 'Share document markup text source',
+ @opt.fns
+ ).cyan_title_hi
+ end
+ make_paths
+ if FileTest.directory?(@path_pod[:fnb])
+ FileUtils::mkdir_p(@file.output_path.src.dir) \
+ unless FileTest.directory?(@file.output_path.src.dir)
+ v=(@opt.act[:maintenance][:set]==:on) \
+ ? 'v' : ''
+ system(%{
+ #rsync -a#{v} #{@path_pod[:fnb]}/sisupod/doc/* #{@file.output_path.po4a.dir}
+ rsync -a#{v} #{@path_pod[:fnb]}/sisupod/doc/#{language.source_language_selected_str}* #{@file.output_path.po4a.dir}
+ chbk=`pwd`
+ cd #{@file.output_path.sisupod.dir}
+ for I in `find -type d` ; do chmod 755 $I ; done
+ for I in `find -type f` ; do chmod 644 $I ; done
+ cd ${chbk}
+ })
+ md=SiSU_Param::Parameters.new(@opt).get
+ file=SiSU_Env::FileOp.new(md)
+ SiSU_Po4a_Project::Po4aCfg.new(@opt,file).song
+ SiSU_Po4a_Project::Po4aProject.new(@opt,file).song
+ else
+ if (@opt.act[:verbose][:set]==:on \
+ || @opt.act[:verbose_plus][:set]==:on \
+ || @opt.act[:maintenance][:set]==:on)
+ SiSU_Screen::Ansi.new(
+ '',
+ "#{@opt.fno} not available"
+ ).blue_tab
+ end
+ end
+ end
+ end
+end
+__END__
+#+END_SRC
+
+* src_shared.rb
+
+#+BEGIN_SRC ruby :tangle "../lib/sisu/src_shared.rb"
+# <<sisu_document_header>>
+module SiSU_Source
+ include SiSU_Env
+ class SiSUpodSource
+ require_relative 'se' # se.rb
+ require_relative 'se_hub_particulars' # se_hub_particulars.rb
+ require_relative 'utils_composite' # utils_composite.rb
+ include SiSU_Composite_Doc_Utils # composite doc, .ssm, extract all related insert files, array of filenames test
+ def initialize(opt,build=nil,place=nil)
+ @opt=opt
+ @date=SiSU_Env::InfoDate.new.dt
+ @env=SiSU_Env::InfoEnv.new(opt.fns)
+ #@ver=SiSU_Env::InfoVersion.instance.get_version
+ @v=(@opt.act[:verbose_plus][:set]==:on \
+ || @opt.act[:maintenance][:set]==:on) \
+ ? 'v' : ''
+ @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
+ @file=@particulars.file
+ @local_path="#{@file.output_path.sisupod.dir}"
+ processing_sisupod=@env.processing_path.processing_sisupod(opt)
+ processing_sisupod.make
+ path_pod=processing_sisupod.paths[:sisupod]
+ path_pod_fnb=processing_sisupod.paths[:fnb]
+ FileUtils::mkdir_p(path_pod) unless FileTest.directory?(path_pod)
+ @path_pod={
+ fnb: path_pod_fnb,
+ pod: path_pod,
+ doc: path_pod + '/' + Gt[:doc] + '/' + opt.lng,
+ po: path_pod + '/' + Gt[:po] + '/' + opt.lng,
+ pot: path_pod + '/' + Gt[:pot],
+ conf: path_pod + '/' + Gt[:conf],
+ image: path_pod + '/' + Gt[:image],
+ audio: path_pod + '/' + Gt[:audio],
+ video: path_pod + '/' + Gt[:video],
+ }
+ end
+ def read
+ unless @opt.act[:quiet][:set]==:on
+ (@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],
+ 'Assemble SiSU source',
+ "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").
+ green_hi_blue
+ : ''
+ end
+ unless @opt.fns.empty?
+ directories
+ doc_import_list=composite_and_imported_filenames_array(@opt.fno)
+ doc_import_list=[@opt.fno, doc_import_list].flatten
+ image_extraction(doc_import_list)
+ language_versions
+ end
+ end
+ def images_extract(f,images) # consider using param info
+ rgx_image=/(?:^|[^_\\])\{(?:\s*|\~\^\s+)(\S+?\.(?:png|jpg|gif)\b)/m
+ if f !~/^%+\s/ \
+ and f =~rgx_image
+ images << f.scan(rgx_image).uniq
+ end
+ images.flatten
+ end
+ def image_extraction(doc_import_list)
+ @rgx_rb_image=/["']\S*?([a-zA-Z0-9_-]+?\.(?:png|jpg|gif))["']/
+ @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/
+ doc_import_dir=@opt.sub_location
+ images=[]
+ if doc_import_list.length > 0
+ doc_import_list=doc_import_list.uniq.flatten
+ doc_import_list.each do |fn|
+ file_array=IO.readlines(fn,'')
+ file_array.each do |f| #% work area
+ f=f.gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image') # embedded symbol (image)
+ if f !~/^%+\s/ \
+ and f =~@rgx_image
+ images=images_extract(f,images)
+ end
+ end
+ end
+ end
+ gi=SiSU_Env::GetInit.new
+ unless FileTest.file?("#{@path_pod[:conf]}/#{gi.makefile_name}")
+ if gi.makefile \
+ && FileTest.file?(gi.makefile)
+ FileUtils::mkdir_p(@path_pod[:conf]) \
+ unless FileTest.directory?(@path_pod[:conf])
+ FileUtils::cp(gi.makefile,"#{@path_pod[:conf]}/#{gi.makefile_name}")
+ end
+ #get images from makefile, consider placing in param
+ end
+ if images \
+ and images.length > 1
+ images=images.flatten.uniq
+ images.delete_if {|x| x =~/https?:\/\// }
+ #images=images.sort
+ FileUtils::mkdir_p(@path_pod[:image])
+ images_pwd=@opt.image_src_path
+ ##sequence copies base images, defaults used in all html outputs
+ #image_source_base='/usr/share/sisu/image'
+ #dir_pwd=Dir.pwd
+ #Dir.chdir(image_source_base)
+ #base_images=Dir.glob('*')
+ #base_images.each do |i|
+ # FileUtils::cp_r(i,"#{images_path_pod}/#{i}")
+ #end
+ #Dir.chdir(dir_pwd)
+ if FileTest.directory?(images_pwd)
+ images=images.uniq
+ images.each do |i|
+ if FileTest.file?("#{images_pwd}/#{i}")
+ FileUtils::cp(
+ "#{images_pwd}/#{i}",
+ "#{@path_pod[:image]}/#{i}"
+ )
+ else
+ STDERR.puts \
+ %{\t*WARN* did not find image - } \
+ + %{"#{images_pwd}/#{i}" } \
+ + %{[#{__FILE__}:#{__LINE__}]}
+ end
+ end
+ else
+ STDERR.puts \
+ %{\t*WARN* did not find - } \
+ + %{#{images_pwd} #{@path_pod[:image]} } \
+ + %{[#{__FILE__}:#{__LINE__}]}
+ end
+ end
+ if doc_import_list.length > 0 \
+ and @opt.fno =~/\.ssm$/
+ doc_import_list.each do |f|
+ if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f}")
+ FileUtils::cp(
+ "#{@opt.base_path}#{doc_import_dir}/#{f}",
+ "#{@path_pod[:doc]}/#{f}"
+ )
+ else
+ STDERR.puts \
+ %{\t*WARN* did not find image - } \
+ + %{"#{@opt.base_path}#{doc_import_dir}/#{f}" } \
+ + %{[#{__FILE__}:#{__LINE__}]}
+ end
+ end
+ end
+ end
+ def language_versions
+ x=@env.document_language_versions_found #check multiple document language versions (param not used)
+ doc_import_dir=@opt.sub_location
+ if x[:f] \
+ and x[:f].length > 0 #store multiple document language versions, sisupod
+ x[:f].each do |f|
+ FileUtils::mkdir_p(@path_pod[:doc]) \
+ unless FileTest.directory?(@path_pod[:doc])
+ if f[:f] =~/\~(\S{2,3})\.ss[tm]$/
+ lng_f=$1
+ if @opt.lng == lng_f
+ if @opt.fno =~/\.ssm$/
+ if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}")
+ FileUtils::cp(
+ "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}",
+ "#{@path_pod[:doc]}/#{f[:n]}"
+ )
+ else
+ STDERR.puts \
+ %{\t*WARN* did not find - } \
+ + %{"#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" } \
+ + %{[#{__FILE__}:#{__LINE__}]}
+ end
+ else
+ if FileTest.file?("#{@opt.base_path}/#{f[:f]}")
+ cpy= :no
+ cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \
+ or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/
+ :yes
+ elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \
+ and @opt.f_pth[:lng_is] == 'en'
+ :yes
+ else :no
+ end
+ if cpy == :yes
+ FileUtils::cp(
+ "#{@opt.base_path}/#{f[:f]}",
+ "#{@path_pod[:doc]}/#{f[:n]}"
+ )
+ end
+ else
+ STDERR.puts \
+ %{\t*WARN* did not find - } \
+ + %{"#{@opt.base_path}/#{f[:f]}" } \
+ + %{[#{__FILE__}:#{__LINE__}]}
+ end
+ end
+ end
+ else
+ if @opt.fno =~/\.ssm$/
+ if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}")
+ FileUtils::cp_r(
+ "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}",
+ "#{@path_pod[:doc]}/#{f[:n]}"
+ )
+ else
+ STDERR.puts \
+ %{\t*WARN* did not find - } \
+ + %{"#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" } \
+ + %{[#{__FILE__}:#{__LINE__}]}
+ end
+ else
+ if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}")
+ cpy= :no
+ cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \
+ or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/
+ :yes
+ elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \
+ and @opt.f_pth[:lng_is] == 'en'
+ :yes
+ else :no
+ end
+ if cpy == :yes
+ FileUtils::cp(
+ "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}",
+ "#{@path_pod[:doc]}/#{f[:n]}"
+ )
+ end
+ else
+ STDERR.puts \
+ %{\t*WARN* did not find - } \
+ + %{"#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" } \
+ + %{[#{__FILE__}:#{__LINE__}]}
+ end
+ end
+ end
+ end
+ end #NB not all possibilies met, revisit, also in case of composite file may wish to add README
+ end
+ def directories
+ SiSU_Env::InfoEnv.new.sisupod_v4(@opt)
+ end
+ end
+end
+__END__
+question?: should you permit the packing of multiple documents in single .xz ?
+
+ open @opt.fns, parse file
+ extract from file content:
+ images and copy each image from whatever image source to _sisu/sisupod/sisu/_sisu/image
+
+ remove previously existing contents of _/sisu/sisupod &
+ make directory structure:
+
+v3 -->
+ _sisu
+ sisupod
+ doc
+ manifest.txt
+ en/content.sst [file content]
+ fr/content.sst
+ _sisu
+ conf
+ image (ln -s ../../image)
+ audio (ln -s ../../audio)
+ video (ln -s ../../video)
+ image [all images for specific document gathered here]
+ audio
+ video
+
+v2 -->
+ _sisu
+ sisupod
+ content.sst [file content]
+ filename.sst [link to content.sst]
+ _sisu/
+ image/ [all images for specific document gathered here]
+
+sisu
+ _sisu
+ sisurc.yml
+ convert/
+ standard_terms/
+ image
+ processing
+ ao/
+ tex/
+ texinfo/
+ tune/
+ sisupod
+
+special case
+
+composite file (master), e.g.
+SiSU.ssm
+#+END_SRC
+
+* document header
+
+#+NAME: sisu_document_header
+#+BEGIN_SRC text
+encoding: utf-8
+- Name: SiSU
+
+ - Description: documents, structuring, processing, publishing, search
+ src
+
+ - Author: Ralph Amissah
+ <ralph.amissah@gmail.com>
+
+ - Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019,
+ 2020, 2021, 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 <http://www.gnu.org/licenses/>.
+
+ If you have Internet connection, the latest version of the GPL should be
+ available at these locations:
+ <http://www.fsf.org/licensing/licenses/gpl.html>
+ <http://www.gnu.org/licenses/gpl.html>
+
+ <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
+
+ - SiSU uses:
+ - Standard SiSU markup syntax,
+ - Standard SiSU meta-markup syntax, and the
+ - Standard SiSU object citation numbering and system
+
+ - Homepages:
+ <http://www.sisudoc.org>
+
+ - Git
+ <https://git.sisudoc.org/projects/>
+ <https://git.sisudoc.org/projects/?p=software/sisu.git;a=summary>
+ <https://git.sisudoc.org/projects/?p=markup/sisu-markup-samples.git;a=summary>
+#+END_SRC