Welcome, my fellow alchemists! A couple of news from the Drabās world.
The next future version, v0.6.0, is focused on Drab.Live
(living assigns). Because of some bugs and limits, I decided to completely refactor it and for now, it looks really promiscuous (for now ;)).
First at all, Drab will not sourround <span>
over expressions anymore, as it caused troubles in, for example, tables. Instead of this, it searches for the parent tag, injects some unique ID there and saves the innerHTML
of this tag, in the cache, as a pattern.
Thus, if you have a template
<p>My name is Bond, <%= @first_name%>, Bond</p>
During the compile time, Drabās engine injects some ID to <p>
<p drab-ampere=ovishfvoaidhfv>My name is Bond, <%= @first_name%>, Bond</p>
and saves the pattern to the internal DETS cache (it is a kind of the shadow html of the partial)
{"ovishfvoaidhfv", "My name is Bond, {{{{@drab-expr:fivdosifvoidfj}}}}, Bond"}
Thanks to this, when updating the assign @first_name
, Drab re-renders the innerHTML
of that <p>
tag, injecting the new value of rendered expression to the pattern.
Second at all, Drab is going to be smarter while updating assigns. Consider the following:
<%= function(@assign1) do %>
Some text, and other assign: <%= assign2 %>
<% end %>
In 0.5, updating @assign2
re-renders the whole expression. This is because @assign2
is one of the arguments of function/1, which is called as function(@assign, do: {:safe, ...@assign2...})
.
That issue was found when having the living assign inside the form_for
function. Updating the assign inside the form caused of re-render the whole stuff, including userās input.
Third at all, the new code is smaller and faster (more floki, less regexp!). Iāve learned a lot while doing this.
API change proposal: HTML safe updates
Now all the updates in drab are raw
. Doing
poke socket, text: "<b>bolded</b>"
or
insert_html(socket, "div", :beforebegin, "<b>bolded</b>")
updates the DOM without escaping the html. Of course there is an easy way to avoid this:
import Phoenix.HTML
insert_html(socket, "div", :beforebegin, ~E/"<b>MORE</b>"/)
but in my opinion it is not consistent with Phoenix, which uses safe htmls by default, enforcing developer to mark them as raw
in case.
Shall I change Drab to render SAFE by default?
This must be changed in all innerHTTML
updating functions. This will require to update all the existing applications.
But since Drab is the only beta 0.5 version, such change could be done without a big pain (sorry!).
Drabās philosophy is to be as much compatible with Phoenix as it is possible. This is why I am quite convinced to make an effort to do it.
Please comment it out.