Module: Kwartz::StatementHelper

Included in:
Converter, Handler, HandlerArgument
Defined in:
lib/kwartz/converter.rb

Instance Method Summary collapse

Instance Method Details

#add_foreach_stmts(stmt_list, handler_arg, foreach_code, endforeach_code, content_only, counter, toggle, init_code, incr_code, toggle_code) ⇒ Object



389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/kwartz/converter.rb', line 389

def add_foreach_stmts(stmt_list, handler_arg, foreach_code, endforeach_code,
                      content_only, counter, toggle, init_code, incr_code, toggle_code)
  arg = handler_arg
  stmt_list << stag_stmt(arg)                   if content_only
  start_code.split(/\n/).each do |code|
    stmt_list << NativeStatement.new(code, kind)
  end if start_code
  stmt_list << stag_stmt(arg)                   if !content_only
  stmt_list.concat(arg.cont_stmts)
  stmt_list << etag_stmt(arg)                   if !content_only
  end_code.split(/\n/).each do |code|
    stmt_list << NativeStatement.new(code, kind)
  end
  stmt_list << etag_stmt(arg)                   if content_only
end

#add_native_code(stmt_list, code, kind) ⇒ Object



362
363
364
365
366
367
368
# File 'lib/kwartz/converter.rb', line 362

def add_native_code(stmt_list, code, kind)
  if code.is_a?(String)
    stmt_list << NativeStatement.new(code, kind)
  elsif code.is_a?(Array)
    stmt_list.concat(code.collect {|line| NativeStatement.new(line, kind)})
  end
end

#add_native_expr_with_default(stmt_list, handler_arg, expr_code, flag_escape, if_code, else_code, endif_code) ⇒ Object



406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/kwartz/converter.rb', line 406

def add_native_expr_with_default(stmt_list, handler_arg,
                                 expr_code, flag_escape,
                                 if_code, else_code, endif_code)
  arg = handler_arg
  stmt_list << stag_stmt(arg)
  stmt_list << NativeStatement.new_without_newline(if_code, :if)
  stmt_list << PrintStatement.new([ NativeExpression.new(expr_code, flag_escape) ])
  stmt_list << NativeStatement.new_without_newline(else_code, :else)
  stmt_list.concat(arg.cont_stmts)
  stmt_list << NativeStatement.new_without_newline(endif_code, :else)
  stmt_list << etag_stmt(arg)
end

#build_print_args(taginfo, attr_info, append_exprs) ⇒ Object

create array of String and NativeExpression for PrintStatement



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/kwartz/converter.rb', line 290

def build_print_args(taginfo, attr_info, append_exprs)
  return [] if taginfo.tagname.nil?
  #if taginfo.tagname.nil?
  #  if (!attr_info || attr_info.empty?) && (!append_exprs || append_exprs.empty?)
  #    return []
  #  else
  #    taginfo.tagname = 'span'
  #  end
  #end
  unless attr_info || append_exprs
    return [taginfo.tag_text]
  end
  args = []
  t = taginfo
  sb = "#{t.head_space}<#{t.is_etag ? '/' : ''}#{t.tagname}"
  attr_info.each do |space, aname, avalue|
    sb << "#{space}#{aname}=\""
    if avalue.is_a?(NativeExpression)
      args << sb     # TextExpression.new(sb)
      args << avalue
      sb = ''
    else
      sb << avalue
    end
    sb << '"'
  end if attr_info
  if append_exprs && !append_exprs.empty?
    unless sb.empty?
      args << sb     # TextExpression.new(sb)
      sb = ''
    end
    args.concat(append_exprs)
  end
  sb << "#{t.extra_space}#{t.is_empty ? '/' : ''}>#{t.tail_space}"
  args << sb         # TextExpression.new(sb)
  return args
end

#build_print_expr_stmt(native_expr, stag_info, etag_info) ⇒ Object

create PrintStatement for NativeExpression



337
338
339
340
341
342
343
344
345
# File 'lib/kwartz/converter.rb', line 337

def build_print_expr_stmt(native_expr, stag_info, etag_info)
  head_space = (stag_info || etag_info).head_space
  tail_space = (etag_info || stag_info).tail_space
  args = []
  args << head_space if head_space    # TexExpression.new(head_space)
  args << native_expr
  args << tail_space if tail_space    # TextExpression.new(tail_space)
  return PrintStatement.new(args)
end

#build_print_stmt(taginfo, attr_info, append_exprs) ⇒ Object

create PrintStatement for TagInfo



330
331
332
333
# File 'lib/kwartz/converter.rb', line 330

def build_print_stmt(taginfo, attr_info, append_exprs)
  args = build_print_args(taginfo, attr_info, append_exprs)
  return PrintStatement.new(args)
end

#create_text_print_stmt(text) ⇒ Object

create print statement from text



283
284
285
286
# File 'lib/kwartz/converter.rb', line 283

def create_text_print_stmt(text)
  return PrintStatement.new([text])
  #return PritnStatement.new([TextExpression.new(text)])
end

#etag_stmt(handler_arg) ⇒ Object

build print statemetn of end-tag



356
357
358
359
# File 'lib/kwartz/converter.rb', line 356

def etag_stmt(handler_arg)
  arg = handler_arg
  return build_print_stmt(arg.etag_info, nil, nil)
end

#stag_stmt(handler_arg) ⇒ Object

build print statement of start-tag



349
350
351
352
# File 'lib/kwartz/converter.rb', line 349

def stag_stmt(handler_arg)
  arg = handler_arg
  return build_print_stmt(arg.stag_info, arg.attr_info, arg.append_exprs)
end

#wrap_content_with_native_stmt(stmt_list, handler_arg, start_code, end_code, kind = nil) ⇒ Object



380
381
382
383
384
385
386
# File 'lib/kwartz/converter.rb', line 380

def wrap_content_with_native_stmt(stmt_list, handler_arg, start_code, end_code, kind=nil)
  stmt_list << stag_stmt(handler_arg)
  add_native_code(stmt_list, start_code, kind)
  stmt_list.concat(handler_arg.cont_stmts)
  add_native_code(stmt_list, end_code, kind)
  stmt_list << etag_stmt(handler_arg)
end

#wrap_element_with_native_stmt(stmt_list, handler_arg, start_code, end_code, kind = nil) ⇒ Object



371
372
373
374
375
376
377
# File 'lib/kwartz/converter.rb', line 371

def wrap_element_with_native_stmt(stmt_list, handler_arg, start_code, end_code, kind=nil)
  add_native_code(stmt_list, start_code, kind)
  stmt_list << stag_stmt(handler_arg)
  stmt_list.concat(handler_arg.cont_stmts)
  stmt_list << etag_stmt(handler_arg)
  add_native_code(stmt_list, end_code, kind)
end