require 'test/spec' require 'ferret' require 'pyrosoma/frame' require 'pyrosoma/frame/liquid' require 'pyrosoma/database' context "Pyrosoma::RenderLiquidTemplate" do setup do @db = Pyrosoma::Database.new(:dir => Ferret::Store::RAMDirectory.new) @master = Pyrosoma::Frame.new({ :id => "master", :foo => "bar", :child => "@frame", }) @frame = Pyrosoma::Frame.new({ :id => "frame", :a => "foo", :b => "bar", :multiple => ["a", "b", "c"], :master => "@master", :indirect => "@master", }) @db << @master << @frame end specify "should render static default template" do @frame.update :template => "static template" @frame.render.should.equal "static template" end specify "should include fields" do @frame.update :template => "a is {{ a }}" @frame.render.should.equal "a is foo" @frame.update :template => "multiple is {{ multiple }}" @frame.render.should.equal "multiple is abc" end specify "should follow links" do @frame.update :template => "master.foo is {{ master.foo }}" @frame.render.should.equal "master.foo is bar" @frame.update :template => "doubly-indirect a is {{ master.child.a }}" @frame.render.should.equal "doubly-indirect a is foo" end specify "should support inverse links" do @frame.update :template => "inverse_child.foo is {{ inverse_child.foo }}" @frame.render.should.equal "inverse_child.foo is bar" end specify "should support non-default templates" do @frame.update :template => "blablabla: {{ a }}" @frame.update :template_small => "{{a}}" @frame.render.should.equal "blablabla: foo" @frame.render(:template_small).should.equal "foo" end specify "should support other templates with filters" do @frame.update :template => "blablabla: {{ a }}" @frame.update :template_small => "{{a}}" @db << @frame @master.update :template => "child: {{ child | render: 'template_small' }}" @master.render.should.equal "child: foo" end specify "should support find-blocks" do @master = Pyrosoma::Frame.new({ :id => "master", :foo => "bar", :child => "@frame", }) @frame = Pyrosoma::Frame.new({ :id => "frame", :a => "foo", :b => "bar", :multiple => ["a", "b", "c"], :master => "@master", :indirect => "@master", }) @db << @master << @frame end specify "should render static default template" do @frame.update :template => "static template" @frame.render.should.equal "static template" end specify "should include fields" do @frame.update :template => "a is {{ a }}" @frame.render.should.equal "a is foo" @frame.update :template => "multiple is {{ multiple }}" @frame.render.should.equal "multiple is abc" end specify "should follow links" do @frame.update :template => "master.foo is {{ master.foo }}" @frame.render.should.equal "master.foo is bar" @frame.update :template => "doubly-indirect a is {{ master.child.a }}" @frame.render.should.equal "doubly-indirect a is foo" end specify "should support inverse links" do @frame.update :template => "inverse_child.foo is {{ inverse_child.foo }}" @frame.render.should.equal "inverse_child.foo is bar" end specify "should support non-default templates" do @frame.update :template => "blablabla: {{ a }}" @frame.update :template_small => "{{a}}" @frame.render.should.equal "blablabla: foo" @frame.render(:template_small).should.equal "foo" end specify "should support other templates with filters" do @frame.update :template => "blablabla: {{ a }}" @frame.update :template_small => "{{a}}" @db << @frame @master.update :template => "child: {{ child | render: 'template_small' }}" @master.render.should.equal "child: foo" end specify "should support find-blocks" do @frame.update :template => "{% find x as 'foo:bar' %}{{x.foo}}{% endfind %}" @frame.render.should.equal "bar" end end