Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/main/php/web/frontend/FrontMatter.class.php

This file was deleted.

7 changes: 4 additions & 3 deletions src/main/php/web/frontend/TemplateParser.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public function parse(Tokenizer $tokens, $start= '{{', $end= '}}', $indent= '')
}

$tokens->nextToken("\n");
$nodes= parent::parse($tokens, $start, $end, $indent);
$nodes->decorate(new FrontMatter((self::$yaml ?? self::$yaml= new YamlParser())->parse(new StringInput($yaml))));
return $nodes;
return new WithFrontMatter(
parent::parse($tokens, $start, $end, $indent),
(self::$yaml ?? self::$yaml= new YamlParser())->parse(new StringInput($yaml))
);
}

// Just a regular template, delegate to parent
Expand Down
32 changes: 32 additions & 0 deletions src/main/php/web/frontend/WithFrontMatter.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php namespace web\frontend;

use com\github\mustache\Node;

class WithFrontMatter extends Node {
private $nodes, $pairs;

/**
* Creates new frontmatter
*
* @param com.handlebarsjs.Nodes $nodes
* @param [:var] $pairs
*/
public function __construct($nodes, $pairs) {
$this->nodes= $nodes;
$this->pairs= (array)$pairs;
}

/**
* Evaluates this node
*
* @param com.github.mustache.Context $context the rendering context
* @param io.streams.OutputStream $out
*/
public function write($context, $out) {
$context->variables+= $this->pairs;
$this->nodes->write($context, $out);
}

/** @return string */
public function __toString() { return (string)$this->nodes; }
}