Fledex.Config (fledex v0.7.0)
View SourceThis module gives access to configure Fledex at runtime.
When you use Fledex this module will be configured accordingly. You can configure
this module also by use Fledex.Config
See __using__/1 for the available options
Caution
Even though you can use this module several times, you might get unwanted
effects and change your configuration (Fledex.Config.Data) unintentionally.
You really should just call use Fledex.Config once. Especially the importing
of the color names can lead to errors. Example:
iex(1)> use Fledex.Config, colors: :wiki
{:module, Fledex.Config.Data,
<<70, 79, 82, 49, 0, 0, 134, 168, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0,
185, 255, 255, 255, 239, 8, 25, 69, 108, 105, 120, 105, 114, 46, 70, 108,
101, 100, 101, 120, 46, 67, 111, 110, 102, 105, 103, 46, ...>>, {:colors, 0}}
iex(2)> red()
16711680
iex(3)> use Fledex.Config, colors: :css
{:module, Fledex.Config.Data,
<<70, 79, 82, 49, 0, 0, 25, 52, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 185,
255, 255, 255, 239, 8, 25, 69, 108, 105, 120, 105, 114, 46, 70, 108, 101,
100, 101, 120, 46, 67, 111, 110, 102, 105, 103, 46, ...>>, {:colors, 0}}
iex(4)> red()
error: function red/0 imported from both Fledex.Color.Names.CSS and Fledex.Color.Names.Wiki, call is ambiguous
└─ iex:4
** (CompileError) cannot compile code (errors have been logged)If you want to call use Fledex.Config several times in iex and want to
avoid the import issue, then you can call respawn/0 in-between.
You can also avoid the import issue if you specify the imports: false option,
which will avoid the import of the color functions. Even though you can't use the
color functions directly anymore (e.g. red() will not be possible), you can still
use the Fledex.Color protocol (e.g. Fledex.Color.to_colorint(:red) will continue
to work)
The above is also the reason why you should NOT use Fledex but import Fledex
in a component and be explicit in your color selection.
Summary
Functions
By using this module you configure Fledex. Currently the only setting is to define
the color modules to be used through the :colors option.
This function will cleanup a previously defined config. It's safe to call this funciton even if none has been defined.
Get the list of modules and their (non-overlapping) color names that are currently configured.
This function will create an AST
Checks whether we have defined a configuration.
Returns a list with the known color name modules (known to Fledex)
Functions
By using this module you configure Fledex. Currently the only setting is to define
the color modules to be used through the :colors option.
Caution
This will create the Fledex.Config.Data module. If you use this
module several times, previous definition will be replaced. This could lead
to unexpected behaviors.
See also create_config_ast/1 that is used internally for more details on what
is happening
Options:
:colors: You can specify a single color module, a list of color modules, or one of the special specifiers (:default,:all,:none,nil). When you specify a color module you can do so either through it's fully qualified module name (and thereby even load color modules that Fledex doesn't know about) or through its shortcut name (seeFledex.Config.known_color_modules/0):imports: Specify whether the color should be imported. (default; false). This avoids importing the color names (and any function name conflicts).
Special specifiers:
:all: All known color modules will be loaded. Be careful, because there are A LOT of color names, probably more than what you really need:default: This will load the core modules (seeFledex.Config.known_color_modules/0). If no:colorsoption is specified then that's also the set that will be loaded.:none: No color will be loaded (still theFledex.Config.Datawill be created. Compare this withnil)nil: This is similar to:noneexcept that theFledex.Config.Datawill not be created, and if it exists will be deleted.
@spec cleanup_old_config() :: :ok
This function will cleanup a previously defined config. It's safe to call this funciton even if none has been defined.
Note
Proably you don't want to call this function and just redefine your configuration to your likings
Get the list of modules and their (non-overlapping) color names that are currently configured.
This function will create an AST
The AST will provide the following functionality:
- defines the
Fledex.Config.Datawhich is used by this module (if available) - creates the necessary color module imports that are being defined
You can use this function directly, but you probably want to use the
macro __using__/1 (through use Fledex.Config, opts)
@spec exists?() :: boolean()
Checks whether we have defined a configuration.
If not, all function calls in this module will succeed, but will only contain defaults (probably quite empty results)
Returns a list with the known color name modules (known to Fledex)
Fledex is configured with a set of color name modules that can be retrieved through this function. A list is returned with a tuple consisting of:
module: The color name moduletype: Whether it's a:corecolor or an:optionalcolor. The former will get loaded as one of the default colorsshortcut_name: anatomname through which you can reference this module
It should be noted that the order is important in the case of name conflicts. Color name definitions from earlier modules take precedence.
Example:
- Given
ModuleAdefines:greenas0x00FF00 - Given
ModuleBdefines:greenas0x00AA00 - If
ModuleAis specied BEFOREModuleBthen:greenwill be defined as0x00FF00 - If
ModuleAis specified AFTERModuleBthen:greenwill be defined as0x00AA00