LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When...

92
LIQUID MARKUP A story by Dane Harrigan Friday, March 11, 2011

Transcript of LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When...

Page 1: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

LIQUID MARKUPA story by Dane Harrigan

Friday, March 11, 2011

Page 2: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

I’m Dane Harrigan

Friday, March 11, 2011

Page 3: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

@daneharrigan

Friday, March 11, 2011

Page 4: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

Friday, March 11, 2011

Page 5: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

Friday, March 11, 2011

Page 6: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

When Should I use Liquid

Friday, March 11, 2011

Page 7: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

When Should I use Liquid

How do I use Liquid

Friday, March 11, 2011

Page 8: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

When Should I use Liquid

How do I use Liquid

Liquify: Liquid Simplified

Friday, March 11, 2011

Page 9: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

Friday, March 11, 2011

Page 10: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

•Template Language

Friday, March 11, 2011

Page 11: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

•Template Language

•Written in Ruby

Friday, March 11, 2011

Page 12: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

•Template Language

•Written in Ruby

•Similar to ERb

Friday, March 11, 2011

Page 13: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

<%= %>

ERb Liquid

{{ }}

Friday, March 11, 2011

Page 14: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

<%= %>

ERb Liquid

{{ }}

<% %> {% %}

Friday, March 11, 2011

Page 15: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

<%= %>

ERb Liquid

{{ }}

<% %> {% %}

<%= helper(val) %> {{ val | helper }}

Friday, March 11, 2011

Page 16: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

•Secure

Friday, March 11, 2011

Page 17: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

•Secure

•Does Not Evaluate Ruby

Friday, March 11, 2011

Page 18: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

What is Liquid

•Secure

•Does Not Evaluate Ruby

•Is a Pain in The Ass to Use

Friday, March 11, 2011

Page 19: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“Ok, so why would I use it?”

Friday, March 11, 2011

Page 20: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

When Should I use Liquid

When to use Liquid

When NOT to use Liquid

Friday, March 11, 2011

Page 21: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

1%99%

Friday, March 11, 2011

Page 22: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“1%? Now I’m interested!”

Friday, March 11, 2011

Page 23: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

When Should I use Liquid

Friday, March 11, 2011

Page 24: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

When Should I use Liquid

When you’re sharing your view code

Friday, March 11, 2011

Page 25: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

When Should I use Liquid

When you’re sharing your view code

•Shopping Carts (Shopify)

Friday, March 11, 2011

Page 26: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

When Should I use Liquid

When you’re sharing your view code

•Shopping Carts (Shopify)

•Newsletter Services (MailChimp)

Friday, March 11, 2011

Page 27: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

When Should I use Liquid

When you’re sharing your view code

•Shopping Carts (Shopify)

•Newsletter Services (MailChimp)

•CMS (Magnetism, Mephisto, Jekyll)

Friday, March 11, 2011

Page 28: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

When Should I use Liquid

Friday, March 11, 2011

Page 29: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

When Should I use Liquid

When you need a limited feature set

Friday, March 11, 2011

Page 30: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

When Should I use Liquid

When you need a limited feature set

•Only allow access to specific objects

Friday, March 11, 2011

Page 31: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

When Should I use Liquid

When you need a limited feature set

•Only allow access to specific objects

•Specify which methods of an object can be executed

Friday, March 11, 2011

Page 32: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

When Should I use Liquid

When you need a limited feature set

•Only allow access to specific objects

•Specify which methods of an object can be executed

•Allow usage of predefined helper methods

Friday, March 11, 2011

Page 33: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“Huh?”

Friday, March 11, 2011

Page 34: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

How do I use Liquid

Friday, March 11, 2011

Page 35: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

How do I use Liquid

•Drops (Classes, Models)

Friday, March 11, 2011

Page 36: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

How do I use Liquid

•Drops (Classes, Models)

•Filters (View Helpers)

Friday, March 11, 2011

Page 37: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

How do I use Liquid

•Drops (Classes, Models)

•Filters (View Helpers)

•Tags (Single Purpose Classes)

Friday, March 11, 2011

Page 38: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“Show me some code already!”

Friday, March 11, 2011

Page 39: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# person_drop.rbclass PersonDrop < Liquid::Drop def first_name "Dane" end def last_name "Harrigan" endend

Friday, March 11, 2011

Page 40: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# app/models/person.rbclass Person < ActiveRecord::Baseliquid_methods :first_name, :last_name

end

Friday, March 11, 2011

Page 41: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# rendering a liquid templatetemplate = Liquid::Template.parse(tmpl_code)template.render(:person => PersonDrop.new)

Friday, March 11, 2011

Page 42: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# rendering a liquid templatetemplate = Liquid::Template.parse(tmpl_code)template.render(:person => PersonDrop.new)

Friday, March 11, 2011

Page 43: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

<body> <h1>{{ person.first_name }} {{ person.last_name }}</h1></body>

Friday, March 11, 2011

Page 44: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“Ok, what about filters?”

Friday, March 11, 2011

Page 45: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# my_filters.rbmodule MyFilters def greet(name) "Hello #{name}!" end def goodbye(name) "Goodbye #{name}!" endend

Friday, March 11, 2011

Page 46: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# rendering a liquid templateLiquid::Template.register_filter MyFilters

template = Liquid::Template.parse(tmpl_code)template.render(:person => PersonDrop.new)

Friday, March 11, 2011

Page 47: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# rendering a liquid templateLiquid::Template.register_filter MyFilters

template = Liquid::Template.parse(tmpl_code)template.render(:person => PersonDrop.new)

Friday, March 11, 2011

Page 48: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

<body> <h1>{{ person.first_name | greet }}</h1></body>

Friday, March 11, 2011

Page 49: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“Way easy. Tags please.”

Friday, March 11, 2011

Page 50: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

<body> {% foo "bar", "cux" %} <h1>{{ person.first_name | greet }}</h1></body>

Friday, March 11, 2011

Page 51: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

<body> {% foo "bar", "cux" %} <h1>{{ person.first_name | greet }}</h1></body>

Friday, March 11, 2011

Page 52: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# rendering a liquid templateLiquid::Template.register_tag 'foo', FooTag

template = Liquid::Template.parse(tmpl_code)template.render(:person => PersonDrop.new)

Friday, March 11, 2011

Page 53: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# rendering a liquid templateLiquid::Template.register_tag 'foo', FooTag

template = Liquid::Template.parse(tmpl_code)template.render(:person => PersonDrop.new)

Friday, March 11, 2011

Page 54: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# foo_tag.rbclass FooTag < Liquid::Tag def render(context) @markup # => '"bar", "cux"' context # => {'person' => PersonDrop.new}

# logic for your foo tag endend

Friday, March 11, 2011

Page 55: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# foo_tag.rbclass FooTag < Liquid::Tag def render(context) @markup # => '"bar", "cux"' context # => {'person' => PersonDrop.new}

# logic for your foo tag endend

Friday, March 11, 2011

Page 56: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“Ok, real example please?”

Friday, March 11, 2011

Page 57: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

<!DOCTYPE HTML><html> <body> {% snippet 'header' %} <h1>{{ person.first_name | greet }}</h1> {% snippet 'footer' %} </body></html>

Friday, March 11, 2011

Page 58: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

<!DOCTYPE HTML><html> <body> {% snippet 'header' %} <h1>{{ person.first_name | greet }}</h1> {% snippet 'footer' %} </body></html>

Friday, March 11, 2011

Page 59: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# rendering a liquid templateLiquid::Template.register_tag 'snippet', SnippetTag

template = Liquid::Template.parse(tmpl_code)template.render(:person => PersonDrop.new)

Friday, March 11, 2011

Page 60: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# snippet_tag.rbclass SnippetTag < Liquid::Tag def render(context) name = @markup.gsub(/("|')/,'').strip

tmpl = Template.snippets.first_by_name(name) content = tmpl.content

template = Liquid::Template.parse(content) template.render(:person => PersonDrop.new) endend

Friday, March 11, 2011

Page 61: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# snippet_tag.rbclass SnippetTag < Liquid::Tag def render(context) name = @markup.gsub(/("|')/,'').strip

tmpl = Template.snippets.first_by_name(name) content = tmpl.content

template = Liquid::Template.parse(content) template.render(:person => PersonDrop.new) endend

Friday, March 11, 2011

Page 62: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# snippet_tag.rbclass SnippetTag < Liquid::Tag def render(context) name = @markup.gsub(/("|')/,'').strip

tmpl = Template.snippets.first_by_name(name) content = tmpl.content

template = Liquid::Template.parse(content) template.render(:person => PersonDrop.new) endend

Friday, March 11, 2011

Page 63: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# snippet_tag.rbclass SnippetTag < Liquid::Tag def render(context) name = @markup.gsub(/("|')/,'').strip

tmpl = Template.snippets.first_by_name(name) content = tmpl.content

template = Liquid::Template.parse(content) template.render(:person => PersonDrop.new) endend

Friday, March 11, 2011

Page 64: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# snippet_tag.rbclass SnippetTag < Liquid::Tag def render(context) name = @markup.gsub(/("|')/,'').strip

tmpl = Template.snippets.first_by_name(name) content = tmpl.content

template = Liquid::Template.parse(content) template.render(:person => PersonDrop.new) endend

Friday, March 11, 2011

Page 65: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# snippet_tag.rbclass SnippetTag < Liquid::Tag def render(context) name = @markup.gsub(/("|')/,'').strip

tmpl = Template.snippets.first_by_name(name) content = tmpl.content

template = Liquid::Template.parse(content) template.render(:person => PersonDrop.new) endend

Friday, March 11, 2011

Page 66: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“Can this actually get easier?”

Friday, March 11, 2011

Page 67: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

Liquify: Liquid Simplified

Friday, March 11, 2011

Page 68: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

•Register Drops, Filters and Tags in one Place

Liquify: Liquid Simplified

Friday, March 11, 2011

Page 69: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

•Register Drops, Filters and Tags in one Place

•Improvements to liquid_methods

Liquify: Liquid Simplified

Friday, March 11, 2011

Page 70: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

•Register Drops, Filters and Tags in one Place

•Improvements to liquid_methods

•Auto-parsed Parameters

Liquify: Liquid Simplified

Friday, March 11, 2011

Page 71: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# register tagLiquid::Template.register_tag 'foo', FooTag

# register filtersLiquid::Template.register_filter BarFilters

# register droptmpl = Liquid::Template.parse(template_code)tmpl.render(:person => PersonDrop.new)

Friday, March 11, 2011

Page 72: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# register tagLiquid::Template.register_tag 'foo', FooTag

# register filtersLiquid::Template.register_filter BarFilters

# register droptmpl = Liquid::Template.parse(template_code)tmpl.render(:person => PersonDrop.new)

Friday, March 11, 2011

Page 73: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# register tagLiquid::Template.register_tag 'foo', FooTag

# register filtersLiquid::Template.register_filter BarFilters

# register droptmpl = Liquid::Template.parse(template_code)tmpl.render(:person => PersonDrop.new)

Friday, March 11, 2011

Page 74: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

# register tagLiquid::Template.register_tag 'foo', FooTag

# register filtersLiquid::Template.register_filter BarFilters

# register droptmpl = Liquid::Template.parse(template_code)tmpl.render(:person => PersonDrop.new)

Friday, March 11, 2011

Page 75: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“I’m dying to see Liquify!”

Friday, March 11, 2011

Page 76: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

Liquify.setup do |config| config.register_tag :foo, FooTag config.register_filter BarFilters config.register_drop :person, PersonDrop

# need access to stuff later? config.register_drop :person, lambda { PersonDrop.first }end

Friday, March 11, 2011

Page 77: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

Liquify.setup do |config| config.register_tag :foo, FooTag config.register_filter BarFilters config.register_drop :person, PersonDrop

# need access to stuff later? config.register_drop :person, lambda { PersonDrop.first }end

Friday, March 11, 2011

Page 78: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

Liquify.setup do |config| config.register_tag :foo, FooTag config.register_filter BarFilters config.register_drop :person, PersonDrop

# need access to stuff later? config.register_drop :person, lambda { PersonDrop.first }end

Friday, March 11, 2011

Page 79: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

Liquify.setup do |config| config.register_tag :foo, FooTag config.register_filter BarFilters config.register_drop :person, PersonDrop

# need access to stuff later? config.register_drop :person, lambda { PersonDrop.first }end

Friday, March 11, 2011

Page 80: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

Liquify.setup do |config| config.register_tag :foo, FooTag config.register_filter BarFilters config.register_drop :person, PersonDrop

# need access to stuff later? config.register_drop :person, lambda { PersonDrop.first }end

Friday, March 11, 2011

Page 81: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

Liquify.invoke(template_code)

Friday, March 11, 2011

Page 82: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“Sweet!”

Friday, March 11, 2011

Page 83: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

class Person < ActiveRecord::Base liquify_methods :first_name, :last_name, :full_name => lambda { |p| "#{p.first_name} #{p.last_name}" }end

Friday, March 11, 2011

Page 84: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“I approve.”

Friday, March 11, 2011

Page 85: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

<body> <h1>{{ person.first_name | greet }}</h1> {% snippet 'profile', item: person, class: 'active' %}</body>

Friday, March 11, 2011

Page 86: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

<body> <h1>{{ person.first_name | greet }}</h1> {% snippet 'profile', item: person, class: 'active' %}</body>

Friday, March 11, 2011

Page 87: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

class SnippetTag < Liquify::Tag def invoke(params) params # => ['profile', { # 'item' => PersonDrop.new, # 'class' => 'active'} # ] endend

Friday, March 11, 2011

Page 88: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

class SnippetTag < Liquify::Tag def invoke # don't need params? endend

Friday, March 11, 2011

Page 89: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

“You’ve changed my life.”

Friday, March 11, 2011

Page 90: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

I’m Dane Harrigan

Friday, March 11, 2011

Page 91: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

Thanks

Friday, March 11, 2011

Page 92: LIQUID MARKUP - Meetupfiles.meetup.com/1397868/Liquid-Markup.pdf · When Should I use Liquid When you need a limited feature set •Only allow access to specific objects •Specify

Twitter: @daneharrigan

Github: daneharrigan

gem install liquify

Friday, March 11, 2011