Class: Emjay::Components::MjDivider

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

ending_tag?, #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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/emjay/components/body/mj_divider.rb', line 25

def self.allowed_attributes
  {
    "border-color" => "color",
    "border-style" => "string",
    "border-width" => "unit(px)",
    "container-background-color" => "color",
    "padding" => "unit(px,%){1,4}",
    "padding-bottom" => "unit(px,%)",
    "padding-left" => "unit(px,%)",
    "padding-right" => "unit(px,%)",
    "padding-top" => "unit(px,%)",
    "width" => "unit(px,%)",
    "align" => "enum(left,center,right)"
  }
end

.component_nameObject



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

def self.component_name
  "mj-divider"
end

.default_attributesObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/emjay/components/body/mj_divider.rb', line 14

def self.default_attributes
  {
    "border-color" => "#000000",
    "border-style" => "solid",
    "border-width" => "4px",
    "padding" => "10px 25px",
    "width" => "100%",
    "align" => "center"
  }
end

Instance Method Details

#get_stylesObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/emjay/components/body/mj_divider.rb', line 41

def get_styles
  compute_align = case get_attribute("align")
  when "left"
    "0px"
  when "right"
    "0px 0px 0px auto"
  else
    "0px auto"
  end

  border_top = ["style", "width", "color"].map { |attr|
    get_attribute("border-#{attr}")
  }.join(" ")

  p_styles = {
    "border-top" => border_top,
    "font-size" => "1px",
    "margin" => compute_align,
    "width" => get_attribute("width")
  }

  {
    p: p_styles,
    outlook: p_styles.merge("width" => get_outlook_width)
  }
end

#renderObject



68
69
70
71
72
73
74
75
76
77
# File 'lib/emjay/components/body/mj_divider.rb', line 68

def render
  p_attrs = html_attributes(style: :p)
  <<~HTML
    <p
      #{p_attrs}
    >
    </p>
    #{render_after}
  HTML
end