# `PhoenixDatastar.Helpers`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.2.0/lib/helpers.ex#L1)

Shared helper functions for PhoenixDatastar modules.

# `get_base_path`

```elixir
@spec get_base_path(String.t()) :: String.t()
```

Extracts the base path from a request path by stripping Datastar suffixes.

Removes `/stream` suffix and `/_event/:event` patterns to get the view's base path.

## Examples

    iex> PhoenixDatastar.Helpers.get_base_path("/counter/stream")
    "/counter"

    iex> PhoenixDatastar.Helpers.get_base_path("/counter/_event/increment")
    "/counter"

    iex> PhoenixDatastar.Helpers.get_base_path("/counter")
    "/counter"

# `get_session_map`

```elixir
@spec get_session_map(Plug.Conn.t()) :: map()
```

Extracts the session map from a Plug.Conn.

Merges the Plug session (from the session store) with all `conn.assigns`
set by plugs in the pipeline. Assign keys are stringified so they can be
pattern-matched in `mount/3` the same way as regular session keys.

Returns the session data if available, otherwise an empty map.

# `get_view_name`

```elixir
@spec get_view_name(module()) :: String.t()
```

Extracts the view module name (last part of module path).

## Examples

    iex> PhoenixDatastar.Helpers.get_view_name(MyApp.CounterStar)
    "CounterStar"

# `render_html`

```elixir
@spec render_html(module(), PhoenixDatastar.Socket.t()) :: Phoenix.HTML.Safe.t()
```

Renders a view's template with the socket's assigns.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
