-
Notifications
You must be signed in to change notification settings - Fork 0
/
ERB2slim.slim
102 lines (86 loc) · 1.92 KB
/
ERB2slim.slim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// /* ------------------------------------------ *\
// if...else
// \* ------------------------------------------ */
:::ERB
<% if 某條件 %>
當條件成立時執行的部份
<% else %>
當條件不成立時執行的部份
<% end %>
:::slim
- if (1+1==2)
會顯示這一行
- else
永遠不會顯示
// /* ------------------------------------------ *\
// 做某件事情 n 次
// \* ------------------------------------------ */
:::ERB
<% n.times do %>
做某件事
<% end %>
:::slim
- 3.times do
早安您好
// /* ------------------------------------------ *\
// 隨機挑一個 0 到 n-1 之間的數字
// \* ------------------------------------------ */
:::ERB
<%= rand(n) %>
:::slim
= rand(3)
// /* ------------------------------------------ *\
// Templates
// \* ------------------------------------------ */
:::html
<h1>sample list</h1>
<ul>
<li>list 1</li>
<li>list 2</li>
<li>list 3</li>
<li>list 4</li>
<li>list 5</li>
</ul>
:::ERB
<h1>sample list</h1>
<ul>
<% (1..5).each do |n| %>
<li>list <%= n %></li>
<% end %>
</ul>
:::slim
h1 sample list
ul
- (1..5).each do |n|
li
| list
= n
or
h1 sample list
ul
- (1..5).each do |n|
li list #{n}
// /* ------------------------------------------ *\
// Layouts
// \* ------------------------------------------ */
:::ERB
<%= yield %>
:::slim
= yield
// /* ------------------------------------------ *\
// 中文假資料helpr
// \* ------------------------------------------ */
= zh_lorem_word, = zh_lorem_words
= zh_lorem_sentence, = zh_lorem_sentences
= zh_lorem_paragraph, = zh_lorem_paragraphs
= zh_lorem_name
= zh_lorem_name_pinyin
= zh_lorem_first_name
= zh_lorem_first_name_pinyin
= zh_lorem_last_name
= zh_lorem_last_name_pinyin
= zh_lorem_email
// /* ------------------------------------------ *\
// 假資料helpr
// \* ------------------------------------------ */
= lorem_date.to_date