際際滷

際際滷Share a Scribd company logo
ERb alternatyvos
RubyConfLT 2010
Vidmantas Kabo邸is
vidmantas.kabosis.lt
Kas yra kas (intro)
   ablono variklis == template engine
   Greitis
   Saugumas
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
eruby
   C




                4
erubis
   Ruby
   Greitesnis u転 ERB, eruby
   Keiiamas 眺terpimo 邸ablonas
   Automatinis eskeipinimas
   Ke邸avimas (preprocessing)
          [%= link_to 'Create', :action=>'create'%]
   Priima vykdymo nurodymus (processing
     instructions) 邸ablonuose
   Rails 3
                                                       5
erubis




 http://www.kuwata-lab.com/erubis/




                                     6
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
rbTenjin (1/3)
   Lengvas, greitas (greiiausias?)
   Saugus ,,pagal nutyljim
   Layouts, partials
   Konvertuoto kodo ke邸avimas
   
   Savybmis labai pana邸us 眺 erubis




                                       8
rbTenjin (2/3)




      http://www.kuwata-lab.com/tenjin/
                                          9
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
Kitas po転i笛ris
   TAL
   Smarty-like (Liquid)
   Ruby DSL
   wiki-style
   Kiti :-)




                                  11
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
TAL: Amrita (1/3)




        http://amrita.sourceforge.jp/



                                        13
TAL: Amrita (2/3)
   ,,Pure XML/HTML document
          <?  ?>, <%=  %>
   I邸vest眺 kontroliuoja duomenys
   Gali b笛ti sukompiliuotas 眺 ruby
   Amrita 2




                                      14
TAL: Amrita (3/3)
<table border="1">
  <tr>
    <th>name</th><th>author</th>
  </tr>
  <tr id="table1">
    <td id="name">
    <td id="author">
  </tr>
</table>

# data
data = {
  :table1=>[
    { :name=>"Ruby", :author=>"matz" },
    { :name=>"perl", :author=>"Larry Wall" },
    { :name=>"python", :author=>"Guido van Rossum" },
  ]
}


                                                        15
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
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
Smarty-like (Liquid)
   Atskira ,,kalba 邸ablonuose
   Ruby realizacijos:
          Liquid
          Ruty




                                     18
Liquid (1/2)
   I邸 ,,Shopify, naudojamas production'e
   Ruby on Rails
   Saugus
   Sintaks pana邸i 眺 Ruby
   Pleiama (tagai, filtrai, blokai)




                                             19
Liquid (2/2)
Hello {{ '*rubyconf*' | textilize | upcase }}


{% if user.name == 'bob' and user.age > 45 %}
  Hello old bob
{% endif %}


# array = [1,2,3,4,5,6]
{% for item in array limit:2 offset:2 %}
  {{ item }}
{% endfor %}
# results in 3,4
                                                20
Ruty
   I邸takos: Django / Jinja Template Engine
   ablon迭 paveldjimas
   Sintaks visi邸kai analogi邸ka Liquid (?)
   Papildomos saugumo priemons
   Ltesnis u転 ERB, bet greitesnis u転 Liquid




                                                21
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
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
wiki-style
   Nra tikrosios ,,邸ablon迭 kalbos
   Skirtos vartotoj迭 眺vesiai apdoroti
   Markdown:
          BlueCloth, Maruku, Kramdown, RDiscount
   Textile:
          RedCloth, ?




                                                    24
Kiti
   HAML
   Radius




                    25
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
Kiti: HAML (2/2)
   Klas 転ymima ., id - #, atributai - (), tag'as - %
    #content
     .left.column
        %h2 Welcome to rubyconf!
        %p= print_information
      .right.column
        = render :partial => "sidebar"


                                                         27
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
Pabaigai
   Svarbiausia  produktyvumas
   Naudojami:
          ERB plaija prasme
          HAML
          Liquid




                                  29
end

?




      30

More Related Content

ERb alternatyvos

  • 1. ERb alternatyvos RubyConfLT 2010 Vidmantas Kabo邸is vidmantas.kabosis.lt
  • 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
  • 4. eruby C 4
  • 5. erubis Ruby Greitesnis u転 ERB, eruby Keiiamas 眺terpimo 邸ablonas Automatinis eskeipinimas Ke邸avimas (preprocessing) [%= link_to 'Create', :action=>'create'%] Priima vykdymo nurodymus (processing instructions) 邸ablonuose Rails 3 5
  • 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
  • 9. rbTenjin (2/3) http://www.kuwata-lab.com/tenjin/ 9
  • 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
  • 13. TAL: Amrita (1/3) http://amrita.sourceforge.jp/ 13
  • 14. TAL: Amrita (2/3) ,,Pure XML/HTML document <? ?>, <%= %> I邸vest眺 kontroliuoja duomenys Gali b笛ti sukompiliuotas 眺 ruby Amrita 2 14
  • 15. TAL: Amrita (3/3) <table border="1"> <tr> <th>name</th><th>author</th> </tr> <tr id="table1"> <td id="name"> <td id="author"> </tr> </table> # data data = { :table1=>[ { :name=>"Ruby", :author=>"matz" }, { :name=>"perl", :author=>"Larry Wall" }, { :name=>"python", :author=>"Guido van Rossum" }, ] } 15
  • 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
  • 18. Smarty-like (Liquid) Atskira ,,kalba 邸ablonuose Ruby realizacijos: Liquid Ruty 18
  • 19. Liquid (1/2) I邸 ,,Shopify, naudojamas production'e Ruby on Rails Saugus Sintaks pana邸i 眺 Ruby Pleiama (tagai, filtrai, blokai) 19
  • 20. Liquid (2/2) Hello {{ '*rubyconf*' | textilize | upcase }} {% if user.name == 'bob' and user.age > 45 %} Hello old bob {% endif %} # array = [1,2,3,4,5,6] {% for item in array limit:2 offset:2 %} {{ item }} {% endfor %} # results in 3,4 20
  • 21. Ruty I邸takos: Django / Jinja Template Engine ablon迭 paveldjimas Sintaks visi邸kai analogi邸ka Liquid (?) Papildomos saugumo priemons Ltesnis u転 ERB, bet greitesnis u転 Liquid 21
  • 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
  • 25. Kiti HAML Radius 25
  • 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
  • 27. Kiti: HAML (2/2) Klas 転ymima ., id - #, atributai - (), tag'as - % #content .left.column %h2 Welcome to rubyconf! %p= print_information .right.column = render :partial => "sidebar" 27
  • 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
  • 30. end ? 30