Class: Tml::Tokens::XMessage::Decoration

Inherits:
Decoration
  • Object
show all
Defined in:
lib/tml/tokens/x_message/decoration.rb

Overview

Param Token

0 tagged himself/herself in 1,choice,singular1,choice,singular#{1,number 2,map,photo2,map,photo#photo|video2,map,photo#photo|video#video|plural#1,number 2,map,photo2,map,photo#photos|video2,map,photo#photos|video#videos}.

Constant Summary collapse

DEFAULT_DECORATION_PLACEHOLDER =
'{!yield!}'

Constants inherited from Decoration

Decoration::RESERVED_TOKEN, Decoration::TOKEN_PLACEHOLDER

Instance Attribute Summary

Attributes inherited from Decoration

#default_name, #full_name, #label, #short_name

Instance Method Summary collapse

Methods inherited from Decoration

#allowed?, #apply, #default_decoration, #to_s

Constructor Details

#initialize(label, opts) ⇒ Decoration

=> “2”,

:type => "anchor",
:styles => ...



49
50
51
52
53
54
55
# File 'lib/tml/tokens/x_message/decoration.rb', line 49

def initialize(label, opts)
  @label = label
  @type = opts[:type]
  @short_name = opts[:index].to_s.gsub(':', '')
  @full_name = "#{opts[:index]}}"
  @default_name = @type
end

Instance Method Details

#close_tagObject



97
98
99
# File 'lib/tml/tokens/x_message/decoration.rb', line 97

def close_tag
  @template.split(DEFAULT_DECORATION_PLACEHOLDER).last
end

#open_tag(method) ⇒ Object



91
92
93
94
95
# File 'lib/tml/tokens/x_message/decoration.rb', line 91

def open_tag(method)
  @template = template(method)
  # pp label: label, type: @type, template: @template, method: method
  @template.split(DEFAULT_DECORATION_PLACEHOLDER).first
end

#template(method) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/tml/tokens/x_message/decoration.rb', line 69

def template(method)
  if method
    if method.is_a?(String)

      # backwards compatibility to legacy code
      if @type == 'anchor'
        return "<a href='#{method}'>#{DEFAULT_DECORATION_PLACEHOLDER}</a>"
      end

      return method
    end

    if method.is_a?(Array) or method.is_a?(Hash)
      return default_decoration(DEFAULT_DECORATION_PLACEHOLDER, method)
    end

    return DEFAULT_DECORATION_PLACEHOLDER
  end

  default_decoration(DEFAULT_DECORATION_PLACEHOLDER)
end

#token_object(token_values) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/tml/tokens/x_message/decoration.rb', line 61

def token_object(token_values)
  if token_values.is_a?(Array)
    token_values[@short_name.to_i]
  else
    Tml::Utils.hash_value(token_values, @short_name)
  end
end

#token_value(token_object, language) ⇒ Object



57
58
59
# File 'lib/tml/tokens/x_message/decoration.rb', line 57

def token_value(token_object, language)
  token_object
end