0.0
No commit activity in last 3 years
No release in over 3 years
Add custom mimetypes by parsing a TOML file in to an XML file which can be installed.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.1.2
 Project Readme

MimetypeXML

Custom mimetype from TOML to XML

Install

  • You need Ruby and Gems (gems comes with ruby) Install this gem with
gem install mimetype-xml 

# You might want to run this with sudo,
# or add the Gem userdir to the beginning of your $PATH variable
# like so in your bashrc: `PATH=$(ruby -e 'print Gem.user_dir')/bin:$PATH`
# This depends on your platform.

Usage

Create the TOML config (./custom-mime.toml):

## CUSTOM MIMETYPES TOML CONFIG FILE ##
# Optional variables ard marked with `(opt.)` in a
# comment at the end of the line

# Add mimetype for elixir files
[x-application-elixir]

type    = "application/x-elixir"
pattern = ["*.ex", "*.exs"] # Always in an array
                            # (even if only one pattern, e.g. ["*.ext"])

comment      = "Elixir File" # Default language
comment_lang = [ ["no", "Elixir Fil"], ["la", "Ordo Elixir"] ] # etc. (opt.)

icon = "mimetypes/application-x-elixir.svg"
size = 48 # I don't really know

xml_file = "elixir-file-mimetype.xml" # (opt.), not useful...


# Another for crystal files

[x-application-crystal]
type = "application/x-crystal"
pattern =  ["*.cr"]
comment = "Crystal File"
icon = "mimetypes/application-x-crystal.svg"
size = 48

# That simple to add new mimetypes, just make the icon in the
# path specified in the `icon` variable. 
# e.g. 'mimetypes/appliaction-x-myfile.svg'

Then generate the xml files and install it through a ruby script (./generate-mimetypes.rb):

require 'mimetype_xml'
require 'toml' # `toml` comes with this gem (`mimetype_xml`)

xml = MimetypeXML::Generate.toml_file(
  :file      => './custom-mime.toml', # The location of the TOML config
  :xml_dir   => '/usr/share/mime/packages/', # Make sure the dir is writable for the user, run `sudo chmod 777 /usr/share/mime/packages/`
  :icon_pack => '~/.icons/YOUR_ICON_PACK' # Replace this with the install dir of your iconpack
)

files = xml.write_files
files.install

Then run the script from your shell:

ruby ./generate-mimetypes.rb

The binary file doesn't do anything at the moment.