2. Kas yra kas (intro)
ablono variklis == template engine
Greitis
Saugumas
3. ERb
Embedded Ruby
<%= %>
ERB - kartu su standartiniu Ruby
Autsaideris greiio ir saugumo at転vilgiu
Turi realizacij迭, sprend転iani迭 jo problemas
eruby
erubis
Ember
rbTenjin
3
7. ember
Ruby
Gali automati邸kai papildyti tr笛kstamais
<% end %> pagal identacij
Klaid迭 prane邸imuose naudoja teisingus eilui迭
numerius
Papildomos instrukcijos
<%+ "doc/example.erb" %>
Ruby on Rails
7
8. rbTenjin (1/3)
Lengvas, greitas (greiiausias?)
Saugus ,,pagal nutyljim
Layouts, partials
Konvertuoto kodo ke邸avimas
Savybmis labai pana邸us 眺 erubis
8
10. rbTenjin (3/3)
###### layout
<html>
<body>
<h1>${@title}</h1>
<div class="main-content">
#{@_content}
</div>
...
###### template
<table>
<?rb i = 0 ?>
<?rb for item in @items ?>
<?rb i += 1 ?>
<?rb color = i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' ?>
<tr bgcolor="#{color}">
<td>#{i}</td>
<td>${item}</td>
</tr>
<?rb end ?>
</table>
10
11. Kitas po転i笛ris
TAL
Smarty-like (Liquid)
Ruby DSL
wiki-style
Kiti :-)
11
12. TAL
Template Attribute Language
Elementai 転ymimi TAL apra邸o atributais
Validus XML/HTML dokumentas
Para邸ytas ,,Zope
TALES, METAL
Ruby realizacijos:
Amrita/Amrita2
Kwartz
12
16. TAL: Kwartz
,,Independence of Presentation Logic
ablonas + 邸ablono logika (plogic)
#list1 {
logic: {
for member in @members
_stag # start tag
_cont # content
_etag # end tag
end
}
}
<tr id="list1">
<td id="mark:item1">foo</td>
</tr>
16
17. TAL
DHH:
The pursuit of "no code"-templates reminds
me of the search for the holy grail of the MDA
camp with "no code"-programs. It's mirage,
but its also a play on words of the "a rose by
any other name..." variety.
http://www.loudthinking.com/arc/000405.html
17
22. Ruby DSL
Prie邸ingai nei ERB/TAL/Liquid, apra邸o
邸ablonus su ,,pure Ruby
Pagrindinis 転aidjas - ,,Markaby
,,Maline - mirs
Builder::XmlMarkup tik XML dokumentams
22
23. Ruby DSL: Markaby
,,Markup as Ruby
Naudojamas ,,Camping microframework'e
Lengvai integruojamas 眺 Rails
Susid笛rusiems su DSL, lengvai perprantamas
html do
head do
title 'Products: ' + action_name
stylesheet_link_tag 'scaffold'
end
body do
p flash[:notice], :style => "color: green"
self << yield
end
end
23
24. wiki-style
Nra tikrosios ,,邸ablon迭 kalbos
Skirtos vartotoj迭 眺vesiai apdoroti
Markdown:
BlueCloth, Maruku, Kramdown, RDiscount
Textile:
RedCloth, ?
24
26. Kiti: HAML (1/2)
,,Markup haiku
Principai:
Markup should be DRY
Markup should be well-intended
HTML structure should be clear
Markup should be meaningful
HAML sesut CSS'ui: SASS
26
28. Kiti: Radius
ablon迭 k笛rimui
Leid転ia patogiai apibr転ti savo tag'us ir juos
parsinti
ablonas beveik XML (namespace)
context.define_tag "hello" do |tag|
"Hello #{tag.attr['name'] || 'World'}!"
end
parser = Radius::Parser.new(context)
parser.parse('<p><radius:hello name="RubyConf" /></p>')
28
29. Pabaigai
Svarbiausia produktyvumas
Naudojami:
ERB plaija prasme
HAML
Liquid
29