Class: Emjay::Components::MjTable

Inherits:
BodyComponent show all
Defined in:
lib/emjay/components/body/mj_table.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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/emjay/components/body/mj_table.rb', line 34

def self.allowed_attributes
  {
    "align" => "enum(left,right,center)",
    "border" => "string",
    "cellpadding" => "integer",
    "cellspacing" => "integer",
    "container-background-color" => "color",
    "color" => "color",
    "font-family" => "string",
    "font-size" => "unit(px)",
    "font-weight" => "string",
    "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}",
    "role" => "enum(none,presentation)",
    "table-layout" => "enum(auto,fixed,initial,inherit)",
    "vertical-align" => "enum(top,bottom,middle)",
    "width" => "unit(px,%,auto)"
  }
end

.component_nameObject



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

def self.component_name
  "mj-table"
end

.default_attributesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/emjay/components/body/mj_table.rb', line 18

def self.default_attributes
  {
    "align" => "left",
    "border" => "none",
    "cellpadding" => "0",
    "cellspacing" => "0",
    "color" => "#000000",
    "font-family" => "Ubuntu, Helvetica, Arial, sans-serif",
    "font-size" => "13px",
    "line-height" => "22px",
    "padding" => "10px 25px",
    "table-layout" => "auto",
    "width" => "100%"
  }
end

.ending_tag?Boolean

Returns:

  • (Boolean)


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

def self.ending_tag?
  true
end

Instance Method Details

#get_stylesObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/emjay/components/body/mj_table.rb', line 58

def get_styles
  table_styles = {
    "color" => get_attribute("color"),
    "font-family" => get_attribute("font-family"),
    "font-size" => get_attribute("font-size"),
    "line-height" => get_attribute("line-height"),
    "table-layout" => get_attribute("table-layout"),
    "width" => get_attribute("width"),
    "border" => get_attribute("border")
  }

  table_styles["border-collapse"] = "separate" if has_cellspacing?

  {table: table_styles}
end

#renderObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/emjay/components/body/mj_table.rb', line 74

def render
  table_attrs = html_attributes(
    cellpadding: get_attribute("cellpadding"),
    cellspacing: get_attribute("cellspacing"),
    role: get_attribute("role"),
    width: get_width,
    border: "0",
    style: :table
  )
  <<~HTML
    <table
      #{table_attrs}
    >
      #{get_content}
    </table>
  HTML
end