Class: Kwartz::StrutsHandler

Inherits:
JstlHandler show all
Defined in:
lib/kwartz/binding/struts.rb

Overview

experimental

directive handler for Struts

Constant Summary

Constants inherited from JstlHandler

JstlHandler::JSTL_DIRECTIVE_FORMAT, JstlHandler::JSTL_DIRECTIVE_PATTERN, JstlHandler::JSTL_MAPPING_PATTERN

Instance Attribute Summary

Attributes inherited from Handler

#converter, #even, #filename, #odd

Instance Method Summary collapse

Methods inherited from JstlHandler

#directive_format, #directive_pattern, #initialize, #mapping_pattern

Methods inherited from Handler

#_elem_info_table, #_import_element_info_from_handler, #extract, get_class, #get_element_info, #get_element_ruleset, #initialize, register_class

Methods included from ElementExpander

#expand_element_info, #expand_statement, #get_element_info, #get_element_ruleset

Methods included from Assertion

assert

Methods included from StatementHelper

#add_foreach_stmts, #add_native_code, #add_native_expr_with_default, #build_print_args, #build_print_expr_stmt, #build_print_stmt, #create_text_print_stmt, #etag_stmt, #stag_stmt, #wrap_content_with_native_stmt, #wrap_element_with_native_stmt

Methods included from ConverterHelper

#_last_stmt_kind, #convert_error, #error_if_empty_tag, #error_when_last_stmt_is_not_if, #include_properties

Constructor Details

This class inherits a constructor from Kwartz::JstlHandler

Instance Method Details

#handle(directive_name, directive_arg, directive_str, stag_info, etag_info, cont_stmts, attr_info, append_exprs, stmt_list) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/kwartz/binding/struts.rb', line 25

def handle(directive_name, directive_arg, directive_str, stag_info, etag_info, cont_stmts, attr_info, append_exprs, stmt_list)
  ret = super
  return ret if ret

  d_name = directive_name
  d_arg  = directive_arg
  d_str  = directive_str

  case directive_name

  when :struts
    case tag = stag_info.tagname
    when 'input'  ;  tag = attr_info['type'] || 'text'  ; attr_info.delete('type')
    when 'a'      ;  tag = 'link'
    when 'script' ;  tag = 'javascript'
    end
    tag == :struts   and raise convert_error("#{d_str}: unknown directive.", stag_info.linenum)
    return self.handle(tag.intern, d_arg, directive_str, stag_info, etag_info,
                       cont_stmts, attr_info, append_exprs, stmt_list)

  else
    convert_mapping = {
      'name'=>'property',
      'class'=>'cssClass'
    }
    convert_mapping.each do |html_aname, struts_aname|
      next unless attr_info[html_aname]
      attr_info[struts_aname] = attr_info[html_aname]
      attr_info.delete(html_aname)
    end
    opts = eval "_evaluate_options(#{d_arg})"
    opts.each do |name, value|
      attr_info[name.to_s] = value.is_a?(Symbol) ? "${#{value}}" : value
    end
    tagname = "html:#{d_name}"
    stag_info.tagname = tagname
    etag_info.tagname = tagname if etag_info
    stag_info.is_empty = true   if !etag_info
    stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
    stmt_list.concat(cont_stmts)
    stmt_list << build_print_stmt(etag_info, nil, nil) if etag_info

  end #case
  return true

end