Qqwy

Qqwy

TypeCheck Core Team

Indentation-based HTML templating language compiling to HEEx/LEEx/EEx?

Hi there! The recent developments w.r.t. Surface and HEEx are very cool!

One thing that would be the cherry on top, would be an indentation-based templating language that compiles down to one of these. If you no longer need to write closing tags, HTML (and any similar XML-like languages) can be expressed much more concisely (without any loss of expressivity).

As an example, you might look at Haml which is a Ruby-based variant (emitting ERb – Embedded Ruby files) of such a language. In Elixir there does exist Calliope which is an Haml parser. Unfortunately, Calliope has been abandoned since 2015.


I would love to write or collaborate on a templating engine like this.
However, where to start? What would be the most appropriate way to create a templating engine that builds on top of HEEx/LEEx/EEx(/Surface)?

I guess the question can be split up as:

  • How to create a templating engine which can be recognized both from a sigil and from a new file extension?
  • How to wrap (H/L)EEx inside another templating engine?

Marked As Solved

joaoevangelista

joaoevangelista

You might want to check out Slime, also with support for phoenix e and liveview, they have pretty advanced in terms of support, maybe is a good go to for contributions or inspiration

Also Liked

jamieorc

jamieorc

Got this solved. Long story short, it was a combination of configuration and file ending.

config :phoenix, :template_engines,
  slim: PhoenixSlime.Engine,
  slime: PhoenixSlime.Engine,
  sheex: PhoenixSlime.LiveView.HTMLEngine
  # slimleex: PhoenixSlime.LiveViewEngine # If you want to use LiveView

I didn’t have sheex originally, as slimleex had been generated. Populimited’s code had sheex in config with PhoenixSlime.LiveView.HTMLEngine as the value. Once I added that and changed the file ending from slim to sheex, my components worked as expected.

For example in my index.html.sheex file:

:link href=~p"/memories/new" class="text-sky-500 hover:underline"
  'new memory

Now works. It is rendered in the brower as

<!-- <Phoenix.Component.link> lib/phoenix_component.ex:2670 -->
<a href="/memories/new" class="text-sky-500 hover:underline">new memory </a>
<!-- </Phoenix.Component.link> -->`
silverdr

silverdr

I was also happy to find it some time ago and also opted for using it (it’s really hard PITA to get back once you got used to haml/slime) in a non-trivial project. Alas, it seems to become abandonware just like all other (?) After kludging around for last two versions of Phoenix, I feel like the need to waste time again and again is no longer worth it. Unless somebody knows a current, maintained fork or another maintained option I’ll end up rewriting lots of slime templates back into [h]eex :frowning:

Any other suggestions?

UPDATE: found a fork working with phx 1.7

https://github.com/populimited/phoenix_slime

jamieorc

jamieorc

Here’s a more complicated example using the table component.

HEEX version:

<.table id="memories" rows={@memories}>
  <:col :let={memory} label="Title"><%= memory.title %></:col>
  <:col :let={memory} label="Added"><%= memory.inserted_at %></:col>
  <:action :let={memory}>
    <.link href={~p"/memories/#{memory}"} class="text-sky-500 hover:underline">View</.link>
    ·
    <.link href={~p"/memories/#{memory}/edit"} class="text-sky-500 hover:underline">Edit</.link>
    ·
    <.link href={~p"/memories/#{memory}"} method="delete" class="text-sky-500 hover:underline">Delete</.link>
  </:action>

Equivalent SHEEX version:

:table id="memories" rows=@memories
  ::col :let=memory label="Title" = memory.title
  ::col :let=memory label="Added" = memory.inserted_at
  ::action :let=memory
    :link href=~p"/memories/#{memory}" class="text-sky-500 hover:underline" View
    |&nbsp; · &nbsp;
    :link href=~p"/memories/#{memory}/edit" class="text-sky-500 hover:underline" Edit
    |&nbsp; · &nbsp;
    :link href=~p"/memories/#{memory}" method="delete" class="text-sky-500 hover:underline" Delete

And the SHEEX (Slim) result.

Good news for all you who still want to use Slim(e) in your Phoenix 1.7.x apps.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New

Other popular topics Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31265 143
New
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43487 311
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41989 114
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement