forked from bradfrost/patternlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
51 lines (38 loc) · 1.37 KB
/
functions.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
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
//This changes the root path of the project. It might live at the root or at a subdirectory like /styleguide
$absolutePath = '/';
$patternsPath = $root.$absolutePath.'patterns/';
/**************
Include Function
Make including files easier. Simply declare the type of fragment you're looking for (atom, molecule, organism, or page) and the name of the file (with no extention)
Takes two variables:
Type: the type of pattern you're looking to include. Options are: atom, molecule, organism, or page
Name: the name of the file
************** */
function inc($type,$name) {
global $patternsPath;
global $absolutePath;
$filePath = $patternsPath;
//Determine which directory to look in based on type: atom, molecule, organism or page
if($type=='atom') {
$filePath = $filePath.'00-Atoms';
} elseif($type=='molecule') {
$filePath = $filePath.'01-Molecules';
} elseif($type=='organism') {
$filePath = $filePath.'02-Organisms';
} elseif($type=='page') {
$filePath = $filePath.'03-Pages';
} else {
$filePath = $filePath;
}
//Iterate over the appropriate path
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filePath));
foreach($objects as $objName => $object){
$pos = stripos($objName, $name);
if ($pos) {
include($objName); //Include the fragment if the file is found
break;
}
}
}