{"id":13507832,"url":"https://github.com/khusnetdinov/phoenix_routes_js","last_synced_at":"2025-04-23T18:09:50.788Z","repository":{"id":24437182,"uuid":"101511143","full_name":"khusnetdinov/phoenix_routes_js","owner":"khusnetdinov","description":"Phoenix routes helpers in JavaScript code.","archived":false,"fork":false,"pushed_at":"2022-03-24T14:58:41.000Z","size":12,"stargazers_count":21,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-23T18:09:45.527Z","etag":null,"topics":["helpers","javascript","phoenix-framework","routes"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khusnetdinov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-26T20:22:13.000Z","updated_at":"2024-06-26T05:15:18.000Z","dependencies_parsed_at":"2022-07-27T04:46:19.042Z","dependency_job_id":null,"html_url":"https://github.com/khusnetdinov/phoenix_routes_js","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khusnetdinov%2Fphoenix_routes_js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khusnetdinov%2Fphoenix_routes_js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khusnetdinov%2Fphoenix_routes_js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khusnetdinov%2Fphoenix_routes_js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khusnetdinov","download_url":"https://codeload.github.com/khusnetdinov/phoenix_routes_js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250487531,"owners_count":21438612,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["helpers","javascript","phoenix-framework","routes"],"created_at":"2024-08-01T02:00:40.430Z","updated_at":"2025-04-23T18:09:50.769Z","avatar_url":"https://github.com/khusnetdinov.png","language":"Elixir","funding_links":[],"categories":["ECMAScript"],"sub_categories":[],"readme":"# PhoenixRoutesJs  [![Hex.pm](https://img.shields.io/hexpm/v/plug.svg)](https://hex.pm/packages/phoenix_routes_js) [![Build Status](https://travis-ci.org/khusnetdinov/phoenix_routes_js.svg?branch=master)](https://travis-ci.org/khusnetdinov/phoenix_routes_js) [![Open Source Helpers](https://www.codetriage.com/khusnetdinov/phoenix_routes_js/badges/users.svg)](https://www.codetriage.com/khusnetdinov/phoenix_routes_js)\n## Phoenix routes helpers in javascript code\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed\nby adding `phoenix_routes_js` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:phoenix_routes_js, \"~\u003e 0.1.1\"}]\nend\n```\n\n## Usage\n\n### Two steps configuration:\n\n1) Add possibility to use view helper by adding `use PhoenixRoutesJs.View` in template `**_web/views/layout_view.ex` file:\n\n```elixir\ndefmodule Project.LayoutView do\n  ...\n  import PhoenixRoutesJs.View\n  ...\nend\n\n```\n\n2) Add helper `render_routes_script` to you layout in `**_web/templates/layout/app.html.eex` before main javascript file:\n\n```elixir\n  ...\n  \u003c%= render_routes_script(@conn) %\u003e\n  \u003cscript src=\"\u003c%= static_path(@conn, \"/js/app.js\") %\u003e\"\u003e\u003c/script\u003e\n  ...\n```\n\n### Examples\n\n```\n  render_routes_script(@conn)\n  render_routes_script(Project.Router)\n```\n\nNow you can use phoenix routes helpers in browser console and javascript code.\n\n\n### Helpers\n```\n   user_path   GET      /users            UserController :index    Routes.user_path('index')\n   user_path   GET      /users/:id/edit   UserController :edit     Routes.user_path('edit', ':id')\n   user_path   GET      /users/new        UserController :new      Routes.user_path('new')\n   user_path   GET      /users/:id        UserController :show     Routes.user_path('show', ':id')\n   user_path   POST     /users            UserController :create   Routes.user_path('create')\n   user_path   PATCH    /users/:id        UserController :update   Routes.user_path('update', ':id')\n               PUT      /users/:id        UserController :update\n   user_path   DELETE   /users/:id        UserController :delete   Routes.user_path('delete', ':id')\n```\n\n### JavaScript\n\nRoutes object is kept in `window`.\n\n#### Browser\n\nNow you can access to you helpers in console:\n\n```javascript\n// browser console\n\nRoutes.user_path('edit', 1)\n\n//=\u003e /users/1/edit\n```\n\n#### JavaScript assets\n\n```JavaScript\n// Somewhere in javascript modules\n\nwindow.Routes.user_path('edit', 1)\n\n//=\u003e /users/1/edit\n```\n\n#### JavaScript options:\n\nRoutes options:\n\n  - `format` - Add '.format' to request path string.\n  - `params` - Add query string to request path.\n\n```JavaScript\nRoutes.user_path('index', {format: 'json', params: {filter: 'query', sort: 'acs'}})\n\n//=\u003e \"/users.json?filter=query\u0026sort=acs\"\n```\n\n## License\n\nThe library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhusnetdinov%2Fphoenix_routes_js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhusnetdinov%2Fphoenix_routes_js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhusnetdinov%2Fphoenix_routes_js/lists"}