Repository navigation
Expand file tree
/
Copy pathLabcoatConfiguration.php
More file actions
81 lines (70 loc) · 2.68 KB
/
Copy pathLabcoatConfiguration.php
File metadata and controls
81 lines (70 loc) · 2.68 KB
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
<?php
namespace Labcoat\Configuration;
use Labcoat\PatternLab;
class LabcoatConfiguration extends Configuration {
protected $root;
public function __construct($root) {
$this->root = $root;
$this->setPatternExtension('twig');
$this->setHiddenControls(['hay']);
if ($assets = $this->getDirectoryIfExists('assets')) {
$this->addAssetDirectory($assets);
}
if ($patterns = $this->getDirectoryIfExists('patterns')) {
$this->setPatternsDirectory($patterns);
}
if ($data = $this->getDirectoryIfExists('data')) {
foreach (glob(PatternLab::makePath([$data, '*.json'])) as $path) {
if (basename($path) == 'listitems.json') $this->addListItems($path);
else $this->addGlobalData($path);
}
}
if ($annotations = $this->getFileIfExists(['styleguide', 'annotations.js'])) {
$this->setAnnotationsFile($annotations);
}
if ($styleguideHeader = $this->getFileIfExists(['styleguide', 'header.twig'])) {
$this->setStyleguideHeader($styleguideHeader);
}
if ($styleguideFooter = $this->getFileIfExists(['styleguide', 'footer.twig'])) {
$this->setStyleguideFooter($styleguideFooter);
}
if ($assets = $this->getDirectoryIfExists(['styleguide', 'assets'])) {
$this->addStyleguideAssetDirectory($assets);
}
if ($assets = $this->findStyleguideAssetsDirectory()) {
$this->addStyleguideAssetDirectory($assets);
}
if ($templates = $this->findStyleguideTemplatesDirectory()) {
$this->setStyleguideTemplatesDirectory($templates);
}
}
protected function findStyleguideAssetsDirectory() {
if (!$vendor = $this->findVendorDirectory()) return null;
$path = PatternLab::makePath([$vendor, 'pattern-lab', 'styleguidekit-assets-default', 'dist']);
return is_dir($path) ? $path : null;
}
protected function findStyleguideTemplatesDirectory() {
if (!$vendor = $this->findVendorDirectory()) return null;
$path = PatternLab::makePath([$vendor, 'pattern-lab', 'styleguidekit-twig-default', 'views']);
return is_dir($path) ? $path : null;
}
protected function findVendorDirectory() {
$className = "Composer\\Autoload\\ClassLoader";
if (!class_exists($className)) return null;
$c = new \ReflectionClass($className);
return dirname($c->getFileName()) . '/..';
}
protected function getDirectoryIfExists($path) {
$dir = $this->makePath($path);
return is_dir($dir) ? $dir : null;
}
protected function getFileIfExists($path) {
$file = $this->makePath($path);
return is_file($file) ? $file : null;
}
protected function makePath($path) {
$path = (array)$path;
array_unshift($path, $this->root);
return PatternLab::makePath($path);
}
}