Drab Versions Save

Remote controlled frontend framework for Phoenix.

v0.6.1

6 years ago

This release fixes new, better bugs introduced in v0.6.0:

  • "atom :save_assigns not found" error
  • @conn case (it was not removing @conn from the initial JS)
  • cache file deleted after mix phx.digest, moved the file to the Drab's priv directory

Please read documentation for Drab.Browser, the API has changed

  • cleaned up the mess with API in Drab.Browser

v0.6.0

6 years ago

This is a major release. The biggest change is completely redesigned engine for Drab.Live with nodrab option. Also introducting shared commanders, updates in Drab.Browser, performance and bug fixes.

Migration from 0.5

After installation, please remove all remaining priv/hashes_expressions.drab.cache.* files (they were renamed to drab.live.cache) and do a mix clean to recompile templates:

mix clean

Changes

Drab.Live

The main change in the new template engine is that now it is not injecting <span> everywhere. Now, it parses the html and tries to find the sourrounding tag and mark it with the attribute called drab-ampere. The attribute value is a hash of the previous buffer and the expression, so it is considered unique.

Consider the template, with initial value of 1 (given in render function in the Controller, as usual):

<p>Chapter <%= @chapter_no %>.</p>

which renders to:

<p drab-ampere="someid">Chapter 1.</p>

This drab-ampere attribute is injected automatically by Drab.Live.EExEngine. Updating the @chapter_no assign in the Drab Commander, by using poke/2:

chapter = peek(socket, :chapter_no)     # get the current value of `@chapter_no`
poke(socket, chapter_no: chapter + 1)   # push the new value to the browser

will change the innerHTML of the <p drab-ampere="someid"> to "Chapter 2." by executing the following JS on the browser:

document.querySelector('[drab-ampere=someid]').innerHTML = "Chapter 2."

This is possible because during the compile phase, Drab stores the drab-ampere and the corresponding pattern in the cache DETS file (located in priv/drab.live.cache).

Sometimes it must add a <span>

In case, when Drab can't find the parent tag, it injects <span> in the generated html. For example, template like:

Chapter <%= @chapter_no %>.

renders to:

Chapter <span drab-ampere="someid">1</span>.

Avoiding using Drab (nodrab option)

If there is no need to use Drab with some expression, you may mark it with nodrab/1 function. Such expressions will be treated as a "normal" Phoenix expressions and will not be updatable by poke/2.

<p>Chapter <%= nodrab(@chapter_no) %>.</p>

In the future (Elixir 1.6 I suppose), the nodrab keyword will be replaced by a special EEx mark / (expression will look like <%/ @chapter_no %>).

The @conn case

The @conn assign is often used in Phoenix templates. Drab considers it read-only, you can not update it with poke/2. And, because it is often quite hudge, may significantly increase the number of data sent to the browser. This is why Drab treats all expressions with only one assign, which happen to be @conn, as a nodrab assign.

Shared Commanders

By default Drab runs the event handler in the commander module corresponding to the controller, which rendered the current page. Now it is possible to choose the module by simply provide the full path to the commander:

<button drab-click='MyAppWeb.MyCommander.button_clicked'>clickme</button>

Notice that the module must be a commander module, ie. it must be marked with use Drab.Commander, and the function must be whitelisted with Drab.Commander.public/1 macro.

Changes in Drab.Browser

All function in Drab.Browser were renamed to their bang version. This is because in the future release functions with and without bang will be more consist with Elixir standards - nobang function will return tuples, bangs will raise on error.

Warning: functions redirect_to!/2 and console!/2 are changed

In preparation to change all the functions in the module, this functions behavior have changed. Now, they are just bang version of the "normal" function, and they are not broadcasting anymore.

You should use broadcast_redirect_to!/2 and broadcast_console!/2 instead.

v0.6.0-pre.1

6 years ago

This pre-release is to check and test the brand new EEx engine of Drab.Live.

Migration from 0.5

After installation, please remove all remaining priv/hashes_expressions.drab.cache.* files (they were renamed to drab.live.cache) and do a mix clean to recompile templates:

mix clean

Changes

The main change in the new template engine is that now it is not injecting <span> everywhere. Now, it parses the html and tries to find the sourrounding tag and mark it with the attribute called drab-ampere. The attribute value is a hash of the previous buffer and the expression, so it is considered unique.

Consider the template, with initial value of 1 (given in render function in the Controller, as usual):

<p>Chapter <%= @chapter_no %>.</p>

which renders to:

<p drab-ampere="someid">Chapter 1.</p>

This drab-ampere attribute is injected automatically by Drab.Live.EExEngine. Updating the @chapter_no assign in the Drab Commander, by using poke/2:

chapter = peek(socket, :chapter_no)     # get the current value of `@chapter_no`
poke(socket, chapter_no: chapter + 1)   # push the new value to the browser

will change the innerHTML of the <p drab-ampere="someid"> to "Chapter 2." by executing the following JS on the browser:

document.querySelector('[drab-ampere=someid]').innerHTML = "Chapter 2."

This is possible because during the compile phase, Drab stores the drab-ampere and the corresponding pattern in the cache DETS file (located in priv/drab.live.cache).

Sometimes it must add a <span>

In case, when Drab can't find the parent tag, it injects <span> in the generated html. For example, template like:

Chapter <%= @chapter_no %>.

renders to:

Chapter <span drab-ampere="someid">1</span>.

Avoiding using Drab (nodrab option)

If there is no need to use Drab with some expression, you may mark it with nodrab/1 function. Such expressions will be treated as a "normal" Phoenix expressions and will not be updatable by poke/2.

<p>Chapter <%= nodrab(@chapter_no) %>.</p>

In the future (Elixir 1.6 I suppose), the nodrab keyword will be replaced by a special EEx mark / (expression will look like <%/ @chapter_no %>).

The @conn case

The @conn assign is often used in Phoenix templates. Drab considers it read-only, you can not update it with poke/2. And, because it is often quite hudge, may significantly increase the number of data sent to the browser. This is why Drab treats all expressions with only one assign, which happen to be @conn, as a nodrab assign.

v0.5.6

6 years ago

Removing @conn (#51) broke templates, rendered in a runtime.

v0.5.5

6 years ago
  • #20 (broadcasting in Phx 1.3)
  • #44 (docs for broadcasting)
  • #45 (button inside for submits in Firefox)
  • #47 (docs and error message updated)
  • #51 (removed @conn from living assigns, encrypts assigns)

v0.5.4

6 years ago

Fixes for adding templates in a runtime.

poke socket, live_partial1: render_to_string("partial1.html", color: "#aaaabb")
poke socket, "partial1.html", color: "red"

Fixes:

  • #37
  • #40 (updated documentation for Drab.Live.EExEngine)
  • #41
  • #34 and #38

v0.5.3

6 years ago

Please clean up the Drab before upgrading from 1.2 to 1.3:

mix deps.clean drab
  • bugfixes (#19, #36).
  • drab.gen.commander works both with Phoenix 1.2 and 1.3

v0.5.2

6 years ago

This is a small update to make Drab compatible with Elixir 1.5. Due to an issue with 1.5.0 (elixir-lang/elixir#6391) Elixir version is fixed on 1.4 or >= 1.5.1.

Fixes:

  • #26, #27, #30, #31, #33

v0.5.1

6 years ago

v0.5.1

Fixes:

  • Transpiled all JS templates, and removed all occurences of forEach (#22)
  • Radio buttons not reported correctly in sender["form"] (#23)
  • New :main_phoenix_app config item, in case the app name can't be read from mix.exs (#25)

Changes:

  • sender[:params] contains params normalized to controller type params (#24)

    %{"_csrf" =>
    "1234", "user[id]" => "42", "user[email]" => "[email protected]",
    "user[account][id]" => "99", "user[account][address][street]" =>
    "123 Any Street"}
    

    becomes:

    %{"_csrf" => "1234",
    "user" => %{"account" => %{"address" => %{"street" => "123 Any Street"},
    "id" => "99"}, "email" => "[email protected]", "id" => "42"}}
    

New features:

  • Core.Browser.set_url/2 to manipulate the browser's URL bar

v0.5.0

6 years ago

This version is a major update. The default module, Drab.Query has been replaced with Drab.Live and Drab.Element. Drab is not jQuery dependent by default anymore.

New modules

Drab.Live

Allows to remotely (from the server side) replace the value of the assign in the displayed paged, without re-rendering and reloading the page.

Such template:

<a href="https://<%= @url%>" @style.backgroundColor=<%= @color%>>
  <%= @url %>
</a>

can be updates live with poke/2:

poke socket, url: "tg.pl/drab", color: "red"

Drab.Element

Query and update displayed page from the server side.

set_prop socket, "p", style: %{"backgroundColor" => "red"} # awesome effect

Broadcasting

Broadcasting functions now get subject instead of socket. There is no need to have an active socket to broadcast anymore. Useful when broadcasting from background servers or ondisconnect callback.

Form parameters in sender

If the event launching element is inside a <FORM>, it gets a values of all input elements within that form. This is a map, where keys are the element's name or id.

Upgrading from 0.4

Add Drab.Query and Drab.Modal to your commanders:

use Drab.Commander, module: [Drab.Query, Drab.Modal]

Depreciations

All soft depreciations up to 0.4.1 became hard.