Fledex.Color.Names.ModuleGenerator (fledex v0.8.0)

Copy Markdown View Source

This module allows to easily create color name modules (implementing the Fledex.Color.Names.Interface behaviour) by simply using this module. Use it in the following way:

defmodule MyColorModule do
  # we point to our csv file that defines the colors
  @external_resource Path.dirname(__DIR__) <> "/my_colors.csv"

  use Fledex.Color.Names.ModuleGenerator,
    filename: @external_resource,
    converter: &MyColorModule.Utils.converter/1,
    splitter_opts: [separator: ",", split_opts: [parts: 11]],
end

The filename and the converter function are mandatory. The converter function needs to return a t:Fledex.Color.Names.Types.color_struct_t struct. You can find some useful utility functions that help you in the conversion in Fledex.Color.Names.LoadUtils.

In addition a set of options can be specified. Most of them are passed on to Fledex.Color.Names.LoadUtils.load_color_file/3.

Apart from those options, you can also specify the option :fields that specifies for which fields a function should be created (default: [:hex]). Thus, by default we wuld create for the color :almond a function almond(:hex) that directly returns the hex-color instead of going through some indirections.

It should be noted that, if no :module option is specified, the __CALLER__ module name will be configured.

Summary

Functions

Create a color names module by use Fledex.Color.Names.ModuleGenerator.

Functions

__using__(opts)

(macro)

Create a color names module by use Fledex.Color.Names.ModuleGenerator.

See the module description to see how to use it