Fix docx report for active storage

This commit is contained in:
Anton Ignatov 2019-10-01 10:26:24 +02:00
parent 91cc054096
commit b382eb607b

View file

@ -59,7 +59,12 @@ module Reports::Docx::PrivateMethods
end end
elsif elem[:type] == 'image' elsif elem[:type] == 'image'
style = elem[:style] style = elem[:style]
@docx.img elem[:data], width: style[:width], height: style[:height], align: (style[:align] || :left) @docx.img elem[:data] do
data elem[:blob].download
width style[:width]
height style[:height]
align style[:align] || :left
end
end end
end end
end end
@ -90,18 +95,17 @@ module Reports::Docx::PrivateMethods
if elem.name == 'img' && elem.attributes['data-mce-token'] if elem.name == 'img' && elem.attributes['data-mce-token']
image = TinyMceAsset.find_by_id(Base62.decode(elem.attributes['data-mce-token'].value)) image = TinyMceAsset.find_by(id: Base62.decode(elem.attributes['data-mce-token'].value))
next unless image next unless image
image_path = image_path(image) image_path = image_path(image)
dimension = FastImage.size(image_path) dimension = FastImage.size(image_path)
style = image_styling(elem, dimension) style = image_styling(elem, dimension)
elements.push( elements.push(
type: 'image', type: 'image',
data: image_path, data: image_path.split('&')[0],
blob: image.blob,
style: style style: style
) )
next next
@ -146,7 +150,7 @@ module Reports::Docx::PrivateMethods
result[:style] = elem.name if elem.name.include? 'h' result[:style] = elem.name if elem.name.include? 'h'
result[:bold] = true if elem.name == 'strong' result[:bold] = true if elem.name == 'strong'
result[:italic] = true if elem.name == 'em' result[:italic] = true if elem.name == 'em'
style_keys = ['text-align', 'color'] style_keys = %w(text-align color)
if style if style
style_keys.each do |key| style_keys.each do |key|
@ -209,7 +213,11 @@ module Reports::Docx::PrivateMethods
y = y * 300 / x y = y * 300 / x
x = 300 x = 300
end end
@docx.img image_path, width: x, height: y @docx.img image_path.split('&')[0] do
data asset.blob.download
width x
height y
end
end end
def initial_document_load def initial_document_load
@ -290,7 +298,6 @@ module Reports::Docx::PrivateMethods
else else
asset.image asset.image
end end
image.service_url image.service_url
end end