-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathTemplate.php
138 lines (114 loc) · 4.31 KB
/
Template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/*!
* Template Helper Class
*
* Copyright (c) 2014 Dave Olsen, http://dmolsen.com
* Licensed under the MIT license
*
* Set-ups the vars needed related to setting up and rendering templates. Meaning putting
*
*/
namespace PatternLab;
use \PatternLab\Config;
use \PatternLab\Console;
use \PatternLab\Timer;
use \PatternLab\PatternData\Exporters\PatternPathSrcExporter;
class Template {
protected static $htmlHead;
protected static $htmlFoot;
protected static $patternHead;
protected static $patternFoot;
protected static $filesystemLoader;
protected static $patternLoader;
protected static $stringLoader;
/**
* Set-up default vars
*/
public static function init() {
// make sure config vars exist
if (!Config::getOption("patternExtension")) {
Console::writeError("the pattern extension config option needs to be set...");
}
if (!Config::getOption("styleguideKit")) {
Console::writeError("the styleguideKit config option needs to be set...");
}
// set-up config vars
$patternExtension = Config::getOption("patternExtension");
$metaDir = Config::getOption("metaDir");
$styleguideKit = Config::getOption("styleguideKit");
$styleguideKitPath = Config::getOption("styleguideKitPath");
if (!$styleguideKitPath || !is_dir($styleguideKitPath)) {
Console::writeError("your styleguide won't render because i can't find your styleguide files. are you sure they're at <path>".Console::getHumanReadablePath($styleguideKitPath)."</path>? you can fix this in <path>./config/config.yml</path> by editing styleguideKitPath...");
}
// load pattern-lab's resources
$partialPath = $styleguideKitPath.DIRECTORY_SEPARATOR."views".DIRECTORY_SEPARATOR."partials";
$generalHeaderPath = $partialPath.DIRECTORY_SEPARATOR."general-header.".$patternExtension;
$generalFooterPath = $partialPath.DIRECTORY_SEPARATOR."general-footer.".$patternExtension;
self::$htmlHead = (file_exists($generalHeaderPath)) ? file_get_contents($generalHeaderPath) : "";
self::$htmlFoot = (file_exists($generalFooterPath)) ? file_get_contents($generalFooterPath) : "";
// gather the user-defined header and footer information
$patternHeadPath = $metaDir.DIRECTORY_SEPARATOR."_00-head.".$patternExtension;
$patternFootPath = $metaDir.DIRECTORY_SEPARATOR."_01-foot.".$patternExtension;
self::$patternHead = (file_exists($patternHeadPath)) ? file_get_contents($patternHeadPath) : "";
self::$patternFoot = (file_exists($patternFootPath)) ? file_get_contents($patternFootPath) : "";
// add the filesystemLoader
$patternEngineBasePath = PatternEngine::getInstance()->getBasePath();
$filesystemLoaderClass = $patternEngineBasePath."\Loaders\FilesystemLoader";
$options = array();
$options["templatePath"] = $styleguideKitPath.DIRECTORY_SEPARATOR."views";
$options["partialsPath"] = $options["templatePath"].DIRECTORY_SEPARATOR."partials";
self::$filesystemLoader = new $filesystemLoaderClass($options);
// add the stringLoader
$stringLoaderClass = $patternEngineBasePath."\Loaders\StringLoader";
self::$stringLoader = new $stringLoaderClass();
// add the patternLoader
$ppdExporter = new PatternPathSrcExporter();
$patternPathSrc = $ppdExporter->run();
$options = array();
$options["patternPaths"] = $patternPathSrc;
$patternLoaderClass = $patternEngineBasePath."\Loaders\PatternLoader";
self::$patternLoader = new $patternLoaderClass($options);
}
/*
* Get the html header
*/
public static function getHTMLHead() {
return self::$htmlHead;
}
/*
* Get the html foot
*/
public static function getHTMLFoot() {
return self::$htmlFoot;
}
/*
* Get the pattern header
*/
public static function getPatternHead() {
return self::$patternHead;
}
/*
* Get the pattern footer
*/
public static function getPatternFoot() {
return self::$patternFoot;
}
/*
* Get the file system loader
*/
public static function getFilesystemLoader() {
return self::$filesystemLoader;
}
/*
* Get the html loader
*/
public static function getStringLoader() {
return self::$stringLoader;
}
/*
* Get the PatternLoader
*/
public static function getPatternLoader() {
return self::$patternLoader;
}
}