Skip to content

Commit

Permalink
Maintenance: Improve handling of SVG logos.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgruner committed May 22, 2024
1 parent d8d655a commit a92e8fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/service/system_assets/product_logo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ def self.store_logo(file)
Time.current.to_i
end

def self.store(logo, logo_resize = nil)
def self.store(logo, logo_resize = nil) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
return if !logo && !logo_resize

if logo&.match?(%r{<svg}i)
return store_logo({ content: logo, mime_type: 'image/svg+xml' })
end

begin
original_image = Rszr::Image.load_data logo if logo

Expand Down
11 changes: 11 additions & 0 deletions spec/lib/service/system_assets/product_logo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@
.to have_attributes(width: 100, height: 100)
end

context 'with SVG logo' do
let(:data) { Rails.public_path.join('assets/images/icons/rss.svg').binread }

it 'stores SVG logo' do
described_class.store(data)

expect(Store.list(object: 'System::Logo', o_id: described_class::PRODUCT_LOGO_RAW)).to be_present
expect(Store.list(object: 'System::Logo', o_id: described_class::PRODUCT_LOGO_RESIZED)).to be_blank
end
end

context 'when logos exist beforehand' do
before do
raw_logo
Expand Down

0 comments on commit a92e8fb

Please sign in to comment.