khusnetdinov / Phoenix_gon
Licence: mit
🔥 Phoenix variables in your JavaScript without headache.
Stars: ✭ 84
Programming Languages
javascript
184084 projects - #8 most used programming language
elixir
2628 projects
Projects that are alternatives of or similar to Phoenix gon
gleam compile
Tiny hex package to make the development experience of using gleam in elixir (and especially phoenix projects) better.
Stars: ✭ 29 (-65.48%)
Mutual labels: hex, phoenix
Alpine Phoenix Builder
Up to date Alpine image with the latest language versions for staged Elixir and Phoenix builds.
Stars: ✭ 71 (-15.48%)
Mutual labels: phoenix, hex
Confex
Useful helper to read and use application configuration from environment variables.
Stars: ✭ 272 (+223.81%)
Mutual labels: environment-variables, hex
Envinject Plugin
This plugin makes it possible to setup a custom environment for your jobs
Stars: ✭ 74 (-11.9%)
Mutual labels: environment-variables
Phoenixengine
please update from this place https://gitee.com/manykit/PHOENIXEngine.git
Stars: ✭ 71 (-15.48%)
Mutual labels: phoenix
Ecto morph
morph your Ecto capabilities into the s t r a t o s p h e r e !
Stars: ✭ 72 (-14.29%)
Mutual labels: phoenix
Senv
Friends don't let friends leak secrets on their terminal window 🙈
Stars: ✭ 71 (-15.48%)
Mutual labels: environment-variables
Phoenix react playground
An example setup for a Phoenix+React project with sensible defaults.
Stars: ✭ 80 (-4.76%)
Mutual labels: phoenix
Pow
Robust, modular, and extendable user authentication system
Stars: ✭ 1,213 (+1344.05%)
Mutual labels: phoenix
Dotenv Java
🗝️ Dotenv is a no-dep, pure Java module that loads environment variables from a .env file
Stars: ✭ 72 (-14.29%)
Mutual labels: environment-variables
Colorhighlight
🎨 Lightweight Color Highlight colorizer for Sublime Text
Stars: ✭ 76 (-9.52%)
Mutual labels: hex
Ex admin
ExAdmin is an auto administration package for Elixir and the Phoenix Framework
Stars: ✭ 1,180 (+1304.76%)
Mutual labels: hex
Xcodecolorsense
🎈 An Xcode plugin that makes working with color easier
Stars: ✭ 79 (-5.95%)
Mutual labels: hex
Geoip
Elixir library to find geo location information given an IP address, hostname or Plug.Conn
Stars: ✭ 77 (-8.33%)
Mutual labels: phoenix
Env
Simple library to read environment variables and convert to simple types.
Stars: ✭ 73 (-13.1%)
Mutual labels: environment-variables
Env Providers
👷 Load Laravel service providers based on your application's environment.
Stars: ✭ 73 (-13.1%)
Mutual labels: environment-variables
Verk web
A dashboard for the job processing system that just verks! 🧛
Stars: ✭ 75 (-10.71%)
Mutual labels: phoenix
Your Phoenix variables in your JavaScript.
Installation
The package can be installed by adding phoenix_gon
to your list of dependencies in mix.exs
:
def deps do
[{:phoenix_gon, "~> 0.4.0"}]
end
Usage
Three steps configuration:
- You need add plug to
lib/project/router.ex
after plug:fetch_session
.
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.
- Add possibility to use view helper by adding
use PhoenixGon.View
in templates inweb/views/layout_view.ex
file:
defmodule Project.LayoutView do
# ...
import PhoenixGon.View
# ...
end
- Add helper
render_gon_script
to you layout in/web/templates/layout/app.html.eex
before main javascript file:
# ...
<%= render_gon_script(@conn) %>
<script src="<%= static_path(@conn, "/js/app.js") %>"></script>
</body>
Now you can read phoenix variables in browser console and javascript code.
Phoenix controllers
For using gon in controllers just add:
defmodule Project.Controller do
# ...
import PhoenixGon.Controller
# ...
end
Controller methods:
All controller variables are kept in assets
map.
-
put_gon
- Put variable to assets. -
update_gon
- Update variable in assets. -
drop_gon
- Drop variable in assets. -
get_gon
- Get variable from assets.
Example:
def index(conn, _params) do
conn = put_gon(conn, controller: variable)
render conn, "index.html"
end
def index(conn, _params) do
conn = put_gon(conn, controller: variable)
redirect conn, to: "/somewhere.html"
end
JavaScript
Gon object is kept in window
.
Browser
Now you can access to you variables in console:
// browser console
Gon.assets()
// Object {controller: "variable"}
JavaScript assets
// Somewhere in javascript modules
window.Gon.assets()
JavaScript methods:
Phoenix env methods:
-
getEnv()
- Returns current phoenix env. -
isDev()
- Returns boolean if development env. -
isProd()
- Returns boolean if production env. -
isCustomEnv(env)
- Return bollean if custom env.
Assets variables methods:
-
assets()
- Returns all variables setting in config and controllers. -
getAsset(key)
- Returns variable by key.
JSON Library
Per default the Poison
is used to encode JSON data, however this can be changed via the application configuration:
config :phoenix_gon, :json_library, Jason
Contributors
Special thanks to Andrey Soshchenko @getux.
License
The library is available as open source under the terms of the MIT License.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].