mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 00:20:54 +08:00
DEV: Allow 3-digit HEX color code in single icon route
Followup to aee8e62
This commit is contained in:
@ -64,7 +64,7 @@ class SvgSpriteController < ApplicationController
|
||||
doc = Nokogiri.XML(icon)
|
||||
doc.at_xpath("symbol").name = "svg"
|
||||
doc.at_xpath("svg")['xmlns'] = "http://www.w3.org/2000/svg"
|
||||
doc.at_xpath("svg")['fill'] = "##{params[:color]}" if params[:color]
|
||||
doc.at_xpath("svg")['fill'] = adjust_hex(params[:color]) if params[:color]
|
||||
|
||||
response.headers["Last-Modified"] = 1.years.ago.httpdate
|
||||
response.headers["Content-Length"] = doc.to_s.bytesize.to_s
|
||||
@ -74,4 +74,14 @@ class SvgSpriteController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def adjust_hex(hex)
|
||||
if hex.size == 3
|
||||
chars = hex.scan(/\w/)
|
||||
hex = chars.zip(chars).flatten.join
|
||||
end
|
||||
"##{hex}"
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user