class SiSU_Po4aUtils::Wrap

Public Class Methods

new(md,orig='',trans='',is_desc='',n_char_max=76,n_indent=0,n_hang=nil) click to toggle source
# File lib/sisu/src_po4a_shelf_set.rb, line 57
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

Public Instance Methods

array_wrap() click to toggle source
# File lib/sisu/src_po4a_shelf_set.rb, line 163
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
line_wrap() click to toggle source
# File lib/sisu/src_po4a_shelf_set.rb, line 66
    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
line_wrap_endnote() click to toggle source
# File lib/sisu/src_po4a_shelf_set.rb, line 159
def line_wrap_endnote
  @n_indent,@n_hang=4,2
  line_wrap
end
line_wrap_indent1() click to toggle source
# File lib/sisu/src_po4a_shelf_set.rb, line 155
def line_wrap_indent1
  @n_indent,@n_hang=2,2
  line_wrap
end
no_line_wrap_block() click to toggle source
# File lib/sisu/src_po4a_shelf_set.rb, line 129
    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