Unpoly v1.3.0 Unpoly View Source

A Plug adapter and helpers for Unpoly, the unobtrusive JavaScript framework.

Options

  • :cookie_name - the cookie name where the request method is echoed to. Defaults to "_up_method".
  • :cookie_opts - additional options to pass to method cookie. See Plug.Conn.put_resp_cookie/4 for all available options.

Link to this section Summary

Functions

Returns whether the given CSS selector is targeted by the current fragment update for either a success or a failed response.

Returns the mode of the layer targeted for a failed fragment update.

Returns the CSS selector for a fragment that Unpoly will update in case of an failed response. Server errors or validation failures are all examples for a failed response (non-200 status code).

Returns whether the given CSS selector is targeted by the current fragment update in case of a failed response (non-200 status code).

Returns the mode of the targeted layer.

Sets the value of the "X-Up-Accept-Layer" response header.

Sets the value of the "X-Up-Dismiss-Layer" response header.

Sets the value of the "X-Up-Events" response header.

Sets the value of the "X-Up-Location" response header.

Sets the value of the "X-Up-Method" response header.

Sets the value of the "X-Up-Target" response header.

Forces Unpoly to use the given string as the document title when processing this response.

Returns the timestamp of an existing fragment that is being reloaded.

Returns the timestamp of an existing fragment that is being reloaded.

Returns the CSS selector for a fragment that Unpoly will update in case of a successful response (200 status code).

Returns whether the given CSS selector is targeted by the current fragment update in case of a successful response (200 status code).

Returns whether the current request is a page fragment update triggered by an Unpoly frontend.

Returns whether the current form submission should be validated (and not be saved to the database).

If the current form submission is a validation, this returns the name attribute of the form field that has triggered the validation.

Returns the current Unpoly version.

Link to this section Functions

Link to this function

any_target?(conn, tested_target)

View Source
any_target?(Plug.Conn.t(), String.t()) :: boolean()

Returns whether the given CSS selector is targeted by the current fragment update for either a success or a failed response.

Note that the matching logic is very simplistic and does not actually know how your page layout is structured. It will return true if the tested selector and the requested CSS selector matches exactly, or if the requested selector is body or html.

Always returns true if the current request is not an Unpoly fragment update.

Link to this function

fail_mode(conn)

View Source
fail_mode(Plug.Conn.t()) :: String.t() | nil

Returns the mode of the layer targeted for a failed fragment update.

A fragment update is considered failed if the server responds with a status code other than 2xx, but still renders HTML.

Server-side code is free to render different HTML for different modes. For example, you might prefer to not render a site navigation for overlays.

Link to this function

fail_target(conn)

View Source
fail_target(Plug.Conn.t()) :: String.t() | nil

Returns the CSS selector for a fragment that Unpoly will update in case of an failed response. Server errors or validation failures are all examples for a failed response (non-200 status code).

The Unpoly frontend will expect an HTML response containing an element that matches this selector.

Server-side code is free to optimize its response by only returning HTML that matches this selector.

Link to this function

fail_target?(conn, tested_target)

View Source
fail_target?(Plug.Conn.t(), String.t()) :: boolean()

Returns whether the given CSS selector is targeted by the current fragment update in case of a failed response (non-200 status code).

Note that the matching logic is very simplistic and does not actually know how your page layout is structured. It will return true if the tested selector and the requested CSS selector matches exactly, or if the requested selector is body or html.

Always returns true if the current request is not an Unpoly fragment update.

Returns the mode of the targeted layer.

Server-side code is free to render different HTML for different modes. For example, you might prefer to not render a site navigation for overlays.

Link to this function

put_resp_accept_layer_header(conn, value)

View Source
put_resp_accept_layer_header(Plug.Conn.t(), term()) :: Plug.Conn.t()

Sets the value of the "X-Up-Accept-Layer" response header.

Link to this function

put_resp_dismiss_layer_header(conn, value)

View Source
put_resp_dismiss_layer_header(Plug.Conn.t(), term()) :: Plug.Conn.t()

Sets the value of the "X-Up-Dismiss-Layer" response header.

Link to this function

put_resp_events_header(conn, value)

View Source
put_resp_events_header(Plug.Conn.t(), term()) :: Plug.Conn.t()

Sets the value of the "X-Up-Events" response header.

Link to this function

put_resp_location_header(conn, value)

View Source
put_resp_location_header(Plug.Conn.t(), String.t()) :: Plug.Conn.t()

Sets the value of the "X-Up-Location" response header.

Link to this function

put_resp_method_header(conn, value)

View Source
put_resp_method_header(Plug.Conn.t(), String.t()) :: Plug.Conn.t()

Sets the value of the "X-Up-Method" response header.

Link to this function

put_resp_target_header(conn, value)

View Source
put_resp_target_header(Plug.Conn.t(), String.t()) :: Plug.Conn.t()

Sets the value of the "X-Up-Target" response header.

Link to this function

put_title(conn, new_title)

View Source
put_title(Plug.Conn.t(), String.t()) :: Plug.Conn.t()

Forces Unpoly to use the given string as the document title when processing this response.

This is useful when you skip rendering the <head> in an Unpoly request.

Returns the timestamp of an existing fragment that is being reloaded.

The timestamp must be explicitely set by the user as an [up-time] attribute on the fragment. It should indicate the time when the fragment's underlying data was last changed.

Link to this function

reload_from_time(conn)

View Source
reload_from_time(Plug.Conn.t()) :: String.t() | nil

Returns the timestamp of an existing fragment that is being reloaded.

The timestamp must be explicitely set by the user as an [up-time] attribute on the fragment. It should indicate the time when the fragment's underlying data was last changed.

Returns the CSS selector for a fragment that Unpoly will update in case of a successful response (200 status code).

The Unpoly frontend will expect an HTML response containing an element that matches this selector.

Server-side code is free to optimize its successful response by only returning HTML that matches this selector.

Link to this function

target?(conn, tested_target)

View Source
target?(Plug.Conn.t(), String.t()) :: boolean()

Returns whether the given CSS selector is targeted by the current fragment update in case of a successful response (200 status code).

Note that the matching logic is very simplistic and does not actually know how your page layout is structured. It will return true if the tested selector and the requested CSS selector matches exactly, or if the requested selector is body or html.

Always returns true if the current request is not an Unpoly fragment update.

Returns whether the current request is a page fragment update triggered by an Unpoly frontend.

This will eventually just check for the X-Up-Version header. Just in case a user still has an older version of Unpoly running on the frontend, we also check for the X-Up-Target header.

Alias for Unpoly.unpoly?/1

Returns whether the current form submission should be validated (and not be saved to the database).

Link to this function

validate_name(conn)

View Source
validate_name(Plug.Conn.t()) :: String.t() | nil

If the current form submission is a validation, this returns the name attribute of the form field that has triggered the validation.

Link to this function

version(conn)

View Source
version(Plug.Conn.t()) :: String.t() | nil

Returns the current Unpoly version.

The version is guaranteed to be set for all Unpoly requests.