az (arizona v0.4.0)
View SourceShort alias module for arizona_template and arizona_stateful.
Provides the same runtime API surface as arizona_template under a
shorter prefix so handcrafted templates that don't use the macros can
be written as az:get(...), az:html(...), etc. It also re-exports
the common types so users writing handler specs can reference them
through a single module: az:bindings(), az:mount_ret(), etc.
The parse transform recognizes both arizona_template:html/1 and
az:html/1 (same for each/2), so either alias compiles to the same
optimized template map.
Parse transform stubs
html/1, native/1, terminal/1 and each/2 are stubs -- they exist
so callers can write az:html({...}) and the parse transform can detect
and replace the call. They never actually execute at runtime; calling
them directly errors with parse_transform_not_applied.
Layout helper
inner_content/1 is the only function that does real runtime work
not delegated to arizona_template. It extracts the inner_content
binding, used by stateless layouts to render the wrapped page. The
value is an opaque nested template for a content slot -- see the
function's own docs.
Summary
Functions
Parse transform stub. The parse transform replaces az:each(Fun, Source)
with compiled iteration code; this runtime body is only reached if the
parse transform did not run, in which case it errors with
parse_transform_not_applied like the other stubs.
Alias for arizona_template:get/2.
Parse transform stub. Calling this at runtime errors -- the parse
transform replaces az:html(...) (or arizona_template:html(...))
calls with compiled template maps before code generation.
Returns the inner_content binding from a layout's bindings map -- the rendered
page this layout wraps. Used by stateless layout modules, normally through the
?inner_content macro, to place the wrapped page content.
Alias for arizona_template:local/2.
Parse transform stub. The parse transform replaces az:native(...) (or
arizona_template:native(...)) calls with compiled JSON template maps before
code generation.
Alias for arizona_template:raw/1.
Parse transform stub. The parse transform replaces az:terminal(...) (or
arizona_template:terminal(...)) calls with compiled ANSI template maps before
code generation.
Alias for arizona_template:track/1.
Alias for arizona_template:with/2.
Types
-type bindings() :: arizona_template:bindings().
-type effect() :: arizona_stateful:effect().
-type effects() :: arizona_stateful:effects().
-type error_info() :: arizona_http:error_info().
-type event_name() :: arizona_stateful:event_name().
-type event_payload() :: arizona_stateful:event_payload().
-type handle_drain_ret() :: arizona_stateful:handle_drain_ret().
-type handle_event_ret() :: arizona_stateful:handle_event_ret().
-type handle_info_ret() :: arizona_stateful:handle_info_ret().
-type handle_update_ret() :: arizona_stateful:handle_update_ret().
-type mount_ret() :: arizona_stateful:mount_ret().
-type render_fun() :: arizona_template:render_fun().
-type render_ret() :: arizona_stateful:render_ret().
-type request() :: arizona_req:request().
-type resets() :: arizona_stateful:resets().
-type template() :: arizona_template:template().
-type unmount_ret() :: arizona_stateful:unmount_ret().
Functions
Parse transform stub. The parse transform replaces az:each(Fun, Source)
with compiled iteration code; this runtime body is only reached if the
parse transform did not run, in which case it errors with
parse_transform_not_applied like the other stubs.
Alias for arizona_template:get/2.
-spec get(Key, Bindings, Default) -> term() when Key :: term(), Bindings :: map(), Default :: term().
Alias for arizona_template:get/3.
-spec get_lazy(Key, Bindings, DefaultFun) -> term() when Key :: term(), Bindings :: map(), DefaultFun :: fun(() -> term()).
Alias for arizona_template:get_lazy/3.
Parse transform stub. Calling this at runtime errors -- the parse
transform replaces az:html(...) (or arizona_template:html(...))
calls with compiled template maps before code generation.
Returns the inner_content binding from a layout's bindings map -- the rendered
page this layout wraps. Used by stateless layout modules, normally through the
?inner_content macro, to place the wrapped page content.
Opaque, and it goes in a content slot whole. The value is a nested template
(#{s := [Page], d := []}) -- not iodata, not a binary. That is what lets a
content slot splice the page verbatim instead of copying and UTF-8-re-decoding
it once per layout layer.
Placements that work, whether the slot is the layout's own or one it hands the page on to (the page renders as itself, unescaped, in all of them):
?html([~"<main>", ?inner_content, ~"</main>"]) %% the slot
?html([case Hide of true -> ~""; false -> ?inner_content end]) %% a case tail
?html([?stateless(fun body/1, #{content => ?inner_content})]) %% a child's propPlacements that raise, because the value is opaque:
- an attribute value --
bad_template_value, carrying the whole page in the error term (a rendered page inside an attribute has no meaning); - measured or inspected --
iolist_size(az:inner_content(Bindings))raisesbadarg, as does anything else expecting iodata; - wrapped in
?raw/1--bad_template_value. There is nothing to opt out of: a content slot already splices the page unescaped, so?raw(?inner_content)is redundant. Drop the wrapper; - inside a list the template cannot see -- a comprehension, or a list
built at runtime, is one opaque value and raises. A literal content-slot list
such as
[~"<hr>", ?inner_content]is fine: it compiles as a fragment, so the page gets a slot of its own.
The value stays opaque rather than paying the per-layer copy that would make those degrade quietly.
Errors with {badkey, inner_content} when the bindings carry no page, i.e. when
the module was rendered as something other than a layout.
Alias for arizona_template:local/2.
Parse transform stub. The parse transform replaces az:native(...) (or
arizona_template:native(...)) calls with compiled JSON template maps before
code generation.
Alias for arizona_template:raw/1.
-spec stateful(Handler, Props) -> arizona_template:stateful_descriptor() when Handler :: module(), Props :: map().
Alias for arizona_template:stateful/2.
-spec stateless(Callback, Props) -> arizona_template:stateless_descriptor() when Callback :: fun((map()) -> arizona_template:template()), Props :: map().
Alias for arizona_template:stateless/2.
-spec stateless(Handler, Fun, Props) -> arizona_template:stateless_descriptor() when Handler :: module(), Fun :: atom(), Props :: map().
Alias for arizona_template:stateless/3.
Parse transform stub. The parse transform replaces az:terminal(...) (or
arizona_template:terminal(...)) calls with compiled ANSI template maps before
code generation.
-spec track(Key) -> ok when Key :: term().
Alias for arizona_template:track/1.
Alias for arizona_template:with/2.