ERb is the standard markup language in the world of Ruby. This is html with inserts on ruby. In the world of Elixir, EEx performs the same role. The same syntax, but instead of Ruby, is Elixir. Here's what it looks like:
<!DOCTYPE html> <html> <head> <title></title> <meta name="keywords" content="template <%= language_name %>"> <meta name="author" content="<%= user_name %>"> </head> <body> <h1 class="page-header"><%= page_header %></h1> <div id="content"> <p><%= page_content %></p> . </div> </body> </html>
The same can be written 1.5 times shorter without losing readability.
Meet: Slim markup language and its Elixir-analogue Slime:
I apologize for the picture instead of the text, Habr incorrectly highlights Slim.
div
substituted;Attributes can optionally be framed or not framed with brackets:
meta name="author" meta[name="author"] meta(name="author") meta{name="author"}
There is an online converter ; suitable if not a lot of templates. There is a html2slim gem that will convert all project templates:
$ gem install html2slim $ erb2slim app/views
There are fewer programmers on Elixir than rubists (by the way, how to call them, “elixirists”?). Slime is used less often. In general, when I spat an hour on EEx, went to look for the implementation of Slim, I found the Slime ecosystem in an immature state. Those. The language itself worked, with the phoenix it was perfectly integrated, but the overall impression was like a keyboard with a falling key.
Well, it opensource. Rolling up my sleeves, I added Slime support to Sublime Text, improved the official language site ( slime-lang.com ) and made the eex2slime utility for converting. I tested it on the open source hex.pm and changelog.com sources: because of the small restrictions on Slime, the source templates had to be prepared a bit, but on the whole the conversion is successful. This utility is an adaptation of the html2slim heme, so Ruby is needed to work> = 1.9.3. Using:
$ gem install eex2slime $ eex2slime lib/web/templates/
I also made an online converter . So far, it only works in slime-> eex mode. Useful for checking exactly how a particular Slime template will work.
Writing and editing code on Slim is faster than on Erb. Of the minuses: not everyone knows him; someone syntax seems poorly readable. However, it is easy to learn it, and syntax highlighting eliminates possible problems with readability.
If the team of your project is small and colleagues do not mind - try Slim / Slime worth it.
PS If it’s inconvenient to write mountains of tags, and Slim doesn't like the syntax, you can try Emmet .
Source: https://habr.com/ru/post/324332/
All Articles