Skip to content

Commit

Permalink
Fixed a few issues with examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
guyc committed Jun 22, 2012
1 parent 81c6609 commit dd229cc
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 19 deletions.
2 changes: 0 additions & 2 deletions Foml.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ static function GeneratePhp($Template)
// and return a temporary filename instead of a string.
static function GenerateXslFo($Template, $Args=null)
{
//Dump($_php); exit;
ob_start();
Foml::RenderFoml($Template, $Args);
$xslFo = ob_get_contents();
ob_end_clean();
//Dump($xslFo); exit;
return $xslFo;
}

Expand Down
7 changes: 6 additions & 1 deletion FomlDoc.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?php
class FomlDoc extends FomlNode
{
public $state;

function RenderToString()
function __construct()
{
$this->state = new FomlRenderState();
}

function RenderToString()
{
ob_start();
$this->Render();
$output = ob_get_contents();
Expand Down
13 changes: 13 additions & 0 deletions FomlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ class FomlFilter
{
public $children = array();

// $Node is an instance of parent FomlFilterNode.
// it is important because it contains a FomlRenderState
// instance that indicates the current output mode of this
// document.

// REVISIT - this expression should be evaluated
// in the eval context where all variables are available.
function __construct($Node, $Arg)
{
$this->node = $Node;
$this->arg = $Arg;
}

function RenderPrefix()
{
}
Expand Down
2 changes: 1 addition & 1 deletion FomlFilterNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function __construct($Matches)
if (isset(FomlParser::$FILTER_CLASSES[$filter]))
{
$filterClass = FomlParser::$FILTER_CLASSES[$filter];
$this->filter = new $filterClass($args);
$this->filter = new $filterClass($this, $args);
} else {
throw new FomlException("Unknown filter '{$filter}'");
}
Expand Down
11 changes: 2 additions & 9 deletions FomlIncludeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ class FomlIncludeFilter extends FomlFilter
{
public $args;

function __construct($Args)
{
// REVISIT - this expression should be evaluated
// in the eval context where all variables are available.
$this->args = $Args;
}

function RenderPrefix()
{
// REVISIT : can't just print the PHP here because we are
// called from within the eval context. However doing it this
// way hides all of the variables, which might be a problem.
$fileName = eval("return {$this->args};");
eval('?'.'>'. FomlParser::ParseFile($fileName));
$fileName = eval("return {$this->arg};");
eval('?'.'>'. FomlParser::ParseFile($fileName, $this->node->state));
}
}

Expand Down
3 changes: 2 additions & 1 deletion FomlNamespaceFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ class FomlNamespaceFilter extends FomlFilter
{
public $namespace;

function __construct($Arg)
function __construct($Arg, $Node)
{
parent::__construct($Arg, $Node);
$this->namespace = $Arg;
}

Expand Down
7 changes: 4 additions & 3 deletions FomlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ class FomlParser
);

// returns a FomlDocument instance
static function ParseFile($FileName)
static function ParseFile($FileName, $State=null)
{
$foml = file_get_contents($FileName);
return FomlParser::ParseString($foml);
return FomlParser::ParseString($foml, $State);
}

static function ParseString($Foml)
static function ParseString($Foml, $State)
{
$tree = FomlParseTree::Parse($Foml);
$doc = $tree->Generate();
if ($State) $doc->state = $State; // for subdocuments, pass the parent document state along
return $doc->RenderToString(); // returns php code
}
}
Expand Down
8 changes: 8 additions & 0 deletions examples/Sampler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
Foml::$keepTempFiles = false;
$debug = false;

// debugging preformatted recursive dump
function Dump($Var)
{
print "<pre>";
print_r($Var);
print "</pre>";
}

if (!$debug) {
Foml::RenderInline("foml/Sampler.foml");
} else {
Expand Down
4 changes: 2 additions & 2 deletions examples/foml/Sampler.foml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
-#----------------------------------------
-# plain text
-#----------------------------------------
/ This should not appear in the output
and neither should this.
/ This should be embedded as XML comments in the output
and so should this indented continuation.

FOML Sampler

Expand Down

0 comments on commit dd229cc

Please sign in to comment.