Class: CML::Tags::Radio

Inherits:
CML::Tag show all
Defined in:
lib/cml/tags/radio.rb

Constant Summary collapse

Template =
<<-HTML.freeze
<label><input name="{{name}}" type="radio" value="{{value}}" class="{{classes}}" {{checked}}/> {{label}}</label>
HTML

Instance Attribute Summary

Attributes inherited from CML::Tag

#attrs, #cml, #tag

Instance Method Summary collapse

Methods inherited from CML::Tag

#children, #classes, #convert, #gold=, #gold?, #initialize, #instructions, #label, #legend, #name, #prefix, #raw_label, #to_html, #to_liquid, #to_s, #validate?, #validations, #wrapper_classes

Constructor Details

This class inherits a constructor from CML::Tag

Instance Method Details

#dataObject



21
22
23
24
25
26
# File 'lib/cml/tags/radio.rb', line 21

def data
  super.merge({
    "checked" => @attrs["checked"] ? "checked=\"checked\"" : "",
    "label" => @attrs["label"].to_s
  })
end

#grouped?Boolean

Radios should always be grouped, but for consistency with checkboxes, we check

Returns:

  • (Boolean)


9
10
11
# File 'lib/cml/tags/radio.rb', line 9

def grouped?
  @cml.parent && @cml.parent.name == "radios"
end

#valueObject



17
18
19
# File 'lib/cml/tags/radio.rb', line 17

def value
  (@attrs["value"] || @attrs["label"]).to_s
end

#wrapper(parsed) ⇒ Object



13
14
15
# File 'lib/cml/tags/radio.rb', line 13

def wrapper(parsed)
  grouped? ? parsed : super
end