Sinatraã§ã対å¿ãã¦ãã軽éï¼ã·ã³ãã«ãªãã³ãã¬ã¼ãã¨ã³ã¸ã³'Haml'ã«ã¤ãã¦ããã¹ãã¡ã¢
Sinatraã§ã対å¿ãã¦ã軽éï¼ã·ã³ãã«ãªãã³ãã¬ã¼ãã¨ã³ã¸ã³Hamlã«ã¤ãã¦ããã¹ã¦ã¿ãã
ãã®ãã¥ã¼ããªã¢ã«ãåæã«è¦ç´ãã¦ã¿ã
ERBã¨æ¯è¼ãã¦ã¿ãã¨ãã®ã·ã³ãã«ãããããããã
ã¿ã°ã¨ãã®ã³ã³ãã³ã
ãã³ãã¬ã¼ãã¨ã³ã¸ã³ | è¨è¿° |
---|---|
ERB | <strong><%= item.title %></strong> |
Haml | %strong= item.title |
Hamlã§ã¯"%ã»ã"ã§ã¿ã°ã表ã
ã¿ã°ã«ã¤ã¥ã=ã®å
容ã¯Rubyã®æã¨ãã¦è©ä¾¡ããã¦ããã®çµæãã¿ã°ã®ã³ã³ãã³ãã«ãªãã
ã¿ã°ã®å±æ§
ãã³ãã¬ã¼ãã¨ã³ã¸ã³ | è¨è¿° |
---|---|
ERB | <strong class="code" id="message">Hello, World</strong> |
Haml | %strong.code#message Hello, World |
ã¿ã°ã®å±æ§ã¯ã¿ã°åã«ç¶ãã¦ããã·ã¥ãè¨è¿°ãããã¨ã§è¨å®ããã
ã¾ããä¸è¨ã®ããã«ã¿ã°ã®ã³ã³ãã³ããRubyã®ã³ã¼ããããªãå ´åã"="ã¯ãããªãã
ã¿ã°ã®å±æ§ï¼CSSã»ã¬ã¯ã¿ã£ã½ãæ¸ãæ¹ï¼
ãã³ãã¬ã¼ãã¨ã³ã¸ã³ | è¨è¿° |
---|---|
ERB | <strong class="code" id="message">Hello, World</strong> |
Haml | %strong.code#message Hello, World |
classãidãªã©ã®å±æ§ã¯CSSã»ã¬ã¯ã¿ã£ã½ãæ¸ãäºãã§ãã
ã¿ã°ã¯çç¥ããã¨divã¿ã°ã¨è¦ãªããã
ãã³ãã¬ã¼ãã¨ã³ã¸ã³ | è¨è¿° |
---|---|
ãªã(HTML) | <div clas='content'>Hello, world.</div> |
Haml | .content Hello, world |
ããã¡ãã£ã¨è¤éãªä¾
ãã®ï¼
ERB
<div class='item' id='item<%= item.id %>'> <%= item.body %> </div>
Haml
.item{:id => "item#{item.id}"}= item.body
å±æ§ã®ã¨ããã§ã¯æ®éã«#{}ã§ã®å¤æ°ã®å±éãã§ããã
ãã®ï¼
ERB
<div id='content'> <div class='left column"> <h1>Welcome to our site!</h2> <p><%= print_information %></p> </div> <div class="right column"> <%= render :partial => "sidebar" %> </div> </div>