Skip to content

Commit d71c9a7

Browse files
committed
Make sure atoms can be passed onto class, class_name and class_selector
The atoms will be converted to string before retrieving it from a stylesheet definition.
1 parent 3815e1b commit d71c9a7

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/ex_css_modules/ex_css_modules.ex

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ defmodule ExCSSModules do
9696
iex> class_name(%{"hello" => "world"}, "hello", "anything")
9797
"world"
9898
99+
iex> class_name(%{"hello" => "world"}, :hello, true)
100+
"world"
101+
99102
iex> class_name(%{"hello" => "world"}, "hello", false)
100103
nil
101104
@@ -111,8 +114,8 @@ defmodule ExCSSModules do
111114
Returns the class name or class names from the definition map, concatenated as
112115
one string separated by spaces.
113116
114-
Second argument can be a string name of the key, a tuple with `{key, boolean}`
115-
or a list of keys or tuples.
117+
Second argument can be a string or atom name of the key, a tuple with
118+
`{key, boolean}` or a list of keys or tuples.
116119
117120
## Examples
118121
@@ -137,6 +140,9 @@ defmodule ExCSSModules do
137140
iex> class_name(%{"hello" => "world", "foo" => "bar"}, [{"hello", true}, {"foo", false}])
138141
"world"
139142
143+
iex> class_name(%{"hello" => "world", "foo" => "bar"}, [{:hello, true}, {:foo, false}])
144+
"world"
145+
140146
iex> class_name(%{"hello" => "world", "foo" => "bar"}, [{"hello", false}])
141147
nil
142148
@@ -153,6 +159,9 @@ defmodule ExCSSModules do
153159

154160
def class_name(definition, {key, return_class?}), do: class_name(definition, key, return_class?)
155161

162+
def class_name(definition, key) when is_atom(key),
163+
do: key |> Atom.to_string() |> (&class_name(definition, &1)).()
164+
156165
def class_name(definition, key) do
157166
definition
158167
|> stylesheet()
@@ -177,6 +186,9 @@ defmodule ExCSSModules do
177186
iex> class_selector(%{ "hello" => "world"}, "hello")
178187
".world"
179188
189+
iex> class_selector(%{ "hello" => "world"}, :hello)
190+
".world"
191+
180192
iex> class_selector(%{ "hello" => "world", "foo" => "bar"}, ["hello", "foo"])
181193
".world.bar"
182194

0 commit comments

Comments
 (0)