Example #1
0
    function testReplaceImgSnippet()
    {
        $he = new Hamle\Hamle($this->model(), new snippetReplaceImgSetup());
        $hamle = "html\n" . "  head\n" . "    title \$titlebar\n" . "  body\n" . "    |each\n" . "      .enlarge\n" . "        img[src={\$url}/thumb&alt=\$alt]\n" . "    div\n" . "      .two.find1\n" . "        .stuff\n" . "          .more-stuff\n" . "            .find2\n" . "              .gone\n";
        $html = <<<TESTHTML
<html>
  <head>
    <title>My Page</title>
    <script type="text/javascript" src="/js/lightbox"></script>
  </head>
  <body>
    <div class="enlarge">
      <a href="#" onclick="enlarge('imgid')" data-img="/img/1">
        <img src="/img/1/thumb" alt="My Image #1" />
      </a>
    </div>
    <div class="enlarge">
      <a href="#" onclick="enlarge('imgid')" data-img="/img/2">
        <img src="/img/2/thumb" alt="My Image #2" />
      </a>
    </div>
    <div>
      <div class="two find1">
        <div class="stuff">
          <div class="more-stuff">
            <div class="found">Hi There</div>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>
TESTHTML;
        $he->string($hamle);
        $out = $he->output();
        $this->assertEquals(trim($html), trim($out));
        $this->compareXmlStrings($html, $out);
    }
Example #2
0
 function __construct($message = "", $code = 0, $previous = NULL)
 {
     ///@todo  Include Line number & file name within parse error exceptions
     $message .= ", on line " . Hamle\Hamle::getLineNo() . " in file ?.hamle";
     parent::__construct($message, $code, $previous);
 }
Example #3
0
    {
        return __DIR__ . "/hamle/{$f}";
    }
    function getSnippets()
    {
        return array(__DIR__ . "/hamle/snippets/replace-img.hamle-snip");
    }
}
$ho = new Hamle(new WrapArray(array(array('url' => '/img/1', 'title' => 'The TITLE', 'titlebar' => "My Page", 'alt' => 'My Image #1'), array('url' => '/img/2', 'title' => 'The TITLE', 'titlebar' => "My Page", 'alt' => 'My Image #2'))), new snippetSetup());
$hamle = "html\n" . "  head\n" . "    title \$titlebar\n" . "  body\n" . "    |each\n" . "      .enlarge\n" . "        img[src={\$url}/thumb&alt=\$alt]\n";
$html = "<html><head>\n" . "   <title>The TITLE</title>\n" . "   <title>The TITLE</title>\n" . "   <title>The TITLE</title>\n" . "</head><body>" . "<div class=\"content\"></div>" . "</body></html>";
echo $ho->outputStr($hamle);
exit;
class mySetup extends Setup
{
    function getNamedModel($name, $id = NULL)
    {
        if ($name == "basetest") {
            return new WrapArray(array(array('url' => 'http://www.test.com', 'title' => 'Test.com'), array('url' => 'http://www.test2.com', 'title' => 'Test2.com'), array('url' => 'http://www.test3.com', 'title' => 'Test3.com')));
        }
        return parent::getNamedModel($name, $id);
    }
}
$h = new Hamle(new WrapArray(array(array('link' => 'https://www.secure.com', 'website' => 'Secure.com'))), new mySetup());
$hamle = "html" . PHP_EOL . "  body" . PHP_EOL . '    |with $(basetest)' . PHP_EOL . '      ul.menu' . PHP_EOL . '        |each' . PHP_EOL . '          li.menuitem[data-menu=$title]' . PHP_EOL . '            a[href=$url] $title' . PHP_EOL;
var_dump($hs = new hamleStrVar("\$(.heroimage^:1)", hamleStrVar::TOKEN_CONTROL));
var_dump($hs->toPHP());
var_dump($hs->toHTML());
exit;
$hamle = "html\n  a.quote[onclick=alert(\"Hi There\")] Hi There";
echo $h->outputStr($hamle);