View Source PhoenixSVG (phoenix_svg v1.0.3)

Use inline SVGs in Phoenix

Link to this section Summary

Functions

List all of the SVG files in the given directory.

Reads a file and parses out the name and path.

Renders an inline svg from a cached file.

Converts a map or keyword list into HTML-safe attributes.

Link to this section Functions

List all of the SVG files in the given directory.

Returns a list of all the files, and an MD5 hash of the list so it can be determined if the list changed and needs to be re-compiled.

Link to this function

read_file!(filepath, basepath)

View Source

Reads a file and parses out the name and path.

The name will be the filename without the extension, and the path will be a list of directory names the file is nested in relative to the base path.

Renders an inline svg from a cached file.

attributes

Attributes

  • :name - The name of the svg file, excluding the .svg extension.
  • :path - A list of nested paths if the file is not in the root.

Any other attributes will be passed through to the <svg> tag.

Note that this function should never be called directly with PhoenixSVG.svg. It's meant to be called from the svg function generated in the __using__ macro. See the Getting Started guide.

Link to this function

to_safe_html_attrs(data)

View Source

Converts a map or keyword list into HTML-safe attributes.

Any keys that contain an underscore will be converted to a dash in the HTMl attribute. For example, %{foo_bar: "foo_bar"} will result in the attribute foo-bar="foo_bar".