Class: SiSU_Po4aUtils::Wrap

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/src_po4a_shelf_set.rb,
lib/sisu/src_po4a_sst_ao_sst_set.rb

Instance Method Summary collapse

Constructor Details

#initialize(md, orig = '', trans = '', n_char_max = 76, n_indent = 0, n_hang = nil) ⇒ Wrap

Returns a new instance of Wrap.



57
58
59
60
61
62
63
64
65
# 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

Instance Method Details

#array_wrapObject



163
164
165
166
167
168
169
170
171
# 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_wrapObject

@po4a_identify_type=‘type: Plain text’



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# 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_endnoteObject



159
160
161
162
# 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_indent1Object



155
156
157
158
# 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_blockObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# 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