Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Liquid Markup

Jon Daniel
October 04, 2012

Liquid Markup

Talk I gave October 4, 2012 at Pittsburgh Ruby Brigade.

Jon Daniel

October 04, 2012
Tweet

More Decks by Jon Daniel

Other Decks in Programming

Transcript

  1. markup = "Welcome, {{ user.name }}" user = User.find(1337) t

    = Liquid::Template.parse(markup) t.render('user' => user)
  2. class Person < ActiveRecord::Base end # denied! "{{ person.name }}"

    => "" class Person < ActiveRecord::Base liquid_methods :name end # okay! "{{ person.name }}" => "Cmdr Shepard"
  3. markup = "Welcome, {{ user.name }}" user = User.find(1337) t

    = Liquid::Template.parse(markup) t.render('user' => user)
  4. registers[:domain] = domain registers[:whatever] = whatever registers[:your] = your registers[:app]

    = app registers[:needs] = needs registers[:file_system] = FileSystem.new
  5. registers[:domain] = domain registers[:whatever] = whatever registers[:your] = your registers[:app]

    = app registers[:needs] = needs registers[:file_system] = FileSystem.new
  6. class FileSystem def initialize(*args) # whatever end def read_template_file(name, context)

    # fetches partials from wherever end end {% include 'some-partial' %}
  7. # a block {% if liquid == 'awesome' %} You

    should try Liquid! {% endif %} # a tag {% assign liquid = 'awesome' %}
  8. class ExampleTag < Liquid::Tag def initialize(name, markup, tokens) # setup

    the tag, parse stuff, ya know... # expensive stuff. end def render(context) # drop in the assigns and go! # should be cheap. end end
  9. class ExampleTag < Liquid::Tag def initialize(name, markup, tokens) # setup

    the tag, parse stuff, ya know... # expensive stuff. end def render(context) # drop in the assigns and go! # should be cheap. end end
  10. class PersonDrop < Liquid::Drop def addresses # stupid slow operation

    Address::find_by_person(@person) end end {{ user.addresses }}
  11. {{ “hello world” | capitalize }} # shamelessly stolen from

    # liquid's source. use your # imagination people! def capitalize(input) input.to_s.capitalize end