Class: MakeTag

Inherits:
Object
  • Object
show all
Defined in:
lib/tags2w.rb

Instance Method Summary collapse

Instance Method Details

#make_it(lines) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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
253
254
255
256
257
258
259
260
261
262
# File 'lib/tags2w.rb', line 187

def make_it(lines)
  @lvl_dp= 0
  @blk_ar= Array.new(20,[''])  #level, space
  lines.each_with_index do |l,i|
    dbg=''
    if /( *)\<%[-]? *(\w+)[(]?(.*?)[)]? *do *\|(.*?)\|/ =~ l
      @lvl_dp += 1
  if $3=='.each'
        blk= ["<cmd class=\"#{$3[1,99]}\" att=\"#{$2};#{$4}\">","<form_for>"]
  else
        blk= ["<cmd class=\"#{$2}\" att=\"#{$3};#{$4}\">","<form_for>"]
  end
      dbg<< "#{$1}#{blk[0]}"
      @blk_ar[@lvl_dp]= blk
    elsif /( *)\<%[-]? *(\w+)[(]?(.*?)[)]? *do *$/ =~ l
      @lvl_dp += 1
      blk= ["<cmd class=\"#{$2}\" att=\"#{$3}\">","<form_tag>"]
      dbg<< "#{$1}#{blk[0]}"
      @blk_ar[@lvl_dp]= blk
    elsif /( *)\<%[-]? *(.*? ) *do *\|(.*?)\|/ =~ l
      spc= $1
      cmd= $2
      att= $3
      #cmd=$2.split('.')[0]
      att= $3.lstrip.gsub(/\-$/,'')
      if cmd.gsub!(/.each /,'')
        blk= ["<cmd class=\"each\" att=\"#{cmd};#{att}\">" ,'<each>']  
      elsif cmd.gsub!(/.each_with_index /,'')
        blk= ["<cmd class=\"each2\" att=\"#{cmd};#{att}\">",'<each2>'] 
      else
        blk= ["<cmd class=\"#{cmd}\" att=\"#{att}\">","<#{cmd}>"]
      end
      @lvl_dp += 1
      @blk_ar[@lvl_dp]= blk
      dbg<< "#{spc}#{blk[0]}"
    elsif /( *)\<%[-]? *([\w_]+) *(.*?)[-]?%>/ =~ l
      spc= $1
      cmd= $2
      att= $3.lstrip.gsub(/\-$/,'')
      if %w[unless if for].index(cmd)
        @lvl_dp += 1
        blk= ["<cmd class=\"#{cmd}\" att=\"#{att}\">","<#{cmd}>"]
        dbg<< "#{spc}#{blk[0]}"
        @blk_ar[@lvl_dp]= blk
      elsif %w[elsif else].index(cmd)
        blk= ["</cmd><cmd class=\"#{cmd}\" att=\"#{att}\">","<#{cmd}>"]
        dbg<< "#{spc}#{blk[0]}"
        @blk_ar[@lvl_dp]= blk
      elsif %w[end].index(cmd)
        blk= ["</cmd>"]  
        dbg<< "#{spc}#{blk[0]}"
        @lvl_dp -= 1
      end
    elsif /( *)\<%=(.*?)%>/ =~ l
      while /( *)\<%=(.*?)%>/ =~ l do 
        l= l.sub(/( *)\<%=(.*?)%>/,"#{spc}<w2code_equ>#{$2}</w2code_equ>")
      end
      dbg<< l 
    elsif /( *)\<\!\-\-(.*)\-\-\>/ =~ l
      dbg<< "#{spc}<w2comment>#{$2}</w2comment>"
    elsif /( *)\<\!\-\-(.*)/ =~ l
      @lvl_dp += 1
      blk= ["<w2comment>#{$2}",'<comment>']
      @blk_ar[@lvl_dp]= blk
      dbg<< "#{spc}#{blk[0]}"
    elsif /(.*)\-\-\>/ =~ l
      blk= ["#{$1}</w2comment>"]  
      dbg<< "#{spc}#{blk[0]}"
      @lvl_dp -= 1
    end
    if dbg!=''
      #puts dbg 
      lines[i]= dbg
    end
  end
end