Helpers for generating Datastar action expressions and encoding module names.
Examples
# In a Phoenix template:
<button data-on:click={Dstar.post(MyApp.CounterHandler, "increment")}>+</button>
# Other HTTP verbs:
<button data-on:click={Dstar.delete(MyApp.ItemHandler, "remove")}>×</button>
# Dynamic module (reads from signal):
<button data-on:click={Dstar.post("increment")}>+</button>
Summary
Functions
Decodes a URL-safe module name back to an Elixir module.
Generates a @delete(...) action expression for Datastar attributes.
Generates a @delete(...) expression with a URL prefix.
Encodes a module name for URL use.
Generates a @get(...) action expression for Datastar attributes.
Generates a @get(...) expression with a URL prefix.
Generates a @patch(...) action expression for Datastar attributes.
Generates a @patch(...) expression with a URL prefix.
Generates a @post(...) action expression for Datastar attributes.
Generates a @post(...) expression with a URL prefix.
Generates a @put(...) action expression for Datastar attributes.
Generates a @put(...) expression with a URL prefix.
Functions
Decodes a URL-safe module name back to an Elixir module.
Returns {:ok, module} if the module exists, :error otherwise.
Examples
iex> Dstar.Actions.decode_module("my_app-counter_view")
{:ok, MyApp.CounterView}
@spec delete(module(), String.t()) :: String.t()
@spec delete( String.t(), keyword() ) :: String.t()
Generates a @delete(...) action expression for Datastar attributes.
CSRF is handled automatically — Datastar sends all signals (including
csrf) as body params, and RenameCsrfParam maps it to _csrf_token.
With a known module (compile-time):
iex> Dstar.Actions.delete(MyApp.CounterHandler, "increment")
"@delete('/ds/my_app-counter_handler/increment')"With a dynamic module signal (runtime on client):
iex> Dstar.Actions.delete("increment")
"@delete('/ds/' + $_dstar_module + '/increment')"With a URL prefix:
iex> Dstar.Actions.delete(MyApp.Handler, "save", prefix: "/ws")
"@delete('/ws/ds/my_app-handler/save')"Options
:prefix— URL path prefix (e.g."/my-workspace"). Only for the module form.:module— Override the module signal name (default:$_dstar_module). Only for the dynamic form.
Generates a @delete(...) expression with a URL prefix.
Example
iex> Dstar.Actions.delete(MyApp.Handler, "save", prefix: "/my-workspace")
"@delete('/my-workspace/ds/my_app-handler/save')"
Encodes a module name for URL use.
Examples
iex> Dstar.Actions.encode_module(MyApp.CounterView)
"my_app-counter_view"
iex> Dstar.Actions.encode_module(MyApp.Web.ChatView)
"my_app-web-chat_view"
Generates a @get(...) action expression for Datastar attributes.
CSRF is handled automatically — Datastar sends all signals (including
csrf) as body params, and RenameCsrfParam maps it to _csrf_token.
With a known module (compile-time):
iex> Dstar.Actions.get(MyApp.CounterHandler, "increment")
"@get('/ds/my_app-counter_handler/increment')"With a dynamic module signal (runtime on client):
iex> Dstar.Actions.get("increment")
"@get('/ds/' + $_dstar_module + '/increment')"With a URL prefix:
iex> Dstar.Actions.get(MyApp.Handler, "save", prefix: "/ws")
"@get('/ws/ds/my_app-handler/save')"Options
:prefix— URL path prefix (e.g."/my-workspace"). Only for the module form.:module— Override the module signal name (default:$_dstar_module). Only for the dynamic form.
Generates a @get(...) expression with a URL prefix.
Example
iex> Dstar.Actions.get(MyApp.Handler, "save", prefix: "/my-workspace")
"@get('/my-workspace/ds/my_app-handler/save')"
Generates a @patch(...) action expression for Datastar attributes.
CSRF is handled automatically — Datastar sends all signals (including
csrf) as body params, and RenameCsrfParam maps it to _csrf_token.
With a known module (compile-time):
iex> Dstar.Actions.patch(MyApp.CounterHandler, "increment")
"@patch('/ds/my_app-counter_handler/increment')"With a dynamic module signal (runtime on client):
iex> Dstar.Actions.patch("increment")
"@patch('/ds/' + $_dstar_module + '/increment')"With a URL prefix:
iex> Dstar.Actions.patch(MyApp.Handler, "save", prefix: "/ws")
"@patch('/ws/ds/my_app-handler/save')"Options
:prefix— URL path prefix (e.g."/my-workspace"). Only for the module form.:module— Override the module signal name (default:$_dstar_module). Only for the dynamic form.
Generates a @patch(...) expression with a URL prefix.
Example
iex> Dstar.Actions.patch(MyApp.Handler, "save", prefix: "/my-workspace")
"@patch('/my-workspace/ds/my_app-handler/save')"
Generates a @post(...) action expression for Datastar attributes.
CSRF is handled automatically — Datastar sends all signals (including
csrf) as body params, and RenameCsrfParam maps it to _csrf_token.
With a known module (compile-time):
iex> Dstar.Actions.post(MyApp.CounterHandler, "increment")
"@post('/ds/my_app-counter_handler/increment')"With a dynamic module signal (runtime on client):
iex> Dstar.Actions.post("increment")
"@post('/ds/' + $_dstar_module + '/increment')"With a URL prefix:
iex> Dstar.Actions.post(MyApp.Handler, "save", prefix: "/ws")
"@post('/ws/ds/my_app-handler/save')"Options
:prefix— URL path prefix (e.g."/my-workspace"). Only for the module form.:module— Override the module signal name (default:$_dstar_module). Only for the dynamic form.
Generates a @post(...) expression with a URL prefix.
Example
iex> Dstar.Actions.post(MyApp.Handler, "save", prefix: "/my-workspace")
"@post('/my-workspace/ds/my_app-handler/save')"
Generates a @put(...) action expression for Datastar attributes.
CSRF is handled automatically — Datastar sends all signals (including
csrf) as body params, and RenameCsrfParam maps it to _csrf_token.
With a known module (compile-time):
iex> Dstar.Actions.put(MyApp.CounterHandler, "increment")
"@put('/ds/my_app-counter_handler/increment')"With a dynamic module signal (runtime on client):
iex> Dstar.Actions.put("increment")
"@put('/ds/' + $_dstar_module + '/increment')"With a URL prefix:
iex> Dstar.Actions.put(MyApp.Handler, "save", prefix: "/ws")
"@put('/ws/ds/my_app-handler/save')"Options
:prefix— URL path prefix (e.g."/my-workspace"). Only for the module form.:module— Override the module signal name (default:$_dstar_module). Only for the dynamic form.
Generates a @put(...) expression with a URL prefix.
Example
iex> Dstar.Actions.put(MyApp.Handler, "save", prefix: "/my-workspace")
"@put('/my-workspace/ds/my_app-handler/save')"