Created
July 5, 2018 18:44
-
-
Save dgallegos/5a5cb5b0729a322d3e48f160f110cf8c to your computer and use it in GitHub Desktop.
Microsoft Fabric File Icons: Mapping MIME Types to correct icon classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# References: | |
# | |
# Ruby Mime Type code - https://gist.github.com/colemanw/9c9a12aae16a4bfe2678de86b661d922 | |
# Microsoft Fabric Icons - https://developer.microsoft.com/en-us/fabric#/styles/icons | |
# | |
def icon_for_mimetype mime | |
mimes = { | |
'image': 'Photo2', | |
'audio': 'Speakers', | |
'video': 'Video', | |
# Documents | |
'application/pdf': 'PDF', | |
'application/msword': 'WordDocument', | |
'application/vnd.ms-word': 'WordDocument', | |
'application/vnd.oasis.opendocument.text': 'WordDocument', | |
'application/vnd.openxmlformats-officedocument.wordprocessingml': 'WordDocument', | |
'application/vnd.ms-excel': 'ExcelDocument', | |
'application/vnd.openxmlformats-officedocument.spreadsheetml': 'ExcelDocument', | |
'application/vnd.oasis.opendocument.spreadsheet': 'ExcelDocument', | |
'application/vnd.ms-powerpoint': 'PowerPointDocument', | |
'application/vnd.openxmlformats-officedocument.presentationml': 'PowerPointDocument', | |
'application/vnd.oasis.opendocument.presentation': 'PowerPointDocument', | |
'text/plain': 'TextDocument', | |
'text/html': 'TextDocument', | |
'application/json': 'JS', | |
# Archives | |
'application/gzip': 'ZipFolder', | |
'application/zip': 'ZipFolder', | |
}.with_indifferent_access | |
if mime | |
m = mimes[mime.split('/').first] | |
m ||= mimes[mime] | |
end | |
m ||= 'Page' | |
"ms-Icon--#{m}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment