Parse mask icon from HTML

This commit is contained in:
Basti 2018-07-02 12:48:46 -05:00
parent 7be7e45493
commit 9042ca0b87
2 changed files with 14 additions and 2 deletions

View File

@ -92,8 +92,7 @@ module Manifique
end
def parse_icons_from_html
icon_links = @html.css("link[rel=icon]")
if icon_links.any?
if icon_links = @html.css("link[rel=icon]")
icon_links.each do |link|
icon = {}
icon["src"] = link.attributes["href"].value rescue nil
@ -104,6 +103,15 @@ module Manifique
end
end
if mask_icon_link = @html.at_css("link[rel=mask-icon]")
icon = { "purpose" => "mask-icon" }
icon["src"] = mask_icon_link.attributes["href"].value rescue nil
return if icon["src"].to_s.empty?
icon["type"] = link.attributes["type"].value rescue get_icon_type(icon["src"])
icon["color"] = mask_icon_link.attributes["color"].value rescue nil
@metadata.icons.push icon
end
@metadata.from_html.push "icons" unless @metadata.icons.empty?
end

View File

@ -170,6 +170,10 @@ RSpec.describe Manifique::WebClient do
png_icons = subject.icons.select{|i| i["type"] == "image/png"}
expect(png_icons.length).to eq(5)
expect(subject.icons.find{|i| i["sizes"] == "512x512"}["src"]).to eq( "/application_icon_x512.png")
mask_icon = subject.icons.find{|i| i["purpose"] == "mask-icon"}
expect(mask_icon["color"]).to eq("#2b90d9")
expect(mask_icon["type"]).to eq("image/svg")
expect(mask_icon["sizes"]).to be_nil
end
it "knows which properties were loaded from HTML" do