Class: CML::Tags::Text

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

Direct Known Subclasses

MultipleText

Constant Summary collapse

BareTemplate =
<<-HTML.freeze
<div class="cml_row"><input name="{{name}}" type="text" value="{{value}}" class="{{classes}}"/></div>
HTML
Template =
<<-HTML.freeze
{{label}}
#{BareTemplate}
HTML

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, #data, #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?, #children, #convert, #ensure_resolved, #finite_value?, #gold=, #gold?, #gold_class, #gold_reason, #initialize, #instructions, #iterating?, #label, #legend, memoize, #multi_type, #name, #parent_multiples, #prefix, #preloaded_data, #raw_label, #to_liquid, #to_s, #validate?, #validations, #validators, #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

#classesObject



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

def classes
  super + (@attrs["default"] ? " default" : "")
end

#to_htmlObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cml/tags/text.rb', line 21

def to_html
  if @opts[:normalize]
    #Making some text boxes
    seeds = Array(@opts[:data][@opts[:parser].golds[name(false)]] || @opts[:data][name(false)])
    seeds = @opts[:iteration] ? [seeds[@opts[:iteration]]].flatten : seeds
    seeds << nil if seeds.length == 0
    inputs = seeds.map do |input|
      Liquid::Template.parse(BareTemplate).render(data.merge({
        "value" => CGI.escapeHTML(input.to_s), 
        "classes" => classes+(input ? " cml_gold_loaded" : "")
      }))
    end.join("\n")
    wrapper("#{label}\n#{inputs}")
  elsif preload = preloaded_data
    wrapper(Liquid::Template.parse(Template).render(data.merge({
      "value" => CGI.escapeHTML(preload.to_s),
      "classes" => classes
    })))
  else
    wrapper(Liquid::Template.parse(Template).render(data, [LiquidFilters]))
  end
end

#valueObject



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

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