drab v0.10.5 Drab.Live.EExEngine View Source
This is an implementation of EEx.Engine that injects Drab.Live
behaviour.
It parses the template during compile-time and inject Drab markers into it. Because of this, template must be a proper HTML. Also, there are some rules to obey, see limitations below.
Limitations
Avalibility of Assigns
To make the assign avaliable within Drab, it must show up in the template with “@assign
” format.
Passing it to render
in the controller is not enough.
Also, the living assign must be inside the <%= %>
mark. If it lives in <% %>
, it will not be
updated by Drab.Live.poke/2
. This means that in the following template:
<% local = @assign %>
<%= local %>
poking @assign
will not update anything or, if @assign
was not declared somewhere else,
it will raise the assign not found exception*.
Properties
Property must be defined inside the tag, using strict @property.path.from.node=<%= expression %>
syntax. One property may be bound only to the one expression, no apostrophe or double quote
allowed.
<button @hidden=<%= @hidden %> ...>
<button @style.backgroundColor=<%= my_color_function(@button1) %> ...>
Please notice that the full path to the property is allowed here, in this case the function
is bound to node.style.backgroundColor
.
Attributes
The attribute must be well defined, and you can’t use the expression as an attribute name.
The following is valid:
<button class="btn <%= @button_class %>">
<a href="<%= build_href(@site) %>">
But following constructs are prohibited:
<tag <%="attr='" <> @value <> "'"%>>
<tag <%=build_attr(@name, @value)%>>
The above will compile (with warnings), but it will not be correctly updated with
Drab.Live.poke
.
The tag name can not be build with the expression.
<<%= @tag_name %> attr=value ...>
Nested expressions are not valid in the attribute pattern. The following is not allowed:
<tag attribute="<%= if clause do %><%= expression %><% end %>">
Do a flat expression instead:
<tag attribute="<%= if clause, do: expression %>">
Scripts
Tag name must be defined in the template as <script>
, and can’t be defined with the expression.
Nested expressions are not valid in the script pattern. The following is not allowed:
<script>
<%= if clause do %>
<%= expression %>
<% end %>>
</script>
Do a flat expression instead:
<script>
<%= if clause, do: expression %>
</script>