Class: Kwartz::RailsHandler
- Inherits:
-
ErubyHandler
- Object
- Handler
- RubyHandler
- ErubyHandler
- Kwartz::RailsHandler
- Defined in:
- lib/kwartz/binding/rails.rb
Overview
directive handler for Rails
ex.
converter = Converter.new(pdata, decls, :handler=>RailsDirectiveHandler.new)
directive examples.
## text_field, password_field
<input type="text" size="10" maxsize="20" kw:d="text_field 'user', 'name'">
=> <%= text_field 'user', 'name', :size=>10, :maxsize=>20 %>
<input type="text" name="user[name]" kw:d="text_field :size=>10">
=> <%= text_field "user", "name", :size=>10 %>
<input type="text" id="user_name" size="10" kw:d="text_field">
=> <%= text_field "user", "name", :size=>10 %>
## link_to, link_to_remote
<a href="#" kw:d="link_to :action=>'list'">Show list</a>
=> <%= link_to 'Show list', :action=>'list' %>
## start_link_tag, start_remote_link_tag
<a href="#" kw:d="start_link_tag :action=>'list'">Show list</a>
=> <%= start_link_tag 'action'=>'list' %>Show list</a>
## mail_to
<a href="mail:[email protected]" kw:d="mail_to">admin</a>
=> <%= mail_to "[email protected]", "admin" %>
## form_tag
<form action="show" kw:d="form_tag :id=>2"> ... </form>
=> <%= form_tag :action=>"show", :id=>2 %> ... </form>
## submit_tag
<input type="submit" value="OK" kw:d="submit_tag">
=> <%= submit_tag "OK" %>
## text_area
<textarea cols="30" rows="3" id="user_desc" kw:d="text_area"></textarea>
=> <%= text_area "user", "desc", :cols=>30, :rows=>3 %>
<textarea cols="30" rows="3" name="user[desc]" kw:d="text_area"></textarea>
=> <%= text_area "user", "desc", :cols=>30, :rows=>3 %>
## hidden_field
<input type="hidden" id="user_id" kw:d="hidden_field">
=> <%= hidden_field "user", "id" %>
<input type="hidden" name="user[id]" kw:d="hidden_field">
=> <%= hidden_field "user", "id" %>
## check_box
<input type="checkbox" id="user_chk1" kw:d="check_box">
=> <%= check_box "user", "chk1" %>
<input type="checkbox" name="user[chk2]" kw:d="check_box">
=> <%= check_box "user", "chk2" %>
## radio_button
<input type="radio" id="user_radio" value="val1" kw:d="radio_button">
=> <%= radio_button "user", "radio", "val1" %>
<input type="radio" name="user[radio]" value="val2" kw:d="radio_button">
=> <%= radio_button "user", "radio", "val2" %>
## select, collection_select, country_select, time_zone_select, date_select, datetime_select
<select name="user[birth]" kw:d="date_select :start_year=>1970">
<option value="2000">2000</option>
</select>
=> <% date_select "user", "birth", :start_year=>1970 %>
## image_tag, link_image_to, link_to_image
<img src="foo.gif" alt="text" width="20" heigth="10" kw:d="image_tag :size=>'30x40'">
=> <%= image_tag "foo.gif", :alt=>"text", :size=>'30x40' %>
Constant Summary
Constants inherited from RubyHandler
Kwartz::RubyHandler::RUBY_DIRECTIVE_FORMAT, Kwartz::RubyHandler::RUBY_DIRECTIVE_PATTERN, Kwartz::RubyHandler::RUBY_MAPPING_PATTERN
Instance Attribute Summary
Attributes inherited from Handler
Instance Method Summary collapse
-
#handle(directive, elem_info, stmt_list) ⇒ Object
handle directives for rails.
Methods inherited from RubyHandler
#directive_format, #directive_pattern, #mapping_pattern
Methods included from RubyExpressionParser
#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
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
Constructor Details
This class inherits a constructor from Kwartz::Handler
Instance Method Details
#handle(directive, elem_info, stmt_list) ⇒ Object
handle directives for rails.
everytime return true whenever directive name is unknown.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/kwartz/binding/rails.rb', line 96 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 attr_info = e.attr_info ## parse 'name="user[name]"' or 'id="user_name"' case d_name.to_s when /(_|\A)radio_button\z/ add_directive_object_and_method_and_value(d_arg, attr_info) when /_field\z/, /_area\z/, /_box\z/, /(_|\A)select\z/, 'input' add_directive_object_and_method(d_arg, attr_info) end ## replace whole element, or only start tag replace_elem = d_name.to_s !~ /\Astart_/ case d_name when :text_field, :password_field, :hidden_field #add_directive_object_and_method(d_arg, attr_info) add_directive_integer_option(d_arg, 'size', attr_info['size']) add_directive_integer_option(d_arg, 'maxsize', attr_info['maxsize']) when :file_field #add_directive_object_and_method(d_arg, attr_info) add_directive_integer_option(d_arg, 'size', attr_info['size']) when :link_to, :link_to_remote, :link_to_unless_current add_directive_content_as_arg(d_arg, elem_info.cont_stmts) when :anchor, :anchor_remote replace_elem = false when :mail_to add_directive_content_as_arg(d_arg, elem_info.cont_stmts) add_directive_attr_as_arg(d_arg, attr_info, 'href') d_arg.sub!(/\A\'mailto:/, "'") when :form_tag, :start_form_tag add_directive_attr_as_option(d_arg, attr_info, 'action') replace_elem = false when :text_area #add_directive_object_and_method(d_arg, attr_info) add_directive_integer_option(d_arg, 'cols', attr_info['cols']) add_directive_integer_option(d_arg, 'rows', attr_info['rows']) when :submit_tag add_directive_attr_as_arg(d_arg, attr_info, 'value') when :submit_to_remote add_directive_attr_as_arg(d_arg, attr_info, 'value') add_directive_attr_as_arg(d_arg, attr_info, 'name') when :radio_button #add_directive_object_and_method_and_value(d_arg, attr_info) when :check_box #add_directive_object_and_method(d_arg, attr_info) when :select, :collection_select, :country_select, :time_zone_select, :date_select, :datetime_select #add_directive_object_and_method(d_arg, attr_info) when :image_tag, :link_image_to, :link_to_image add_directive_attr_as_arg(d_arg, attr_info, 'src') add_directive_str_option(d_arg, 'alt', attr_info['alt']) else end #case ## print_directive(elem_info, stmt_list, d_name, d_arg, replace_elem) return true # everytime return true end |