Class: SiSU_Po4aUtils::Wrap
- Inherits:
-
Object
- Object
- SiSU_Po4aUtils::Wrap
- Defined in:
- lib/sisu/src_po4a_shelf_set.rb,
lib/sisu/src_po4a_sst_ao_sst_set.rb
Instance Method Summary collapse
- #array_wrap ⇒ Object
-
#initialize(md, orig = '', trans = '', n_char_max = 76, n_indent = 0, n_hang = nil) ⇒ Wrap
constructor
A new instance of Wrap.
-
#line_wrap ⇒ Object
@po4a_identify_type=‘type: Plain text’.
- #line_wrap_endnote ⇒ Object
- #line_wrap_indent1 ⇒ Object
- #no_line_wrap_block ⇒ Object
Constructor Details
#initialize(md, orig = '', trans = '', n_char_max = 76, n_indent = 0, n_hang = nil) ⇒ Wrap
Returns a new instance of Wrap.
59 60 61 62 63 64 65 66 67 |
# File 'lib/sisu/src_po4a_shelf_set.rb', line 59 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_wrap ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'lib/sisu/src_po4a_shelf_set.rb', line 165 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 ⇒ Object
@po4a_identify_type=‘type: Plain text’
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 129 130 |
# File 'lib/sisu/src_po4a_shelf_set.rb', line 68 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 ⇒ Object
161 162 163 164 |
# File 'lib/sisu/src_po4a_shelf_set.rb', line 161 def line_wrap_endnote @n_indent,@n_hang=4,2 line_wrap end |
#line_wrap_indent1 ⇒ Object
157 158 159 160 |
# File 'lib/sisu/src_po4a_shelf_set.rb', line 157 def line_wrap_indent1 @n_indent,@n_hang=2,2 line_wrap end |
#no_line_wrap_block ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/sisu/src_po4a_shelf_set.rb', line 131 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 |