Class: CML::Tags::Ratings

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

Constant Summary collapse

Template =
"{{legend}}\n<div class=\"cml_row\">\n<table>\n  <thead>\n    <tr>\n<th></th>\n{% for rating in ratings limit:10 %}\n<th class=\"{{gold_classes[forloop.index0]}}\">{{rating.raw_label}}</th>\n{% endfor %}\n<th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n<td>{{from}}</td>\n{% for rating in ratings limit:10 %}\n<td class=\"{{gold_classes[forloop.index0]}}\">{{rating}}</td>\n{% endfor %}\n<td>{{to}}</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n".freeze

Constants included from CML::TagLogic

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

Attributes included from CML::TagLogic

#errors, #has_grouped_logic, #has_liquid_logic, #logic_tree

Instance Method Summary collapse

Methods inherited from CML::Tag

#cacheable?, #classes, #convert, #ensure_resolved, #gold=, #gold?, #gold_class, #gold_reason, #initialize, #instructions, #iterating?, #label, #legend, memoize, #multi_type, #name, #parent_multiples, #prefix, #preloaded_data, #raw_label, #to_html, #to_liquid, #to_s, #validate?, #validations, #validators, #value, #wrapper, #wrapper_classes

Methods included from CML::TagLogic

#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, #in_logic_graph?, #keep_merge!, #only_if, parse_expression, resolve_combinator

Constructor Details

This class inherits a constructor from CML::Tag

Instance Method Details

#childrenObject



43
44
45
# File 'lib/cml/tags/ratings.rb', line 43

def children
  ratings
end

#dataObject



30
31
32
33
34
35
36
37
# File 'lib/cml/tags/ratings.rb', line 30

def data
  super.merge({
    "ratings" => ratings, 
    "from" => @attrs["from"].to_s, 
    "to" => @attrs["to"].to_s,
    "gold_classes" => gold_classes
  })
end

#finite_value?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/cml/tags/ratings.rb', line 64

def finite_value?
  true
end

#gold_classesObject



39
40
41
# File 'lib/cml/tags/ratings.rb', line 39

def gold_classes
  ratings.map {|rating| rating.gold_class }
end

#ratingsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cml/tags/ratings.rb', line 47

def ratings
  if @cml.xpath(".//cml:rating").empty?
    max = @attrs["points"] ? @attrs["points"].to_s.to_i : 4
    tags = Parser.parse((1..max).map do |r|
      "<cml:rating label='#{r}' />"
    end.join("\n")).xpath("root/cml:rating")
  else
    tags = @cml.xpath(".//cml:rating")
  end
  tags.map do |c|
    c["validates"] ||= @attrs["validates"].to_s
    c["name"] ||= name
    (@opts[:normalize] ? Checkbox : Radio).new(c, @opts.merge(:bare => true))
  end
end