Skip to content

Commit 846a957

Browse files
committed
updating twig pattern engine to match changes to api
not tested
1 parent 9aaf746 commit 846a957

File tree

5 files changed

+128
-43
lines changed

5 files changed

+128
-43
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*!
4+
* Twig Pattern Engine Loader Class - Filesystem
5+
*
6+
* Copyright (c) 2014 Dave Olsen, http://dmolsen.com
7+
* Licensed under the MIT license
8+
*
9+
* Sets an instance of Twig to deal with rendering of templates that aren't patterns
10+
*
11+
*/
12+
13+
namespace PatternLab\PatternEngine\Twig\Loaders;
14+
15+
use \PatternLab\PatternEngine\Loader;
16+
17+
class FilesystemLoader extends Loader {
18+
19+
/**
20+
* Load a new Twig instance that uses the File System Loader
21+
*/
22+
public function __construct($options = array()) {
23+
24+
$twigLoader = new \Twig_Loader_Filesystem(array($options["templatePath"],$options["partialsPath"]));
25+
$this->instance = new \Twig_Environment($twigLoader);
26+
27+
}
28+
29+
/**
30+
* Render a template
31+
* @param {Array} the options to be rendered by Twig
32+
*
33+
* @return {String} the rendered result
34+
*/
35+
public function render($options = array()) {
36+
37+
return $this->instance->render($options["template"], $options["data"]);
38+
39+
}
40+
41+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*!
4+
* Mustache Pattern Engine Loader Class - Patterns
5+
*
6+
* Copyright (c) 2014 Dave Olsen, http://dmolsen.com
7+
* Licensed under the MIT license
8+
*
9+
* Sets an instance of Mustache to deal with rendering of patterns
10+
*
11+
*/
12+
13+
namespace PatternLab\PatternEngine\Twig\Loaders;
14+
15+
use \PatternLab\Config;
16+
use \PatternLab\PatternEngine\Twig\Loaders\Twig\PatternLoader as Twig_Loader_PatternLoader;
17+
use \PatternLab\PatternEngine\Loader;
18+
19+
class PatternLoader extends Loader {
20+
21+
/**
22+
* Load a new Twig instance that uses the Pattern Loader
23+
*/
24+
public function __construct($options = array()) {
25+
26+
//default var
27+
$patternSourceDir = Config::getOption("patternSourceDir");
28+
$twigLoader = new Twig_Loader_PatternLoader($patternSourceDir,array("patternPaths" => $options["patternPaths"]));
29+
$this->instance = new \Twig_Environment($twigLoader);
30+
31+
}
32+
33+
/**
34+
* Render a pattern
35+
* @param {Array} the options to be rendered by Twig
36+
*
37+
* @return {String} the rendered result
38+
*/
39+
public function render($options = array()) {
40+
41+
return $this->instance->render($options["pattern"], $options["data"]);
42+
43+
}
44+
45+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*!
4+
* Twig Pattern Engine Loader Class - String
5+
*
6+
* Copyright (c) 2014 Dave Olsen, http://dmolsen.com
7+
* Licensed under the MIT license
8+
*
9+
* Sets an instance of Twig to deal with rendering of strings
10+
*
11+
*/
12+
13+
namespace PatternLab\PatternEngine\Twig\Loaders;
14+
15+
use \PatternLab\PatternEngine\Loader;
16+
17+
class StringLoader extends Loader {
18+
19+
/**
20+
* Load a new Twig instance that is just a vanilla Twig rendering engine for strings
21+
*/
22+
public function __construct($options = array()) {
23+
24+
$twigLoader = new \Twig_Loader_String();
25+
$this->instance = new \Twig_Environment($twigLoader);
26+
27+
}
28+
29+
/**
30+
* Render a string
31+
* @param {Array} the options to be rendered by Twig
32+
*
33+
* @return {String} the rendered result
34+
*/
35+
public function render($options = array()) {
36+
37+
return $this->instance->render($options["string"], $options["data"]);
38+
39+
}
40+
41+
}

src/PatternLab/PatternEngine/Twig/PatternEngineRule.php

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
namespace PatternLab\PatternEngine\Twig;
1414

15-
use \PatternLab\Config;
16-
use \PatternLab\PatternEngine\Twig\PatternLoader;
1715
use \PatternLab\PatternEngine\Rule;
1816

1917
class PatternEngineRule extends Rule {
@@ -23,48 +21,8 @@ public function __construct() {
2321
parent::__construct();
2422

2523
$this->engineProp = "twig";
24+
$this->basePath = "\PatternLab\PatternEngine\Mustache";
2625

2726
}
2827

29-
/**
30-
* Load a new Twig instance that uses the Pattern Loader
31-
*
32-
* @return {Object} an instance of the Twig engine
33-
*/
34-
public function getPatternLoader($options = array()) {
35-
36-
//default var
37-
$patternSourceDir = Config::getOption("patternSourceDir");
38-
39-
$twigLoader = new PatternLoader($patternSourceDir,array("patternPaths" => $options["patternPaths"]));
40-
41-
return new \Twig_Environment($twigLoader);
42-
43-
}
44-
45-
/**
46-
* Load a new Twig instance that uses the File System Loader
47-
*
48-
* @return {Object} an instance of the Twig engine
49-
*/
50-
public function getFileSystemLoader($options = array()) {
51-
52-
$twigLoader = new Twig_Loader_Filesystem(array($options["templatePath"],$options["partialsPath"]));
53-
54-
return new \Twig_Environment($twigLoader);
55-
56-
}
57-
58-
/**
59-
* Load a new Twig instance that is just a vanilla Twig string rendering engine
60-
*
61-
* @return {Object} an instance of the Twig engine
62-
*/
63-
public function getVanillaLoader($options = array()) {
64-
65-
$twigLoader = new \Twig_Loader_String();
66-
67-
return new \Twig_Environment($twigLoader);
68-
69-
}
7028
}

0 commit comments

Comments
 (0)