Class: Emjay::Components::MjGroup
Instance Attribute Summary
#attributes, #context, #props
Class Method Summary
collapse
Instance Method Summary
collapse
#get_box_widths, #get_shorthand_attr_value, #get_shorthand_border_value, #html_attributes, #render_children, #styles
ending_tag?, #get_attribute, #get_content, #initialize, raw_element?
Class Method Details
.allowed_attributes ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/emjay/components/body/mj_group.rb', line 13
def self.allowed_attributes
{
"background-color" => "color",
"direction" => "enum(ltr,rtl)",
"vertical-align" => "enum(top,bottom,middle)",
"width" => "unit(px,%)"
}
end
|
.component_name ⇒ Object
9
10
11
|
# File 'lib/emjay/components/body/mj_group.rb', line 9
def self.component_name
"mj-group"
end
|
.default_attributes ⇒ Object
22
23
24
|
# File 'lib/emjay/components/body/mj_group.rb', line 22
def self.default_attributes
{"direction" => "ltr"}
end
|
Instance Method Details
#get_child_context ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/emjay/components/body/mj_group.rb', line 26
def get_child_context
parent_width = @context[:container_width]
non_raw_siblings = @props[:non_raw_siblings] || 1
padding_size = get_shorthand_attr_value("padding", "left") +
get_shorthand_attr_value("padding", "right")
container_width = get_attribute("width") ||
"#{parent_width.to_f / non_raw_siblings}px"
parsed = WidthParser.call(container_width, parse_float_to_int: false)
container_width = if parsed[:unit] == "%"
"#{(parent_width.to_f * parsed[:parsed_width]) / 100 - padding_size}px"
else
"#{parsed[:parsed_width] - padding_size}px"
end
children = @props[:children] || []
@context.merge(
container_width: container_width,
non_raw_siblings: children.length
)
end
|
#get_styles ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/emjay/components/body/mj_group.rb', line 51
def get_styles
{
div: {
"font-size" => "0",
"line-height" => "0",
"text-align" => "left",
"display" => "inline-block",
"width" => "100%",
"direction" => get_attribute("direction"),
"vertical-align" => get_attribute("vertical-align"),
"background-color" => get_attribute("background-color")
},
tdOutlook: {
"vertical-align" => get_attribute("vertical-align"),
"width" => get_width_as_pixel
}
}
end
|
#render ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/emjay/components/body/mj_group.rb', line 70
def render
children = @props[:children] || []
non_raw_siblings = @props[:non_raw_siblings] || 1
group_context = get_child_context
group_width = group_context[:container_width]
container_width = @context[:container_width]
get_element_width = ->(width) {
unless width
return "#{container_width.to_i / non_raw_siblings.to_i}px"
end
parsed = WidthParser.call(width, parse_float_to_int: false)
if parsed[:unit] == "%"
"#{(100 * parsed[:parsed_width]) / group_width.to_f}px"
else
"#{parsed[:parsed_width]}#{parsed[:unit]}"
end
}
classes_name = "#{get_column_class} mj-outlook-group-fix"
css_class = get_attribute("css-class")
classes_name += " #{css_class}" if css_class
<<~HTML
<div#{html_attributes(class: classes_name, style: :div)}>
<!--[if mso | IE]>
<table#{html_attributes(
bgcolor: ((get_attribute("background-color") == "none") ? nil : get_attribute("background-color")),
border: "0",
cellpadding: "0",
cellspacing: "0",
role: "presentation"
)}>
<tr>
<![endif]-->
#{render_children(children, attributes: {"mobileWidth" => "mobileWidth"}, renderer: ->(component) {
if component.class.raw_element?
component.render
else
comp_width = if component.respond_to?(:get_width_as_pixel, true)
begin
component.send(:get_width_as_pixel)
rescue
component.get_attribute("width")
end
else
component.get_attribute("width")
end
<<~CELL
<!--[if mso | IE]>
<td#{component.html_attributes(
style: {
"align" => component.get_attribute("align"),
"vertical-align" => component.get_attribute("vertical-align"),
"width" => get_element_width.call(comp_width)
}
)}>
<![endif]-->
#{component.render}
<!--[if mso | IE]>
</td>
<![endif]-->
CELL
end
})}
<!--[if mso | IE]>
</tr>
</table>
<![endif]-->
</div>
HTML
end
|