-
Notifications
You must be signed in to change notification settings - Fork 115
/
functions.php
77 lines (57 loc) · 1.88 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
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
<?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/';
$sassPath = $root.$absolutePath.'css/scss/';
/**************
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
************** */
/**
* Provide a filter for excluding hidden .git or .svn folders from the inc() function
*/
class ExcludeFilter extends RecursiveFilterIterator {
public static $FILTERS = array(
'.svn',
'.git'
);
public function accept() {
//Check if a file is within one of the folders listed in the exclude list
foreach(self::$FILTERS as $filter) {
if(strpos($this->current()->getPath(),$filter)) {
return false;
}
}
return true;
}
}
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 ExcludeFilter(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;
}
}
}