Gonex v0.1.0 Gonex.View View Source

This module contains functions for rendering gon script.

Link to this section Summary

Link to this section Functions

Link to this function

render_gon(conn, namespace \\ "gon")

View Source

Renders gon script.

Optionally namespace can be specified. Default is "gon".

For converting Elixir map into JavaScript object under the hood it uses Jason.encode!/2 with option :escape set to :html_safe to prevent XSS.

Examples

iex>put_gon(conn, greeting: "Hello, World!")

iex>safe_to_string render_gon(conn)
"<script type=\"text/javascript\">window.gon={\"greeting\":\"Hello, World!\"}</script>"

iex>safe_to_string render_gon(conn, "myAppGon")
"<script type=\"text/javascript\">window.myAppGon={\"greeting\":\"Hello, World!\"}</script>"