diff --git a/lib/email/styles.rb b/lib/email/styles.rb index 562b4982a74..9e014eef888 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -9,6 +9,7 @@ module Email MAX_IMAGE_DIMENSION = 400 ONEBOX_IMAGE_BASE_STYLE = "max-height: 80%; max-width: 20%; height: auto; float: left; margin-right: 10px;" ONEBOX_IMAGE_THUMBNAIL_STYLE = "width: 60px;" + ONEBOX_INLINE_AVATAR_STYLE = "width: 20px; height: 20px; float: none; vertical-align: middle;" @@plugin_callbacks = [] @@ -133,7 +134,7 @@ module Email style('.onebox-metadata', "color: #919191") style('.github-info', "margin-top: 10px;") style('.github-info div', "display: inline; margin-right: 10px;") - style('.onebox-avatar-inline', "width: 20px; height: 20px; float: none; vertical-align: middle;") + style('.onebox-avatar-inline', ONEBOX_INLINE_AVATAR_STYLE) @fragment.css('aside.quote blockquote > p').each do |p| p['style'] = 'padding: 0;' @@ -261,8 +262,10 @@ module Email if attachments[original_filename] url = attachments[original_filename].url - style = if div['data-oneboxed'] - "#{ONEBOX_IMAGE_THUMBNAIL_STYLE} #{ONEBOX_IMAGE_BASE_STYLE}" + onebox_type = div['data-onebox-type'] + style = if onebox_type + onebox_style = onebox_type == "avatar-inline" ? ONEBOX_INLINE_AVATAR_STYLE : ONEBOX_IMAGE_THUMBNAIL_STYLE + "#{onebox_style} #{ONEBOX_IMAGE_BASE_STYLE}" else calculate_width_and_height_style(div) end diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 8dea3107554..d9bc62ad192 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -451,28 +451,36 @@ module PrettyText width = img['width'] height = img['height'] - oneboxed = img.ancestors.css(".onebox-body").any? || img.classes.include?("onebox-avatar") + onebox_type = nil + + if img.ancestors.css(".onebox-body").any? + if img.classes.include?("onebox-avatar-inline") + onebox_type = "avatar-inline" + else + onebox_type = "thumbnail" + end + end # we always want this to be tiny and without any special styles if img.classes.include?('site-icon') - oneboxed = false + onebox_type = nil width = 16 height = 16 end if Upload.secure_media_url?(url) - img.add_next_sibling secure_media_placeholder(doc, url, oneboxed: oneboxed, width: width, height: height) + img.add_next_sibling secure_media_placeholder(doc, url, onebox_type: onebox_type, width: width, height: height) img.remove end end end - def self.secure_media_placeholder(doc, url, oneboxed: false, width: nil, height: nil) + def self.secure_media_placeholder(doc, url, onebox_type: false, width: nil, height: nil) data_width = width ? "data-width=#{width}" : '' data_height = height ? "data-height=#{height}" : '' - data_oneboxed = oneboxed ? "data-oneboxed=true" : '' + data_onebox_type = onebox_type ? "data-onebox-type='#{onebox_type}'" : '' <<~HTML -
@martin check this out:
+ + HTML + end + it "keeps the special onebox styles" do + strip_and_inline + expect(@frag.to_s).to include("cid:email/test.png") + expect(@frag.css('[data-sripped-secure-media]')).not_to be_present + expect(@frag.css('[data-embedded-secure-image]')[0].attr('style')).to eq('width: 20px; height: 20px; float: none; vertical-align: middle; max-height: 80%; max-width: 20%; height: auto; float: left; margin-right: 10px;') + end + end end end end