Esempio n. 1
0
 function test_local_global()
 {
     $template = new LiquidTemplate();
     $template->register_filter(new MoneyFilter());
     $template->parse('{{1000 | money}}');
     $this->assertIdentical(' 1000$ ', $template->render());
     $this->assertIdentical(' 1000$ CAD ', $template->render(null, new CanadianMoneyFilter()));
 }
 function test_array_scoping()
 {
     $template = new LiquidTemplate();
     $template->parse('{{ test.test }}');
     $this->assertEqual('worked', $template->render(array('test' => array('test' => 'worked'))));
     // this wasn't working properly in if tests, test seperately
     $template->parse('{{ foo.bar }}');
     $this->dump($template->render(array('foo' => array())));
 }
Esempio n. 3
0
 function test_error_with_css()
 {
     $text = " div { font-weight: bold; } ";
     $template = new LiquidTemplate();
     $template->parse($text);
     $this->assertEqual($text, $template->render());
     $this->assertIsA($template->root->nodelist[0], 'string');
 }
Esempio n. 4
0
 /**
  * Tests filtered value assignment
  *
  * @return void
  */
 public function testAssignWithFilters()
 {
     $template = new LiquidTemplate();
     $template->parse('{% assign test = "hello" | upcase %}{{ test }}');
     $this->assertTrue($template->render() === 'HELLO');
     $template->parse('{% assign test = "hello" | upcase | downcase | capitalize %}{{ test }}');
     $this->assertTrue($template->render() === 'Hello');
     $template->parse('{% assign test = var1 | first | upcase %}{{ test }}');
     $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'A');
     $template->parse('{% assign test = var1 | last | upcase %}{{ test }}');
     $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'C');
     $template->parse('{% assign test = var1 | join %}{{ test }}');
     $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'a b c');
     $template->parse('{% assign test = var1 | join : "." %}{{ test }}');
     $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'a.b.c');
 }
Esempio n. 5
0
<?php

require_once '../lib/liquid.php';
$liquid = new LiquidTemplate();
$liquid->parse(file_get_contents('templates/index.liquid'));
$assigns = array('date' => date('r'));
print $liquid->render($assigns);
Esempio n. 6
0
 function test_include_tag_no_with()
 {
     $template = new LiquidTemplate();
     $template->setFileSystem(new LiquidTestFileSystem());
     $template->parse("Outer-{% include 'inner' %}-Outer-{% include 'inner' other:'23' %}");
     $output = $template->render(array("inner" => "orig", "var" => array(1, 2, 3)));
     $this->assertEqual("Outer-Inner: orig-Outer-Inner: orig23", $output);
 }
Esempio n. 7
0
 public function assertTrueHelper($templateString, $expected, $data = array())
 {
     $template = new LiquidTemplate();
     $template->parse($templateString);
     $this->assertTrue($template->render($data) === $expected);
 }
Esempio n. 8
0
<?php

define('LIQUID_INCLUDE_SUFFIX', 'tpl');
define('LIQUID_INCLUDE_PREFIX', '');
require_once '../Liquid.class.php';
$liquid = new LiquidTemplate();
$liquid->parse('{{ hello }} {{ goback }}');
print $liquid->render(array('hello' => 'hello world', 'goback' => '<a href=".">index</a>'));
Esempio n. 9
0
 function test_override_global_filter()
 {
     $template = new LiquidTemplate();
     $template->register_filter(new GlobalFilter());
     $template->parse("{{'test' | notice }}");
     $this->assertEqual('Global test', $template->render());
     $this->assertEqual('Local test', $template->render(array(), new LocalFilter()));
 }
Esempio n. 10
0
 function test_nested_context_drop()
 {
     $template = new LiquidTemplate();
     $template->parse(' {{ product.context.foo }} ');
     $output = $template->render(array('product' => new ProductDrop(), 'foo' => 'monkey'));
     $this->assertEqual(' monkey ', $output);
 }
Esempio n. 11
0
<?php

define('LIQUID_INCLUDE_ALLOW_EXT', true);
require_once '../Liquid.class.php';
define('PROTECTED_PATH', dirname(__FILE__) . '/protected/');
$liquid = new LiquidTemplate(PROTECTED_PATH . 'templates/');
$cache = array('cache' => 'file', 'cache_dir' => PROTECTED_PATH . 'cache/');
//$cache = array('cache' => 'apc');
//$liquid->setCache($cache);
$liquid->parse(file_get_contents(PROTECTED_PATH . 'templates/child.tpl'));
$assigns = array('document' => array('title' => 'This is php-liquid', 'content' => 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.', 'copyright' => '&copy; Copyright 2012 Harald Hanek - All rights reserved.'));
echo $liquid->render($assigns);
Esempio n. 12
0
<?php

class ProductsFilter
{
    function price($integer)
    {
        return sprintf("\$%.2d USD", $integer / 100);
    }
    function prettyprint($text)
    {
        return preg_replace('/\\*(.*)\\*/', '<b>\\1</b>', $text);
    }
    function count($array)
    {
        return count($array);
    }
    function paragraph($p)
    {
        return "<p>" . $p . "</p>";
    }
}
require_once '../lib/liquid.php';
$liquid = new LiquidTemplate();
$liquid->register_filter(new ProductsFilter());
$liquid->parse(file_get_contents('templates/products.liquid'));
$products_list = array(array('name' => 'Arbor Draft', 'price' => 39900, 'description' => 'the *arbor draft* is a excellent product'), array('name' => 'Arbor Element', 'price' => 40000, 'description' => 'the *arbor element* rocks for freestyling'), array('name' => 'Arbor Diamond', 'price' => 59900, 'description' => 'the *arbor diamond* is a made up product because im obsessed with arbor and have no creativity'));
$products = array('products' => $products_list, 'section' => 'Snowboards', 'cool_products' => true);
$assigns = array('date' => date('r'));
print $liquid->render($products);