Skip to content

Commit 1f3b50b

Browse files
committed
reorganizing the twig pattern engine rule
1 parent 6c9164c commit 1f3b50b

File tree

3 files changed

+75
-42
lines changed

3 files changed

+75
-42
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
/*!
4+
* Twig Pattern Engine Rule Class
5+
*
6+
* Copyright (c) 2014 Dave Olsen, http://dmolsen.com
7+
* Licensed under the MIT license
8+
*
9+
* If the test matches "twig" it will return an instance of the Twig Pattern Engine
10+
*
11+
*/
12+
13+
namespace PatternLab\PatternEngine\Twig;
14+
15+
use \PatternLab\Config;
16+
use \PatternLab\PatternEngine\Twig\PatternLoader;
17+
use \PatternLab\PatternEngine\Rule;
18+
19+
class PatternEngineRule extends Rule {
20+
21+
public function __construct() {
22+
23+
parent::__construct();
24+
25+
$this->engineProp = "twig";
26+
27+
}
28+
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+
$twigLoader = new PatternLoader(Config::$options["patternSourceDir"],array("patternPaths" => $options["patternPaths"]));
37+
38+
return new \Twig_Environment($twigLoader);
39+
40+
}
41+
42+
/**
43+
* Load a new Twig instance that uses the File System Loader
44+
*
45+
* @return {Object} an instance of the Twig engine
46+
*/
47+
public function getFileSystemLoader($options = array()) {
48+
49+
$twigLoader = new Twig_Loader_Filesystem($options["templatePath"]);
50+
51+
return new \Twig_Environment($twigLoader);
52+
53+
}
54+
55+
/**
56+
* Load a new Twig instance that is just a vanilla Twig string rendering engine
57+
*
58+
* @return {Object} an instance of the Twig engine
59+
*/
60+
public function getVanillaLoader($options = array()) {
61+
62+
$twigLoader = new \Twig_Loader_String();
63+
64+
return new \Twig_Environment($twigLoader);
65+
66+
}
67+
}

src/PatternLab/TwigPatternEngine/TwigLoader.php renamed to src/PatternLab/PatternEngine/Twig/PatternLoader.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
namespace PatternLab\TwigPatternEngine;
1515

16-
use \PatternLab\PatternEngine\Loader;
16+
use \PatternLab\PatternEngine\Util;
1717

18-
class TwigLoader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface {
18+
class PatternLoader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface {
1919

2020
/** Identifier of the main namespace. */
2121
const MAIN_NAMESPACE = '__main__';
@@ -35,7 +35,10 @@ public function __construct($paths = array(),$patternPaths = array()) {
3535
$this->setPaths($paths);
3636
}
3737
$options['patternPaths'] = $patternPaths['patternPaths'];
38-
$this->patternLoader = new Loader($options);
38+
39+
// load some extra functions to help with manipulating pattern info
40+
$this->patternUtil = new Util($options);
41+
3942
}
4043

4144
/**
@@ -165,9 +168,9 @@ public function isFresh($name, $time) {
165168

166169
protected function findTemplate($name) {
167170

168-
list($partialName,$styleModifier,$parameters) = $this->patternLoader->getPartialInfo($name);
171+
list($partialName,$styleModifier,$parameters) = $this->patternUtil->getPartialInfo($name);
169172

170-
$name = $this->patternLoader->getFileName($partialName,$this->extension);
173+
$name = $this->patternUtil->getFileName($partialName,$this->extension);
171174

172175
$name = $this->normalizeName($name);
173176

src/PatternLab/TwigPatternEngine/PatternEngineRule.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)