class Tml::Tokens::XMessage::Decoration

Param Token

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

Constants

DEFAULT_DECORATION_PLACEHOLDER

Public Class Methods

new(label, opts) click to toggle source

{:index => “2”,

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

}

# 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

Public Instance Methods

close_tag() click to toggle source
# File lib/tml/tokens/x_message/decoration.rb, line 97
def close_tag
  @template.split(DEFAULT_DECORATION_PLACEHOLDER).last
end
open_tag(method) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/tml/tokens/x_message/decoration.rb, line 57
def token_value(token_object, language)
  token_object
end