liquor, liquid и другие безопасные языки разметки в ror
TRANSCRIPT
![Page 1: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/1.jpg)
Liquor, Liquidи другие безопасные языки разметки в
RoR
Тимофей Цветков, EvilMartians
![Page 2: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/2.jpg)
Safe templates
То, что не страшно разрешить
редактировать пользователю
![Page 3: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/3.jpg)
Safe Templates?
Shopify
![Page 4: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/4.jpg)
Safe Templates?
multi site app with custom user design
email templates
![Page 5: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/5.jpg)
Solutions•Radius http://radius.rubyforge.org
•Ruty http://ruty.rubyforge.org
•Laminate http://github.com/scottpersinger/laminate
•cs/Template http://cstemplate.rubyforge.org
![Page 6: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/6.jpg)
Radius
context = Radius::Context.new do |c| c.define_tag 'repeat' do |tag| number = (tag.attr['times'] || '1').to_i result = '' number.times { result << tag.expand } result end end
![Page 7: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/7.jpg)
Ruty
Похож на Liquid
![Page 8: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/8.jpg)
Rutyclass YourClass def foo 42 end def bar 23 end def delete # delete object here, not possible to do from the # template because not safe end def ruty_safe? name return [:foo, :bar].include?(name) endend
![Page 9: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/9.jpg)
Laminate
‘Laminate is a system for executing user-written
templates built using the Lua language’
![Page 10: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/10.jpg)
cs/Template
‘cs/Template is a fast, generic template engine
for Ruby, written in C’
![Page 11: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/11.jpg)
Liquid
Shopify, Mephisto and many others
![Page 12: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/12.jpg)
Liquid<ul id="products"> {% for product in products %} <li> <h2>{{product.title}}</h2> Only {{product.price | format_as_money }} <p>{{product.description | prettyprint | truncate: 200 }}</p> </li> {% endfor %} </ul>
![Page 13: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/13.jpg)
Liquid::Dropclass Post < ActiveRecord::Base
liquid_methods :title, :body end
class Post < ActiveRecord::Basedef to_liquid
PostDrop.new selfend
end
![Page 14: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/14.jpg)
Liquid::Dropclass Liquid::Drop
alias :[], :invoke_dropdef invoke_drop
methods = self.class.public_instance_methods.map{ |m| m.to_s }
if methods.include? method.to_ssend(method.to_sym)
elsebefore_method(method)
endend
def before_method(method)nil
endend
![Page 15: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/15.jpg)
Liquid suxx
Drops suxx
methods? named_scopes? associations?
![Page 16: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/16.jpg)
![Page 17: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/17.jpg)
Liquor
http://github.com/evilmartians/liquor
![Page 18: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/18.jpg)
Liquor
class PostDrop < Liquor::Dropliquor_attributes << :title << :bodyliquor_names_scopes << :recent << :for_tag
belongs_to :bloghas_many :commentshas_one :author
end
![Page 19: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/19.jpg)
Liquor
Filters, content_for and yield tags
![Page 20: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/20.jpg)
Liquor. Expressions
{% assign playlists = site.playlists|by_name:artist.name %}
{% for artist in site.artists.active|scoped_to:genre %}
![Page 21: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/21.jpg)
Liquorclass ActiveRecord::NamedScope
def to_liquorself
endend
But only array and .paginate methods are allowed
![Page 22: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/22.jpg)
Liquor
We use it in production:kasta.rurespectproduction.com (comming soon)
![Page 23: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/23.jpg)
Красный быстрый
96 капель.Горящий куантро и еще кое-что...
Да, мы будем компилировать
![Page 24: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/24.jpg)
ror2ru
Накуси выкуси
![Page 25: Liquor, Liquid и другие безопасные языки разметки в RoR](https://reader036.vdocuments.mx/reader036/viewer/2022062412/58780e051a28ab971e8b6651/html5/thumbnails/25.jpg)
Троллинг