Class: SiSU_SStm_AO_SStm::Source::Scroll
- Inherits:
-
SiSU_SStm_AO_SStm::Source
- Object
- SiSU_SStm_AO_SStm::Source
- SiSU_SStm_AO_SStm::Source::Scroll
- Includes:
- SiSU_Po4aUtils
- Defined in:
- lib/sisu/src_po4a_sst_ao_sst.rb
Constant Summary collapse
- @@endnotes =
{ para: [], end: [] }
Instance Method Summary collapse
- #auto_translate?(set_to = nil) ⇒ Boolean
-
#auto_translation(src_txt, markup = :src) ⇒ Object
check for an appropriate request flag.
-
#block(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document.
- #br ⇒ Object
-
#code(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document.
- #compare_structure_src_trn(data_src, data_trn, todo) ⇒ Object
-
#group(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document.
-
#heading(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document.
-
#idx(dob_src = '') ⇒ Object
% used for book index but broken as original markup lost, already abstracted, fix.
- #idx_markup(idx) ⇒ Object
-
#initialize(fn, data_src, data_master, md_src, md_master, wrap_width) ⇒ Scroll
constructor
A new instance of Scroll.
-
#markup(dob) ⇒ Object
[dob_src,dob_trn].
-
#para(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document.
- #pot_data(dob_src = '', notes_s) ⇒ Object
- #pot_metadata_src ⇒ Object
- #pot_metadata_src_trn ⇒ Object
- #pot_structure ⇒ Object
- #pot_structure_wrap(orig, trans, indent = 0, hang = 0) ⇒ Object
- #publish(fn, pot) ⇒ Object
- #songsheet ⇒ Object
-
#table(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document.
-
#verse(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document.
- #wrap_endnotes(orig_notes = '', trn_notes = '') ⇒ Object
Methods inherited from SiSU_SStm_AO_SStm::Source
#process_file, #read_process_src_files, #read_setup, #wrap_width_set
Methods included from SiSU_Response
#answer?, #available_selections_, #query, #response?, #response_short, #response_strict, #selection_options, #selections_available_
Methods included from SiSU_Languages_Selected
#language, #sisu_languages_available, #source_language_selected_str, #translation_languages_available, #translation_languages_selected, #translation_languages_selected_str, #translation_languages_selected_that_are_available, #translation_languages_selected_that_are_available_str
Methods included from SiSU_Object_Munge
#block_, #clean_text, #code_, #extract_endnotes, #footnotes_inline, #footnotes_ref_and_note, #i_ao_o_src_markup_restore, #i_ao_o_strip_markup, #i_src_o_strip_markup, #object_marks, #objects, #src_markup, #textface_marks, #textface_marks_po4a
Constructor Details
#initialize(fn, data_src, data_master, md_src, md_master, wrap_width) ⇒ Scroll
Returns a new instance of Scroll.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 178 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 |
Instance Method Details
#auto_translate?(set_to = nil) ⇒ Boolean
401 402 403 404 405 406 407 408 409 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 401 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 |
#auto_translation(src_txt, markup = :src) ⇒ Object
check for an appropriate request flag
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 410 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 |
#block(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 543 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 |
#br ⇒ Object
195 196 197 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 195 def br (@md.opt.selections.str =~/--dos/) ? "\r\n" : "\n" # --unix end |
#code(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document
595 596 597 598 599 600 601 602 603 604 605 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 595 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 |
#compare_structure_src_trn(data_src, data_trn, todo) ⇒ Object
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 672 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 |
#group(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 560 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 |
#heading(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 435 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 |
#idx(dob_src = '') ⇒ Object
% used for book index but broken as original markup lost, already abstracted, fix
659 660 661 662 663 664 665 666 667 668 669 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 659 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 |
#idx_markup(idx) ⇒ Object
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 619 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 |
#markup(dob) ⇒ Object
- dob_src,dob_trn
799 800 801 802 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 799 def markup(dob) dob,notes=objects.textface_marks_po4a(dob,:separate) [dob,notes] end |
#para(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 466 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 |
#pot_data(dob_src = '', notes_s) ⇒ Object
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 764 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 |
#pot_metadata_src ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 253 def @po4a_identify_type='type: SiSU doc' #'type: Plain text' =SiSU_Metadata::Summary.new(@md_src) w=[] w << [ ..title.main, ..title.sub, ..title.edition, ..title.note, ..title.short, ..title.language, ..title.language_char, ] w << [ ..creator.head, ..creator., ..creator.contributor, ..creator.illustrator, ..creator.photographer, ..creator.translator, ..creator.audio, ..creator.digitized_by, ..creator.prepared_by, ] w << [ ..rights.head, ..rights.copyright.text, ..rights.copyright.translation, ..rights.copyright.illustrations, ..rights.copyright.photographs, ..rights.copyright.digitization, ..rights.copyright.audio, ..rights.license, ] w << [ ..classify.head, ..classify.subject, ..classify.topic_register, ..classify.loc, ..classify.dewey, ] w << [ ..date.head, ..date.added_to_site, ..date.available, ..date.created, ..date.issued, ..date.modified, ..date.published, ..date.valid, ] w << [ ..make.language, ..make.headings, ..make.num_top, ..make.breaks, ..make.emphasis, ..make.bold, ..make.italics, ..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 |
#pot_metadata_src_trn ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 327 def #@po4a_identify_type='type: Plain text' =SiSU_Metadata::Summary.new(@md_src) w=[] w << [ ..title.main, ..title.sub, ..title.edition, ..title.note, ..title.short, ..title.language, ..title.language_char, ] w << [ ..creator.head, ..creator., ..creator.contributor, ..creator.illustrator, ..creator.photographer, ..creator.translator, ..creator.audio, ..creator.digitized_by, ..creator.prepared_by, ] w << [ ..rights.head, ..rights.copyright.text, ..rights.copyright.translation, ..rights.copyright.illustrations, ..rights.copyright.photographs, ..rights.copyright.digitization, ..rights.copyright.audio, ..rights.license, ] w << [ ..classify.head, ..classify.subject, ..classify.topic_register, ..classify.loc, ..classify.dewey, ] w << [ ..date.head, ..date.added_to_site, ..date.available, ..date.created, ..date.issued, ..date.modified, ..date.published, ..date.valid, ] w << [ ..make.language, ..make.headings, ..make.num_top, ..make.breaks, ..make.emphasis, ..make.bold, ..make.italics, ..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 |
#pot_structure ⇒ Object
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 434 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 |
#pot_structure_wrap(orig, trans, indent = 0, hang = 0) ⇒ Object
203 204 205 206 207 208 209 210 211 212 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 203 def pot_structure_wrap(orig,trans,indent=0,hang=0) SiSU_Po4aUtils::Wrap.new( @md, orig, trans, @wrap_width, indent, hang ) end |
#publish(fn, pot) ⇒ Object
803 804 805 806 807 808 809 810 811 812 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 803 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 |
#songsheet ⇒ Object
198 199 200 201 202 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 198 def songsheet fn=@fn pot=compare_structure_src_trn(@data_src,@data_master,@@todo) publish(fn,pot) end |
#table(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document
606 607 608 609 610 611 612 613 614 615 616 617 618 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 606 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 |
#verse(dob_src = '', notes_s = '', dob_trn = '', notes_t = '') ⇒ Object
% used to extract the structure of a document
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 577 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 |
#wrap_endnotes(orig_notes = '', trn_notes = '') ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/sisu/src_po4a_sst_ao_sst.rb', line 213 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 |