Skip to content

Instantly share code, notes, and snippets.

@dgallegos
Created July 5, 2018 18:44
Show Gist options
  • Save dgallegos/5a5cb5b0729a322d3e48f160f110cf8c to your computer and use it in GitHub Desktop.
Save dgallegos/5a5cb5b0729a322d3e48f160f110cf8c to your computer and use it in GitHub Desktop.
Microsoft Fabric File Icons: Mapping MIME Types to correct icon classes
# 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