Module: Rabbit::Format::SpanTextFormatter

Includes:
Formatter
Defined in:
lib/rabbit/formatter.rb

Constant Summary collapse

PANGO2CSS =
{
  "font_family" => Proc.new do |name, value|
    ["font-family", "'#{value}'"]
  end,
  "foreground" => "color",
  "size" => Proc.new do |name, value|
    ["font-size", "#{(value / Pango::SCALE) * 2}px"]
  end,
  "style" => "font-style",
  "weight" => "font-weight",
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Formatter

#tagged_text

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



43
44
45
# File 'lib/rabbit/formatter.rb', line 43

def value
  @value
end

Instance Method Details

#format(text) ⇒ Object



57
58
59
# File 'lib/rabbit/formatter.rb', line 57

def format(text)
  tagged_text(text, "span", normalize_attribute(name, @value))
end

#html_format(text) ⇒ Object



61
62
63
64
# File 'lib/rabbit/formatter.rb', line 61

def html_format(text)
  css_name, css_value = pango2css(name, @value)
  tagged_text(text, "span", {'style' => "#{css_name}: #{css_value};"})
end

#html_formatter?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/rabbit/formatter.rb', line 53

def html_formatter?
  true
end

#initialize(value) ⇒ Object



45
46
47
# File 'lib/rabbit/formatter.rb', line 45

def initialize(value)
  @value = value
end

#text_formatter?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/rabbit/formatter.rb', line 49

def text_formatter?
  true
end