Class: Emjay::Components::MjText

Inherits:
BodyComponent show all
Defined in:
lib/emjay/components/body/mj_text.rb

Instance Attribute Summary

Attributes inherited from Emjay::Component

#attributes, #context, #props

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BodyComponent

#get_box_widths, #get_child_context, #get_shorthand_attr_value, #get_shorthand_border_value, #html_attributes, #render_children, #styles

Methods inherited from Emjay::Component

#get_attribute, #get_child_context, #get_content, #initialize, raw_element?

Constructor Details

This class inherits a constructor from Emjay::Component

Class Method Details

.allowed_attributesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/emjay/components/body/mj_text.rb', line 29

def self.allowed_attributes
  {
    "align" => "enum(left,right,center,justify)",
    "background-color" => "color",
    "color" => "color",
    "container-background-color" => "color",
    "font-family" => "string",
    "font-size" => "unit(px)",
    "font-style" => "string",
    "font-weight" => "string",
    "height" => "unit(px,%)",
    "letter-spacing" => "unitWithNegative(px,em)",
    "line-height" => "unit(px,%,)",
    "padding-bottom" => "unit(px,%)",
    "padding-left" => "unit(px,%)",
    "padding-right" => "unit(px,%)",
    "padding-top" => "unit(px,%)",
    "padding" => "unit(px,%){1,4}",
    "text-decoration" => "string",
    "text-transform" => "string",
    "vertical-align" => "enum(top,bottom,middle)"
  }
end

.component_nameObject



10
11
12
# File 'lib/emjay/components/body/mj_text.rb', line 10

def self.component_name
  "mj-text"
end

.default_attributesObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/emjay/components/body/mj_text.rb', line 18

def self.default_attributes
  {
    "align" => "left",
    "color" => "#000000",
    "font-family" => "Ubuntu, Helvetica, Arial, sans-serif",
    "font-size" => "13px",
    "line-height" => "1",
    "padding" => "10px 25px"
  }
end

.ending_tag?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/emjay/components/body/mj_text.rb', line 14

def self.ending_tag?
  true
end

Instance Method Details

#get_stylesObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/emjay/components/body/mj_text.rb', line 53

def get_styles
  {
    text: {
      "font-family" => get_attribute("font-family"),
      "font-size" => get_attribute("font-size"),
      "font-style" => get_attribute("font-style"),
      "font-weight" => get_attribute("font-weight"),
      "letter-spacing" => get_attribute("letter-spacing"),
      "line-height" => get_attribute("line-height"),
      "text-align" => get_attribute("align"),
      "text-decoration" => get_attribute("text-decoration"),
      "text-transform" => get_attribute("text-transform"),
      "color" => get_attribute("color"),
      "height" => get_attribute("height")
    }
  }
end

#renderObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/emjay/components/body/mj_text.rb', line 71

def render
  height = get_attribute("height")

  if height
    <<~HTML
      #{ConditionalTag.conditional_tag(
        "<table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"#{height}\" style=\"vertical-align:top;height:#{height};\">"
      )}
      #{render_content}
      #{ConditionalTag.conditional_tag(
        "</td></tr></table>"
      )}
    HTML
  else
    render_content
  end
end