Module: Mullet::HTML::AttributeCommand

Included in:
MessageAttributeCommand, ScopeAttributeCommand
Defined in:
lib/mullet/html/attribute_command.rb

Overview

Operation to set attribute value. Classes including this module are expected to respond to the get_value method returning the attribute value to set.

Instance Method Summary collapse

Instance Method Details

#execute(render_context, attributes) ⇒ Object

Sets attribute in the attributes collection.

Parameters:



24
25
26
27
28
29
30
31
32
33
# File 'lib/mullet/html/attribute_command.rb', line 24

def execute(render_context, attributes)
  value = get_value(render_context)
  if value == Scope::NOT_FOUND || value == nil
    # Value not found.  Do not render the attribute.
    attributes.delete(@attribute_name)
  else
    escaped_value = render_context.escape_xml(value)
    attributes.store(@attribute_name, escaped_value)
  end
end

#initialize(attribute_name) ⇒ Object

Constructor

Parameters:

  • attribute_name (Symbol)

    name of attribute this command sets



14
15
16
# File 'lib/mullet/html/attribute_command.rb', line 14

def initialize(attribute_name)
  @attribute_name = attribute_name
end