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

#even, #filename, #odd

Instance Method Summary collapse

Methods inherited from JstlHandler

#directive_format, #directive_pattern, #initialize, #mapping_pattern

Methods included from JstlExpressionParser

#parse_expr_str, #parse_expr_str!

Methods inherited from Handler

#_elem_info_table, #_import_element_info_from_handler, #apply_rulesets, #extract, get_class, #get_element_info, #get_ruleset, #handle_directives, #initialize, register_class, #register_element_info

Methods included from Expander

#expand_element_info, #expand_statement, #expand_statements, #get_element_info, #get_ruleset

Methods included from Assertion

assert

Methods included from HandlerHelper

#_last_stmt_kind, #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, #error_if_empty_tag, #error_when_last_stmt_is_not_if, #etag_stmt, #expand_attr_vars, #expand_attr_vars_in_native_expr, #expand_attr_vars_in_native_stmt, #stag_stmt, #wrap_content_with_native_stmt, #wrap_element_with_native_stmt

Methods included from ConvertErrorHelper

#convert_error

Constructor Details

This class inherits a constructor from Kwartz::JstlHandler

Instance Method Details

#handle(directive, elem_info, 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
71
# File 'lib/kwartz/binding/struts.rb', line 25

def handle(directive, elem_info, stmt_list)
  ret = super
  return ret if ret

  d_name = directive.name
  d_arg  = directive.arg
  d_str  = directive.str
  e = elem_info

  case d_name

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

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

  end #case
  return true

end