mirror of
https://github.com/pattern-lab/patternlab-php.git
synced 2025-01-29 20:08:43 +01:00
adding support for lineage
This commit is contained in:
parent
938adfb8dc
commit
953dcc2d64
@ -24,6 +24,7 @@ class Builder {
|
||||
protected $navSyncPort; // for populating the websockets template partial
|
||||
protected $patternTypes; // a list of pattern types that match the directory structure
|
||||
protected $patternPaths; // the paths to patterns for use with mustache partials
|
||||
protected $patternLineages; // the list of patterns that make up a particular pattern
|
||||
protected $patternTypesRegex; // the simple regex for the pattern types. used in getPath()
|
||||
protected $navItems; // the items for the nav. includes view all links
|
||||
protected $viewAllPaths; // the paths to the view all pages
|
||||
@ -177,11 +178,18 @@ class Builder {
|
||||
* @return {String} the final rendered pattern including the standard header and footer for a pattern
|
||||
*/
|
||||
private function generatePatternFile($f) {
|
||||
|
||||
$hr = file_get_contents(__DIR__.$this->sp."../_patternlab-files/pattern-header-footer/header.html");
|
||||
$rf = $this->renderPattern($f);
|
||||
$fr = file_get_contents(__DIR__.$this->sp."../_patternlab-files/pattern-header-footer/footer.html");
|
||||
$fr = str_replace("{{ patternPartial }}",$this->getPatternPartial($f),$fr);
|
||||
|
||||
// the footer isn't rendered as mustache but we have some variables there any way. find & replace.
|
||||
$pp = $this->getPatternPartial($f);
|
||||
$fr = str_replace("{{ patternPartial }}",$pp,$fr);
|
||||
$fr = str_replace("{{ lineage }}",json_encode($this->patternLineages[$pp]),$fr);
|
||||
|
||||
return $hr."\n".$rf."\n".$fr;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -469,8 +477,9 @@ class Builder {
|
||||
protected function gatherPatternPaths() {
|
||||
|
||||
// set-up vars
|
||||
$this->patternPaths = array();
|
||||
$this->patternTypes = array();
|
||||
$this->patternPaths = array();
|
||||
$this->patternTypes = array();
|
||||
$this->patternLineages = array();
|
||||
|
||||
// get the pattern types
|
||||
foreach(glob(__DIR__.$this->sp."/*",GLOB_ONLYDIR) as $patternType) {
|
||||
@ -482,7 +491,9 @@ class Builder {
|
||||
|
||||
// find the patterns for the types
|
||||
foreach($this->patternTypes as $patternType) {
|
||||
|
||||
$patternTypePaths = array();
|
||||
$patternTypeClean = $this->getPatternName($patternType, false);
|
||||
|
||||
// find pattern paths for pattern subtypes
|
||||
foreach(glob(__DIR__.$this->sp.$patternType."/*/*.mustache") as $filename) {
|
||||
@ -490,6 +501,7 @@ class Builder {
|
||||
$pattern = $this->getPatternName($matches[1], false);
|
||||
if (($pattern[0] != "_") && (!isset($patternTypePaths[$pattern]))) {
|
||||
$patternTypePaths[$pattern] = $this->getPath($filename);
|
||||
$this->patternLineages[$patternTypeClean."-".$pattern] = $this->getLineage($filename);
|
||||
}
|
||||
}
|
||||
|
||||
@ -499,10 +511,10 @@ class Builder {
|
||||
$pattern = $this->getPatternName($matches[1], false);
|
||||
if (($pattern[0] != "_") && (!isset($patternTypePaths[$pattern]))) {
|
||||
$patternTypePaths[$pattern] = $this->getPath($filename);
|
||||
$this->patternLineages[$patternTypeClean."-".$pattern] = $this->getLineage($filename);
|
||||
}
|
||||
}
|
||||
|
||||
$patternTypeClean = $this->getPatternName($patternType, false);
|
||||
$this->patternPaths[$patternTypeClean] = $patternTypePaths;
|
||||
|
||||
}
|
||||
@ -590,6 +602,19 @@ class Builder {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lineage for a given pattern by parsing it and matching mustache partials
|
||||
* @param {String} the filename for the pattern to be parsed
|
||||
*
|
||||
* @return {Array} a list of patterns
|
||||
*/
|
||||
protected function getLineage($filename) {
|
||||
$data = file_get_contents($filename);
|
||||
if (preg_match_all('/{{>([ ]+)?([A-Za-z0-9-]+)([ ]+)?}}/',$data,$matches)) {
|
||||
return $matches[2];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the directory path for a given pattern or json file by parsing the file path
|
||||
* @param {String} the filepath for a directory that contained the match
|
||||
|
@ -494,6 +494,9 @@ function receiveIframeMessage(event) {
|
||||
|
||||
}
|
||||
|
||||
// for testing purposes
|
||||
console.log(event.data.lineage);
|
||||
|
||||
// reset the defaults
|
||||
urlHandler.skipBack = false;
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
// alert the iframe parent that the pattern has loaded. for page follow.
|
||||
if (self != top) {
|
||||
var targetOrigin = (window.location.protocol == "file:") ? "*" : window.location.protocol+"//"+window.location.host;
|
||||
parent.postMessage( { "patternpartial": "{{ patternPartial }}", "path": window.location.toString() }, targetOrigin);
|
||||
parent.postMessage( { "patternpartial": "{{ patternPartial }}", "path": window.location.toString(), "lineage": {{ lineage }} }, targetOrigin);
|
||||
}
|
||||
|
||||
// if there are clicks on the iframe make sure the nav in the iframe parent closes
|
||||
|
Loading…
x
Reference in New Issue
Block a user