Class: CML::Tags::Checkbox
Constant Summary
collapse
- BareTemplate =
<<-HTML.freeze
{{default}}
<input name="{{name}}" type="checkbox" value="{{value}}" class="{{classes}}" {{checked}}/>
HTML
- Template =
<<-HTML.freeze
{{default_normalized}}<div class="cml_row" {{title}}><label class="{{gold_class}}">#{BareTemplate} {{label}}</label></div>
HTML
CML::TagLogic::And, CML::TagLogic::AndPhraseExp, CML::TagLogic::CombinatorDefault, CML::TagLogic::CombinatorDict, CML::TagLogic::CombinatorExp, CML::TagLogic::GroupExp, CML::TagLogic::Or, CML::TagLogic::OrCombinatorExp, CML::TagLogic::PrecedenceRegexp, CML::TagLogic::TokenExp, CML::TagLogic::TokenRegexp
Instance Attribute Summary
Attributes inherited from CML::Tag
#attrs, #cml, #opts, #tag
#errors, #has_grouped_logic, #has_liquid_logic, #logic_tree
Instance Method Summary
collapse
Methods inherited from CML::Tag
#cacheable?, #children, #convert, #ensure_resolved, #gold=, #gold?, #gold_class, #gold_reason, #initialize, #instructions, #iterating?, #label, #legend, memoize, #multi_type, #name, #parent_multiples, #preloaded_data, #raw_label, #to_html, #to_liquid, #to_s, #validate?, #validations, #validators, #wrapper_classes
#dependencies_on_fields, #dependencies_through_cml_group, #depends_on_fields, #describe_logic_token, #detect_grouped_logic, #detect_liquid_logic, #each_logic_token_in, #expand_logic, #expand_parsed_expression, #keep_merge!, #only_if, parse_expression, resolve_combinator
Constructor Details
This class inherits a constructor from CML::Tag
Instance Method Details
#checked ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/cml/tags/checkbox.rb', line 44
def checked
manipulated = !@opts[:missed].nil?
if @opts[:data] && @opts[:normalize]
manipulated = true
seeds = Array(@opts[:data][@opts[:parser].golds[name(false)]] || @opts[:data][name(false)]).map {|s| s.is_a?(Array) ? s.map {|t| t.to_s.downcase } : s.to_s.downcase }
seeds = @opts[:iteration] ? [seeds[@opts[:iteration]]].flatten : seeds
if seeds.compact.empty?
manipulated = false
elsif seeds.include?(value.to_s.downcase)
@checked = true
return "checked=\"checked\""
end
elsif preload = preloaded_data
manipulated = true
if Array(preload).map{|x| x.to_s.downcase }.include?(value.to_s.downcase)
return "checked=\"checked\""
end
end
!manipulated && @attrs["checked"] ? "checked=\"checked\"" : ""
end
|
#classes ⇒ Object
40
41
42
|
# File 'lib/cml/tags/checkbox.rb', line 40
def classes
super+(@checked ? " cml_gold_loaded" : "")
end
|
#data ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/cml/tags/checkbox.rb', line 65
def data
default = ""
default_normalized = ""
if @attrs["default"]
if @opts[:normalize]
default_normalized = Checkbox.new("<cml:checkbox label=\"Default value: #{@attrs["default"]}\" name=\"#{name(false)}\" value=\"#{@attrs["default"]}\"/>", @opts.merge(:no_reason => true, :normalize => true)).to_html
else
default = Hidden.new("<cml:hidden name=\"#{name(false)}\" value=\"#{@attrs["default"]}\"/>", @opts.merge(:grouped => grouped?, :no_field_wrap => true)).to_html
end
end
c = checked
super.merge({
"default" => default,
"default_normalized" => default_normalized,
"checked" => c,
"label" => @attrs["label"].to_s,
"title" => title_attribute
})
end
|
#finite_value? ⇒ Boolean
27
28
29
|
# File 'lib/cml/tags/checkbox.rb', line 27
def finite_value?
true
end
|
#grouped? ⇒ Boolean
19
20
21
|
# File 'lib/cml/tags/checkbox.rb', line 19
def grouped?
@opts[:bare] || (@cml.parent && @cml.parent.name == "checkboxes")
end
|
#in_logic_graph? ⇒ Boolean
23
24
25
|
# File 'lib/cml/tags/checkbox.rb', line 23
def in_logic_graph?
!grouped?
end
|
#prefix(name) ⇒ Object
13
14
15
16
17
|
# File 'lib/cml/tags/checkbox.rb', line 13
def prefix(name)
name = super(name)
name + (name !~ /\[\]$/ && grouped? ? "[]" : "")
end
|
#value ⇒ Object
35
36
37
38
|
# File 'lib/cml/tags/checkbox.rb', line 35
def value
value = (@attrs["value"] || (grouped? ? @attrs["label"] : "true")).to_s
ensure_resolved(value)
end
|
#wrapper(parsed) ⇒ Object
31
32
33
|
# File 'lib/cml/tags/checkbox.rb', line 31
def wrapper(parsed)
grouped? || @opts[:no_reason] ? parsed : super
end
|