Module: Kwartz::Expander

Includes:
Assertion
Included in:
Handler
Defined in:
lib/kwartz/converter.rb

Overview

(abstract) expand ExpandStatement and ElementInfo

Handler class includes this module.

Instance Method Summary collapse

Methods included from Assertion

assert

Instance Method Details

#expand_element_info(elem_info, stmt_list, content_only = false) ⇒ Object

expand ElementInfo



486
487
488
489
490
491
492
493
# File 'lib/kwartz/converter.rb', line 486

def expand_element_info(elem_info, stmt_list, content_only=false)
  expand_statements(elem_info.before, stmt_list, elem_info) if elem_info.before
  stmts = content_only ? [ ExpandStatement.new(:cont) ] : elem_info.logic
  stmts.each do |stmt|
    expand_statement(stmt, stmt_list, elem_info)
  end
  expand_statements(elem_info.after, stmt_list, elem_info) if elem_info.after
end

#expand_statement(stmt, stmt_list, elem_info) ⇒ Object

expand ExpandStatement



505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/kwartz/converter.rb', line 505

def expand_statement(stmt, stmt_list, elem_info)

  if stmt.is_a?(NativeStatement)
    if elem_info
      native_stmt = expand_attr_vars_in_native_stmt(stmt, elem_info.attr_info)
    else
      native_stmt = stmt
    end
    stmt_list << native_stmt
    return
  end

  if ! stmt.is_a?(ExpandStatement)
    stmt_list << stmt
    return
  end

  e = elem_info

  ## remove dummy <span> tag
  if @delspan && elem_info && elem_info.dummy_span_tag?('span')
    #e.stag_info.tagname = e.etag_info.tagname = nil
    e.stag_info.clear_as_dummy_tag()
    e.etag_info.clear_as_dummy_tag()
  end

  case stmt.kind

  when :stag
    assert unless elem_info
    if e.stag_expr
      assert unless e.stag_expr.is_a?(NativeExpression)
      stmt_list << build_print_expr_stmt(e.stag_expr, e.stag_info, nil, e.attr_info)
    else
      stmt_list << build_print_stmt(e.stag_info, e.attr_info, e.append_exprs)
    end

  when :etag
    assert unless elem_info
    if e.etag_expr
      assert unless e.etag_expr.is_a?(NativeExpression)
      stmt_list << build_print_expr_stmt(e.etag_expr, nil, e.etag_info, e.attr_info)
    elsif e.etag_info    # e.etag_info is nil when <br>, <input>, <hr>, <img>, <meta>
      stmt_list << build_print_stmt(e.etag_info, nil, nil)
    end

  when :cont
    if e.cont_expr
      assert unless e.cont_expr.is_a?(NativeExpression)
      #stmt_list << PrintStatement.new([e.cont_expr])
      native_expr = expand_attr_vars_in_native_expr(e.cont_expr, e.attr_info)
      stmt_list << PrintStatement.new([native_expr])
    else
      elem_info.cont_stmts.each do |cont_stmt|
        expand_statement(cont_stmt, stmt_list, nil)
      end
    end

  when :elem
    assert unless elem_info
    if e.elem_expr
      assert unless e.elem_expr.is_a?(NativeExpression)
      stmt_list << build_print_expr_stmt(e.elem_expr, e.stag_info, e.etag_info, e.attr_info)
    else
      stmt.kind = :stag
      expand_statement(stmt, stmt_list, elem_info)
      stmt.kind = :cont
      expand_statement(stmt, stmt_list, elem_info)
      stmt.kind = :etag
      expand_statement(stmt, stmt_list, elem_info)
      stmt.kind = :elem
    end

  when :element, :content
    content_only = stmt.kind == :content
    #elem_info = @elements[stmt.name]
    elem_info = get_element_info(stmt.name)
    unless elem_info
      raise convert_error("element '#{stmt.name}' is not found.", nil)
    end
    expand_element_info(elem_info, stmt_list, content_only)

  else
    assert
  end #case
end

#expand_statements(stmts, stmt_list, elem_info) ⇒ Object

expand list of ExpandStatement



497
498
499
500
501
# File 'lib/kwartz/converter.rb', line 497

def expand_statements(stmts, stmt_list, elem_info)
  stmts.each do |stmt|
    expand_statement(stmt, stmt_list, elem_info)
  end
end

#get_element_info(name) ⇒ Object

(abstract) get ElementInfo



480
481
482
# File 'lib/kwartz/converter.rb', line 480

def get_element_info(name)
  not_implemented
end

#get_ruleset(selector) ⇒ Object

(abstract) get Ruleset



474
475
476
# File 'lib/kwartz/converter.rb', line 474

def get_ruleset(selector)
  not_implemented
end