Class: HtmlCommandHandler
- Inherits:
-
Object
- Object
- HtmlCommandHandler
- Includes:
- CommandHandler
- Defined in:
- lib/xml_command_handlers/html_command_handler.rb
Instance Method Summary collapse
- #append_id_and_class_attributes(command, attributes) ⇒ Object
- #can_handle?(parent, command_symbol, *args, &block) ⇒ Boolean
- #do_handle(parent, command_symbol, *args, &block) ⇒ Object
- #parse_tag_name(command) ⇒ Object
Instance Method Details
#append_id_and_class_attributes(command, attributes) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/xml_command_handlers/html_command_handler.rb', line 29 def append_id_and_class_attributes(command, attributes) class_only_match = command.match("__.+").to_s if class_only_match.length > 0 class_value = class_only_match[2, class_only_match.length] else match_data = command.match("_[^_]+") return unless match_data match = match_data.to_s id_value = match[1, match.length] if match.length > 0 attributes[:id] = id_value if id_value match2 = match_data.post_match.match("_[^_]+").to_s if match_data.post_match class_value = match2[1, match2.length] if match2.length > 0 end attributes[:class] = class_value if class_value end |
#can_handle?(parent, command_symbol, *args, &block) ⇒ Boolean
7 8 9 10 |
# File 'lib/xml_command_handlers/html_command_handler.rb', line 7 def can_handle?(parent, command_symbol, *args, &block) (parent == nil or parent.is_a?(Node)) and (args.size == 0 or ((args.size == 1) and ((args[0].is_a?(Hash)) or (args[0].is_a?(Hash))))) end |
#do_handle(parent, command_symbol, *args, &block) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/xml_command_handlers/html_command_handler.rb', line 12 def do_handle(parent, command_symbol, *args, &block) attributes = Hash.new attributes = args[0] if (args.size == 1) append_id_and_class_attributes(command_symbol.to_s, attributes) tag_name = parse_tag_name(command_symbol.to_s) Node.new(parent, tag_name, attributes, &block) end |
#parse_tag_name(command) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/xml_command_handlers/html_command_handler.rb', line 20 def parse_tag_name(command) match_data = command.match("_") if (match_data.to_a.size > 0) command.match("_").pre_match else command end end |