Class: CML::Tags::Checkbox

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

Constant Summary collapse

Template =
<<-HTML.freeze
{{default}}
<label><input name="{{name}}" type="checkbox" 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, #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



25
26
27
28
29
30
31
32
33
34
# File 'lib/cml/tags/checkbox.rb', line 25

def data
  default = ""
  if @attrs["default"]
    default = Hidden.new("<cml:hidden name=\"#{name}\" value=\"#{@attrs["default"]}\"/>", @opts).to_html
  end
  super.merge({ 
    "default" => default, 
    "checked" => @attrs["checked"] ? "checked=\"checked\"" : "",
    "label" => @attrs["label"].to_s})
end

#grouped?Boolean

Returns:

  • (Boolean)


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

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

#prefix(name) ⇒ Object



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

def prefix(name)
  super(name) + (grouped? ? "[]" : "")
end

#valueObject



21
22
23
# File 'lib/cml/tags/checkbox.rb', line 21

def value
  (@attrs["value"] || (grouped? ? @attrs["label"] : "true")).to_s
end

#wrapper(parsed) ⇒ Object



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

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