Slide 1

Slide 1 text

Dynamiczne szablony - Liquid Markup Krzysztof Wawer! ! github.com/wafcio [email protected]

Slide 2

Slide 2 text

Co to jest Liquid? github.com/Shopify/liquid

Slide 3

Slide 3 text

Renderowanie szablonu Liquid::Template.parse('Hello {{who}}'). render({ 'who' => 'world' }) => "Hello world"

Slide 4

Slide 4 text

Zmienne i tagi "{{title}}" "{% post %}" - atrybut, zmienna - tag

Slide 5

Slide 5 text

Filtry w Liquid "Hello {{ 'tobi' | capitalize}}" "Today is {{ 'now' | date: "%Y %h"}}"

Slide 6

Slide 6 text

Własne filtry module TextFilter def textilize(input) RedCloth.new(input).to_html end end ! Liquid::Template.register_filter(TextFilter) ! Liquid::Template.parse(" {{ '*hi*' | textilize }} "). render({}, filters: [TextFilter]) # => "hi"

Slide 7

Slide 7 text

Liquid Tag class ExampleTag < Liquid::Tag def initialize(name, markup, token) ! end ! def render(context) end end ! Liquid::Template.register_tag('example_menu', ExampleTag) ! Liquid::Template.parse("{% example_tag key1=value1%}").render

Slide 8

Slide 8 text

Liquid Drop class PostDrop < Liquid::Drop def initialize(post) @post = post end ! def title @post.title end end Liquid::Template.parse(„{{post.title}}, {{post.content}}”). render({ 'post' => PostDrop.new(Post.find(id)) }) => "Post title, "