Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/khusnetdinov/phoenix_gon
:fire: Phoenix variables in your JavaScript without headache.
https://github.com/khusnetdinov/phoenix_gon
controller-variables environment-variables hex javascript phoenix phoenix-env phoenix-variables
Last synced: 4 days ago
JSON representation
:fire: Phoenix variables in your JavaScript without headache.
- Host: GitHub
- URL: https://github.com/khusnetdinov/phoenix_gon
- Owner: khusnetdinov
- License: mit
- Created: 2017-04-25T15:21:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-10T17:00:56.000Z (about 1 year ago)
- Last Synced: 2024-10-09T13:08:04.084Z (25 days ago)
- Topics: controller-variables, environment-variables, hex, javascript, phoenix, phoenix-env, phoenix-variables
- Language: Elixir
- Homepage:
- Size: 52.7 KB
- Stars: 99
- Watchers: 5
- Forks: 21
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Allow you to pass Phoenix environment or controller variables to JavaScript without problems. (ECMAScript)
- fucking-awesome-elixir - phoenix_gon - Allow you to pass Phoenix environment or controller variables to JavaScript without problems. (ECMAScript)
- awesome-elixir - phoenix_gon - Allow you to pass Phoenix environment or controller variables to JavaScript without problems. (ECMAScript)
README
# PhoenixGon [![Hex.pm](https://img.shields.io/hexpm/v/plug.svg)](https://hex.pm/packages/phoenix_gon) [![Build Status](https://travis-ci.org/khusnetdinov/phoenix_gon.svg?branch=master)](https://travis-ci.org/khusnetdinov/phoenix_gon) [![Open Source Helpers](https://www.codetriage.com/khusnetdinov/phoenix_gon/badges/users.svg)](https://www.codetriage.com/khusnetdinov/phoenix_gon)
## Your Phoenix variables in your JavaScript.
![img](http://res.cloudinary.com/dtoqqxqjv/image/upload/v1492849051/github/gon.png)
## Installation
The package can be installed by adding `phoenix_gon` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:phoenix_gon, "~> 0.4.0"}]
end
```## Usage
### Three steps configuration:
1. You need add plug to `lib/project/router.ex` after plug `:fetch_session`.
```elixir
defmodule Project.Router do
# ...pipeline :browser do
# ...plug :fetch_session
plug PhoenixGon.Pipeline# ...
end# ...
end
```Plug accepts options:
- `:env` - this option for hard overloading Mix.env.
- `:namespace` - namespace for javascript object in global window space.
- `:assets` - map for keeping permanent variables in javascript.
- `:camel_case` - if set to true, all assets names will be converted to camel case format on render.2. Add possibility to use view helper by adding `use PhoenixGon.View` in templates in `web/views/layout_view.ex` file:
```elixir
defmodule Project.LayoutView do
# ...import PhoenixGon.View
# ...
end```
3. Add helper `render_gon_script` to you layout in `/web/templates/layout/app.html.eex` before main javascript file:
```elixir
# ...
<%= render_gon_script(@conn) %>
">