Class: Emjay::Components::MjSocialElement
- Inherits:
-
BodyComponent
- Object
- Emjay::Component
- BodyComponent
- Emjay::Components::MjSocialElement
- 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
Class Method Summary collapse
- .allowed_attributes ⇒ Object
- .component_name ⇒ Object
- .default_attributes ⇒ Object
- .ending_tag? ⇒ Boolean
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_attributes ⇒ Object
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 97 |
# 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" => "string", "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_name ⇒ Object
36 37 38 |
# File 'lib/emjay/components/body/mj_social_element.rb', line 36 def self.component_name "mj-social-element" end |
.default_attributes ⇒ Object
44 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 44 def self.default_attributes { "alt" => "", "align" => "left", "icon-position" => "left", "color" => "#000", "border" => "0", "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
40 41 42 |
# File 'lib/emjay/components/body/mj_social_element.rb', line 40 def self.ending_tag? true end |
Instance Method Details
#get_styles ⇒ Object
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 146 |
# File 'lib/emjay/components/body/mj_social_element.rb', line 99 def get_styles = icon_size = ["icon-size"] icon_height = ["icon-height"] bg_color = ["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" => get_attribute("border"), "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 |
#render ⇒ Object
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 176 177 |
# File 'lib/emjay/components/body/mj_social_element.rb', line 148 def render = src = ["src"] srcset = ["srcset"] sizes = ["sizes"] href = ["href"] icon_size = ["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 |