Skip to content

Turns an icon collection into eex templates so that you can assign CSS classes to them

Notifications You must be signed in to change notification settings

space-rocket/modify-svgs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ModifySvgs

Signature

  @moduledoc """
  Documentation for `ModifySvgs`.
  """

  @doc """
  convert_svg_to_eex/3

  ## Examples

      iex> ModifySvgs.convert_svg_to_eex("bootstrap-icons", "../my_app/lib/my_app_web/templates/icons", "<%= assigns[:svg_class] %>")
      "<svg class="<%= assigns[:svg_class] %>..." ...some long svg stuff</svg>", "<svg class="<%= assigns[:svg_class] %>..." ...some long svg stuff</svg>"

  """

How to use

To use go into iex -S mix

Then run:

ModifySvgs.convert_svg_to_eex("bootstrap-icons", "../my_app/lib/my_app_web/templates/icons", "<%= assigns[:svg_class] %>")

The above command simple moves all the bootstrap-icons to the templates directory with html.eex extension and injects <%= assigns[:svg_class] %> into the svg's css class.

Next step is to create a view for your svgs.

(Inside your app)

lib/my_app_web/views/svg_view.ex

defmodule MyAppWeb.SvgView do
  use MyAppWeb, :view

end

That is it!

You can now use svgs icons inside your eex templates like this:

<%= render MyAppWeb.SvgView, "_emoji-sunglasses.html", svg_class: "text-teal-500" %>

Installation

~~If available in Hex(spoiler, its not), the package can be installed by adding modify_svgs to your list of dependencies in mix.exs:

def deps do
  [
    {:modify_svgs, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/modify_svgs. ~~

About

Turns an icon collection into eex templates so that you can assign CSS classes to them

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages