z_render (zotonic_core v1.0.0-rc.17)

Render routines using wires and actions. Based on Nitrogen, which is copyright (c) 2008-2009 Rusty Klophaus

Summary

Functions

Prepend extra arguments to an action. The arguments are prepended to the list of action arguments, overruling or adding existing arguments.

Set the contents of an element to the the html fragment

Add a html after the target element

Append a html fragment at the bottom of the contents of an element

Append a html fragment at the bottom of the contents of an element

Insert a html fragment at the top of the contents of an element

Remove all scripts from the context, resetting it back to a clean sheet.

Map a target id to a css selector

Map a target id to a css selector, check the Args proplist for additional selectors

Collect all scripts in the context, returns an iolist with javascript.

Add a html after the target element

Add a html before the target element

Append a html fragment at the bottom of the contents of an element

Insert a html fragment at the top of the contents of an element

Make a javascript to call the postback, posting an encoded string containing callback information. The PostbackTag is send to the server, EventType is normally the atom 'postback'.

Make an encoded string containing information which module and function to call.

Replace the placeholders with their rendered content and collect all scripts from the mixed html and context. The result is a clean HTML tree and can be used for return by controllers.

Quote a css selector (assume no escaping needed...)

Render adds output to the render-state of the context. Makes sure that the added output is an iolist The stored render state is later used in output/2

Render a css selector, allow direct expressions like

Render adds output to the render field of the context state. Do update the context for possible changes in scripts etc.

Render a validator to the correct javascript. Args are all arguments of the validator scomp. This renders an allocation of the initial validator and then appends all validations. 'type' holds multiple validations. Validations are of the form: {validator, [Args]}

Replace an element to the the html fragment

Set the value of an input element.

Set the contents of an element to the the html fragment

Set the contents of an iframe to the generated html.

Set the contents of all elements matching the css selector to the the html fragment

Set the contents of all elements matching the css selector to the the html fragment

Add an input validator to the list of known validators, used when rendering custom validators

Types

action/0

-type action() :: {atom(), proplists:proplist()}.

ctx_rs/0

-type ctx_rs() :: render_state() | z:context().

html_element_id/0

-type html_element_id() :: binary() | string() | undefined.

render_state/0

-type render_state() ::
          #render_state{updates :: list(),
                        actions :: list(),
                        content_scripts :: list(),
                        scripts :: list(),
                        wire :: list(),
                        validators :: list(),
                        render :: list()}.

Functions

action_with_args(Action, Args)

-spec action_with_args(Action, Args) -> Action1
                          when
                              Action :: MaybeAction | [MaybeAction],
                              MaybeAction :: action() | [Action] | undefined,
                              Args :: proplists:proplist(),
                              Action1 :: action() | [action()].

Prepend extra arguments to an action. The arguments are prepended to the list of action arguments, overruling or adding existing arguments.

add_script(Script, Context)

-spec add_script(Script, Context) -> NewContext
                    when
                        Script :: iodata() | undefined,
                        Context :: z:context(),
                        NewContext :: z:context().

appear(TargetId, Html, Context)

Set the contents of an element to the the html fragment

appear_after(TargetId, Html, Context)

Add a html after the target element

appear_after_selector(CssSelector, Html, Context)

appear_after_selector_js(CssSelector, Html)

appear_before(TargetId, Html, Context)

Append a html fragment at the bottom of the contents of an element

appear_before_selector(CssSelector, Html, Context)

appear_before_selector_js(CssSelector, Html)

appear_bottom(TargetId, Html, Context)

Append a html fragment at the bottom of the contents of an element

appear_bottom_selector(CssSelector, Html, Context)

appear_bottom_selector_js(CssSelector, Html)

appear_replace(TargetId, Html, Context)

appear_replace_selector(CssSelector, Html, Context)

appear_replace_selector_js(CssSelector, Html)

appear_selector(CssSelector, Html, Context)

appear_selector_js(CssSelector, Html)

appear_top(TargetId, Html, Context)

Insert a html fragment at the top of the contents of an element

appear_top_selector(CssSelector, Html, Context)

appear_top_selector_js(CssSelector, Html)

clean(Context)

-spec clean(z:context()) -> z:context().

Remove all scripts from the context, resetting it back to a clean sheet.

css_selector(TargetId)

Map a target id to a css selector

css_selector(TargetId, Args)

Map a target id to a css selector, check the Args proplist for additional selectors

dialog(Title, Template, Vars, Context)

-spec dialog(Title, Template, Vars, Context) -> Context1
                when
                    Title :: string() | binary() | z:trans() | undefined,
                    Template ::
                        template_compiler:template() |
                        #module_index{key ::
                                          #module_index_key{site :: atom(),
                                                            type ::
                                                                z_module_indexer:key_type() | undefined,
                                                            name ::
                                                                atom() | binary() | {binary(), binary()}},
                                      filepath :: file:filename_all() | undefined,
                                      module :: atom() | undefined,
                                      erlang_module :: atom() | undefined,
                                      tag :: integer() | undefined},
                    Vars :: list() | map(),
                    Context :: z:context(),
                    Context1 :: z:context().

dialog_close(Context)

-spec dialog_close(z:context()) -> z:context().

dialog_close(Level, Context)

-spec dialog_close(Level, z:context()) -> z:context() when Level :: non_neg_integer().

get_script(Context)

-spec get_script(z:context()) -> iolist().

Collect all scripts in the context, returns an iolist with javascript.

growl(Text, Context)

-spec growl(unicode:chardata(), z:context()) -> z:context().

growl(Text, Type, Stay, Context)

growl_error(Text, Context)

-spec growl_error(unicode:chardata(), z:context()) -> z:context().

insert_after(TargetId, Html, Context)

Add a html after the target element

insert_after_selector(CssSelector, Html, Context)

insert_after_selector_js(CssSelector, Html)

insert_before(TargetId, Html, Context)

Add a html before the target element

insert_before_selector(CssSelector, Html, Context)

insert_before_selector_js(CssSelector, Html)

insert_bottom(TargetId, Html, Context)

Append a html fragment at the bottom of the contents of an element

insert_bottom_selector(CssSelector, Html, Context)

insert_bottom_selector_js(CssSelector, Html)

insert_top(TargetId, Html, Context)

Insert a html fragment at the top of the contents of an element

insert_top_selector(CssSelector, Html, Context)

insert_top_selector_js(CssSelector, Html)

make_postback(PostbackTag, EventType, TriggerId, TargetId, Delegate, Context)

-spec make_postback(term(), term(), term(), term(), term(), z:context()) -> {iodata(), term()}.

Make a javascript to call the postback, posting an encoded string containing callback information. The PostbackTag is send to the server, EventType is normally the atom 'postback'.

make_postback(PostbackTag, EventType, TriggerId, TargetId, Delegate, QArgs, Context)

make_postback_info(Tag, EventType, TriggerId, TargetId, Delegate, Context)

Make an encoded string containing information which module and function to call.

make_validation_postback(Validator, Context)

make_validation_postback(Validator, Args, Context)

output(MixedHtml, Context)

-spec output(term(), z:context()) -> {iolist(), z:context()}.

Replace the placeholders with their rendered content and collect all scripts from the mixed html and context. The result is a clean HTML tree and can be used for return by controllers.

overlay(Template, Vars, Context)

-spec overlay(Template, Vars, Context) -> Context1
                 when
                     Template ::
                         template_compiler:template() |
                         #module_index{key ::
                                           #module_index_key{site :: atom(),
                                                             type ::
                                                                 z_module_indexer:key_type() | undefined,
                                                             name ::
                                                                 atom() |
                                                                 binary() |
                                                                 {binary(), binary()}},
                                       filepath :: file:filename_all() | undefined,
                                       module :: atom() | undefined,
                                       erlang_module :: atom() | undefined,
                                       tag :: integer() | undefined},
                     Vars :: list() | map(),
                     Context :: z:context(),
                     Context1 :: z:context().

overlay_close(Context)

-spec overlay_close(z:context()) -> z:context().

quote_css_selector(S)

Quote a css selector (assume no escaping needed...)

render(Mixed, Context)

-spec render(term(), z:context()) -> z:context().

Render adds output to the render-state of the context. Makes sure that the added output is an iolist The stored render state is later used in output/2

render_actions(TriggerId, TargetId, T, Context)

-spec render_actions(html_element_id(), html_element_id(), list(), z:context()) ->
                        {iolist(), z:context()}.

render_css_selector(Selector)

Render a css selector, allow direct expressions like

render_html(Render, Context)

render_to_iolist(MixedHtml, Context)

-spec render_to_iolist(MixedHtml :: term(), z:context()) -> {iolist(), z:context()}.

Render adds output to the render field of the context state. Do update the context for possible changes in scripts etc.

render_to_iolist(Template, Vars, Context)

-spec render_to_iolist(Template :: term(), list(), z:context()) -> {iolist(), z:context()}.

render_validator(TriggerId, TargetId, Args, Context)

-spec render_validator(undefined | binary(), undefined | binary(), list(), z:context()) -> iolist().

Render a validator to the correct javascript. Args are all arguments of the validator scomp. This renders an allocation of the initial validator and then appends all validations. 'type' holds multiple validations. Validations are of the form: {validator, [Args]}

replace(TargetId, Html, Context)

Replace an element to the the html fragment

replace_selector(CssSelector, Html, Context)

replace_selector_js(CssSelector, Html)

set_value(TargetId, Value, Context)

Set the value of an input element.

set_value_selector(CssSelector, Value, Context)

update(TargetId, Html, Context)

-spec update(string() | binary(),
             #render{template :: template_compiler:template(),
                     is_all :: boolean(),
                     vars :: proplists:proplist()} |
             iodata(),
             z:context()) ->
                z:context().

Set the contents of an element to the the html fragment

update_iframe(IFrameId, Html, Context)

Set the contents of an iframe to the generated html.

update_selector(CssSelector, Html, Context)

Set the contents of all elements matching the css selector to the the html fragment

update_selector_js(CssSelector, Html)

Set the contents of all elements matching the css selector to the the html fragment

validator(TriggerId, TargetId, Validator, Context)

-spec validator(string(), string(), term(), term()) -> term().

Add an input validator to the list of known validators, used when rendering custom validators

wire(Actions, Context)

-spec wire(action() | [action()], z:context()) -> z:context().

wire(TriggerId, Actions, Context)

wire(TriggerId, TargetId, Actions, Context)