Skip to content

Commit

Permalink
Add liquid.cr support (#15)
Browse files Browse the repository at this point in the history
* Add liquid.cr support

* Minor

* Add specs for passing custom context to Liquid

E.g.:

context = Liquid::Context.new
context.set "key", "value"
render( "/path/to/template.liquid", context)
  • Loading branch information
docelic authored and jeromegn committed Feb 10, 2018
1 parent d177f02 commit bfd630f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions shard.yml
Expand Up @@ -13,3 +13,5 @@ development_dependencies:
github: MakeNowJust/crustache
temel:
github: f/temel
liquid:
github: TechMagister/liquid.cr
1 change: 1 addition & 0 deletions spec/fixtures/test.liquid
@@ -0,0 +1 @@
<span>{{ process.pid }}</span>
31 changes: 31 additions & 0 deletions spec/kilt/liquid_spec.cr
@@ -0,0 +1,31 @@
require "../spec_helper"
require "../../src/liquid"

class LiquidView
@process = { "pid" => Process.pid }
Kilt.file "spec/fixtures/test.liquid"
end

class LiquidViewWithCustomContext
# Use of instance variable is not required in user code. It is used here to
# avoid name clash with 'context' variable existing within spec.
def initialize
@context = Liquid::Context.new
@context.set "process", { "pid" => Process.pid }
end
Kilt.file "spec/fixtures/test.liquid", "__kilt_io__", "@context"
end

it "renders liquid" do
ctx = Liquid::Context.new
ctx.set "process", { "pid" => Process.pid }
Kilt.render("spec/fixtures/test.liquid", ctx).should eq("<span>#{Process.pid}</span>\n")
end

it "works with classes" do
LiquidView.new.to_s.should eq("<span>#{Process.pid}</span>\n")
end

it "works with classes and custom context" do
LiquidViewWithCustomContext.new.to_s.should eq("<span>#{Process.pid}</span>\n")
end
4 changes: 4 additions & 0 deletions src/liquid.cr
@@ -0,0 +1,4 @@
require "./kilt"
require "liquid"

Kilt.register_engine "liquid", Liquid.embed

0 comments on commit bfd630f

Please sign in to comment.