Class: Emjay::Components::MjSocialElement

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

Constant Summary collapse

IMG_BASE_URL =
"https://www.mailjet.com/images/theme/v1/icons/ico-social/"
DEFAULT_SOCIAL_NETWORKS =
{
  "facebook" => {"share-url" => "https://www.facebook.com/sharer/sharer.php?u=[[URL]]", "background-color" => "#3b5998", "src" => "#{IMG_BASE_URL}facebook.png"},
  "twitter" => {"share-url" => "https://twitter.com/intent/tweet?url=[[URL]]", "background-color" => "#55acee", "src" => "#{IMG_BASE_URL}twitter.png"},
  "x" => {"share-url" => "https://twitter.com/intent/tweet?url=[[URL]]", "background-color" => "#000000", "src" => "#{IMG_BASE_URL}twitter-x.png"},
  "google" => {"share-url" => "https://plus.google.com/share?url=[[URL]]", "background-color" => "#dc4e41", "src" => "#{IMG_BASE_URL}google-plus.png"},
  "pinterest" => {"share-url" => "https://pinterest.com/pin/create/button/?url=[[URL]]&media=&description=", "background-color" => "#bd081c", "src" => "#{IMG_BASE_URL}pinterest.png"},
  "linkedin" => {"share-url" => "https://www.linkedin.com/shareArticle?mini=true&url=[[URL]]&title=&summary=&source=", "background-color" => "#0077b5", "src" => "#{IMG_BASE_URL}linkedin.png"},
  "instagram" => {"background-color" => "#3f729b", "src" => "#{IMG_BASE_URL}instagram.png"},
  "web" => {"src" => "#{IMG_BASE_URL}web.png", "background-color" => "#4BADE9"},
  "snapchat" => {"src" => "#{IMG_BASE_URL}snapchat.png", "background-color" => "#FFFA54"},
  "youtube" => {"src" => "#{IMG_BASE_URL}youtube.png", "background-color" => "#EB3323"},
  "tumblr" => {"src" => "#{IMG_BASE_URL}tumblr.png", "share-url" => "https://www.tumblr.com/widgets/share/tool?canonicalUrl=[[URL]]", "background-color" => "#344356"},
  "github" => {"src" => "#{IMG_BASE_URL}github.png", "background-color" => "#000000"},
  "xing" => {"src" => "#{IMG_BASE_URL}xing.png", "share-url" => "https://www.xing.com/app/user?op=share&url=[[URL]]", "background-color" => "#296366"},
  "vimeo" => {"src" => "#{IMG_BASE_URL}vimeo.png", "background-color" => "#53B4E7"},
  "medium" => {"src" => "#{IMG_BASE_URL}medium.png", "background-color" => "#000000"},
  "soundcloud" => {"src" => "#{IMG_BASE_URL}soundcloud.png", "background-color" => "#EF7F31"},
  "dribbble" => {"src" => "#{IMG_BASE_URL}dribbble.png", "background-color" => "#D95988"}
}.freeze
SOCIAL_NETWORKS =

Build noshare variants

DEFAULT_SOCIAL_NETWORKS.each_with_object({}) { |(key, val), hash|
  hash[key] = val
  hash["#{key}-noshare"] = val.merge("share-url" => "[[URL]]")
}.freeze

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



63
64
65
66
67
68
69
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
# File 'lib/emjay/components/body/mj_social_element.rb', line 63

def self.allowed_attributes
  {
    "align" => "enum(left,center,right)",
    "icon-position" => "enum(left,right)",
    "background-color" => "color",
    "color" => "color",
    "border-radius" => "string",
    "font-family" => "string",
    "font-size" => "unit(px)",
    "font-style" => "string",
    "font-weight" => "string",
    "href" => "string",
    "icon-size" => "unit(px,%)",
    "icon-height" => "unit(px,%)",
    "icon-padding" => "unit(px,%){1,4}",
    "line-height" => "unit(px,%,)",
    "name" => "string",
    "padding-bottom" => "unit(px,%)",
    "padding-left" => "unit(px,%)",
    "padding-right" => "unit(px,%)",
    "padding-top" => "unit(px,%)",
    "padding" => "unit(px,%){1,4}",
    "text-padding" => "unit(px,%){1,4}",
    "rel" => "string",
    "src" => "string",
    "srcset" => "string",
    "sizes" => "string",
    "alt" => "string",
    "title" => "string",
    "target" => "string",
    "text-decoration" => "string",
    "vertical-align" => "enum(top,middle,bottom)"
  }
end

.component_nameObject



37
38
39
# File 'lib/emjay/components/body/mj_social_element.rb', line 37

def self.component_name
  "mj-social-element"
end

.default_attributesObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/emjay/components/body/mj_social_element.rb', line 45

def self.default_attributes
  {
    "alt" => "",
    "align" => "left",
    "icon-position" => "left",
    "color" => "#000",
    "border-radius" => "3px",
    "font-family" => "Ubuntu, Helvetica, Arial, sans-serif",
    "font-size" => "13px",
    "line-height" => "1",
    "padding" => "4px",
    "text-padding" => "4px 4px 4px 0",
    "target" => "_blank",
    "text-decoration" => "none",
    "vertical-align" => "middle"
  }
end

.ending_tag?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/emjay/components/body/mj_social_element.rb', line 41

def self.ending_tag?
  true
end

Instance Method Details

#get_stylesObject



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
# File 'lib/emjay/components/body/mj_social_element.rb', line 98

def get_styles
  social = get_social_attributes
  icon_size = social["icon-size"]
  icon_height = social["icon-height"]
  bg_color = social["background-color"]

  {
    td: {
      "padding" => get_attribute("padding"),
      "padding-top" => get_attribute("padding-top"),
      "padding-right" => get_attribute("padding-right"),
      "padding-bottom" => get_attribute("padding-bottom"),
      "padding-left" => get_attribute("padding-left"),
      "vertical-align" => get_attribute("vertical-align")
    },
    table: {
      "background" => bg_color,
      "border-radius" => get_attribute("border-radius"),
      "width" => icon_size
    },
    icon: {
      "padding" => get_attribute("icon-padding"),
      "font-size" => "0",
      "height" => icon_height || icon_size,
      "vertical-align" => "middle",
      "width" => icon_size
    },
    img: {
      "border-radius" => get_attribute("border-radius"),
      "display" => "block"
    },
    tdText: {
      "vertical-align" => "middle",
      "padding" => get_attribute("text-padding"),
      "text-align" => get_attribute("align")
    },
    text: {
      "color" => get_attribute("color"),
      "font-size" => get_attribute("font-size"),
      "font-weight" => get_attribute("font-weight"),
      "font-style" => get_attribute("font-style"),
      "font-family" => get_attribute("font-family"),
      "line-height" => get_attribute("line-height"),
      "text-decoration" => get_attribute("text-decoration")
    }
  }
end

#renderObject



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/emjay/components/body/mj_social_element.rb', line 146

def render
  social = get_social_attributes
  src = social["src"]
  srcset = social["srcset"]
  sizes = social["sizes"]
  href = social["href"]
  icon_size = social["icon-size"]

  has_link = !!get_attribute("href")
  icon_position = get_attribute("icon-position")

  icon_html = render_icon(src, srcset, sizes, href, icon_size, has_link)
  content_html = render_text_content(href, has_link)

  tr_attrs = html_attributes(class: get_attribute("css-class"))

  parts = if icon_position == "left"
    "#{icon_html} #{content_html}"
  else
    "#{content_html} #{icon_html}"
  end

  <<~HTML
    <tr
      #{tr_attrs}
    >
      #{parts}
    </tr>
  HTML
end