-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5a807c
commit 616d79a
Showing
6 changed files
with
82 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,40 @@ | ||
# Phlex vs Slim | ||
|
||
[Slim](https://slim-template.github.io)โs goal is reduce templating syntax to just the essential parts without becoming cryptic. | ||
|
||
We canโt really make a direct comparison between Phlex and Slim becuase Slim is not a component framework and Phlex is not a templating language. However, there are some similarities between the two that we can look at. We can also get into why Phlex is designed around this idea of a โcomponentโ. | ||
|
||
### Minimal templating syntax | ||
|
||
If youโre using Slim, thereโs a good chance you wanted something with a more minimal syntax than ERB, especially when it comes to switching between the HTML parts and the Ruby parts, such as an `if` conditional. | ||
|
||
Phlex too has a pretty minimal syntax, with one significant difference: the Phlex syntax is just Ruby. You donโt need to learn anything else, you already know it. Modules, classes, methods, arguments, blocks. Thatโs it. | ||
|
||
Because itโs just Ruby, the transition between the Ruby code and the template code is even more seamless. Thereโs no transition because itโs all Ruby. One factor to consider is Ruby doesnโt have significant whitespace. | ||
|
||
### Components and abstraction | ||
|
||
Phlex is designed around the idea of a โcomponentโ. A component is a Ruby class that represents a small part of the page. Extracting small components helps keep your user experience consistent and makes your code much easier to maintain in the long run. | ||
|
||
Additionally, because Phlex is just Ruby, you can start by extracting methods. | ||
|
||
```ruby | ||
def MyButton(...) | ||
button(class: "my button classes", ...) | ||
end | ||
``` | ||
|
||
When you realise you need more options, you can upgrade that to a class. | ||
|
||
```ruby | ||
class MyButton < ApplicationComponent | ||
def initialize(style:, color:) | ||
@style = style | ||
@color = color | ||
end | ||
|
||
def view_template(&) | ||
button(class: [@style, @color], &) | ||
end | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters