Current section

Files

Jump to
ex_effective_bootstrap lib ex_effective_bootstrap icons.ex
Raw

lib/ex_effective_bootstrap/icons.ex

defmodule ExEffectiveBootstrap.Icons do
@moduledoc """
Use Feather and FontAwesome svg icons in your views"
= icon(:check)
"""
alias ExEffectiveBootstrap.Options
@svg_path "deps/ex_effective_bootstrap/priv/icons"
# icon(:check, class: 'big-4')
# icon('check', class: 'small-3')
@spec icon(atom | String.t(), Keyword.t()) :: Phoenix.HTML.Safe.t()
def icon(svg, opts \\ []) do
opts =
opts
|> Options.merge(class: "eb-icon eb-icon-#{svg}")
|> Enum.map(fn {key, value} -> "#{key}='#{value}'" end)
|> Enum.join(" ")
svg_tag =
File.read!("#{@svg_path}/#{svg}.svg")
|> String.replace("svg", "svg #{opts}", global: false)
{:safe, svg_tag}
end
end