Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Commit c770365

Browse files
committed
Merge branch 'dev' of https://github.com/pattern-lab/patternlab-php into dev
2 parents 4bbcf3d + 7888de3 commit c770365

File tree

23 files changed

+570
-55
lines changed

23 files changed

+570
-55
lines changed

.gitignore

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
.DS_Store
2-
public/index.html
3-
public/styleguide.html
4-
public/styleguide/html/styleguide.html
5-
public/css/*
6-
public/fonts/*
7-
public/js/*
8-
public/images/*
9-
public/patterns/*
2+
public/*
3+
!public/listeners/*
4+
!public/styleguide/*
5+
!public/patterns/**/*
6+
!public/data/*.js
107
config.ini
118
latest-change.txt
12-
/public/styleguide/js/styleguide-ck.js
13-
/public/listeners/synclisteners-ck.js
14-
/public/styleguide/js/data-saver-ck.js
15-
/public/styleguide/js/url-handler-ck.js
16-
/public/styleguide/js/annotations-viewer-ck.js
9+
*-ck.js

CHANGELOG

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.
22

3+
PL-v0.3.5
4+
- ADD: an explicit MIT license
5+
- FIX: updated .gitignore so that it's more flexible
6+
- THX: thanks to @alienlebarge for the .gitignore fix
7+
8+
PL-v0.3.4
9+
- FIX: Generator class renamed because it's a reserved name in PHP 5.5
10+
- THX: thanks to @faustgertz for the heads up
11+
312
PL-v0.3.3
413
- FIX: links created with {{ link.pattern }} now have the correct path
514
- FIX: links within a pattern now properly update the history

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 Brad Frost, http://bradfrostweb.com & Dave Olsen, http://dmolsen.com
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

builder/builder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*!
4-
* Pattern Lab Builder CLI - v0.3.3
4+
* Pattern Lab Builder CLI - v0.3.5
55
*
66
* Copyright (c) 2013 Dave Olsen, http://dmolsen.com
77
* Licensed under the MIT license
@@ -36,7 +36,7 @@
3636
// initiate the g (generate) switch
3737

3838
// iterate over the source directory and generate the site
39-
$g = new Generator();
39+
$g = new Generatr();
4040
$g->generate();
4141
print "your site has been generated...\n";
4242

@@ -45,12 +45,12 @@
4545
// initiate the w (watch) switch
4646

4747
// iterate over the source directory and generate the site
48-
$g = new Generator();
48+
$g = new Generatr();
4949
$g->generate();
5050
print "your site has been generated...\n";
5151

5252
// watch the source directory and regenerate any changed files
53-
$w = new Watcher();
53+
$w = new Watchr();
5454
print "watching your site for changes...\n";
5555
$w->watch();
5656

builder/lib/builder.lib.php

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*!
4-
* Pattern Lab Builder Class - v0.3.3
4+
* Pattern Lab Builder Class - v0.3.5
55
*
66
* Copyright (c) 2013 Dave Olsen, http://dmolsen.com
77
* Licensed under the MIT license
@@ -10,7 +10,7 @@
1010
*
1111
*/
1212

13-
class Builder {
13+
class Buildr {
1414

1515
// i was lazy when i started this project & kept (mainly) to two letter vars. sorry.
1616
protected $mpl; // mustache pattern loader instance
@@ -24,6 +24,7 @@ class Builder {
2424
protected $navSyncPort; // for populating the websockets template partial
2525
protected $patternTypes; // a list of pattern types that match the directory structure
2626
protected $patternPaths; // the paths to patterns for use with mustache partials
27+
protected $patternLineages; // the list of patterns that make up a particular pattern
2728
protected $patternTypesRegex; // the simple regex for the pattern types. used in getPath()
2829
protected $navItems; // the items for the nav. includes view all links
2930
protected $viewAllPaths; // the paths to the view all pages
@@ -51,7 +52,7 @@ public function __construct() {
5152
// if the variables are array-like make sure the properties are validated/trimmed/lowercased before saving
5253
if (($key == "ie") || ($key == "id")) {
5354
$values = explode(",",$value);
54-
array_walk($values,'Builder::trim');
55+
array_walk($values,'Buildr::trim');
5556
$this->$key = $values;
5657
} else {
5758
$this->$key = $value;
@@ -122,12 +123,13 @@ protected function generateMainPages() {
122123
$this->navItems['navsyncport'] = $this->navSyncPort;
123124
$this->navItems['patternpaths'] = json_encode($this->patternPaths);
124125
$this->navItems['viewallpaths'] = json_encode($this->viewAllPaths);
126+
$this->navItems['mqs'] = $this->gatherMQs();
125127

126128
// grab the partials into a data object for the style guide
127129
$sd = $this->gatherPartials();
128130

129131
// sort partials by patternLink
130-
usort($sd['partials'], "Builder::sortPartials");
132+
usort($sd['partials'], "Buildr::sortPartials");
131133

132134
// render the "view all" pages
133135
$this->generateViewAllPages();
@@ -177,11 +179,18 @@ protected function generatePatterns() {
177179
* @return {String} the final rendered pattern including the standard header and footer for a pattern
178180
*/
179181
private function generatePatternFile($f) {
182+
180183
$hr = file_get_contents(__DIR__.$this->sp."../_patternlab-files/pattern-header-footer/header.html");
181184
$rf = $this->renderPattern($f);
182185
$fr = file_get_contents(__DIR__.$this->sp."../_patternlab-files/pattern-header-footer/footer.html");
183-
$fr = str_replace("{{ patternPartial }}",$this->getPatternPartial($f),$fr);
186+
187+
// the footer isn't rendered as mustache but we have some variables there any way. find & replace.
188+
$pp = $this->getPatternPartial($f);
189+
$fr = str_replace("{{ patternPartial }}",$pp,$fr);
190+
$fr = str_replace("{{ lineage }}",json_encode($this->patternLineages[$pp]),$fr);
191+
184192
return $hr."\n".$rf."\n".$fr;
193+
185194
}
186195

187196
/**
@@ -246,7 +255,7 @@ protected function generateViewAllPages() {
246255
}
247256

248257
/**
249-
* Gather data from source/_data/data.json, source/_data/listitems.json, and pattern-specific json files
258+
* Gather data from source/_data/_data.json, source/_data/_listitems.json, and pattern-specific json files
250259
*
251260
* Reserved attributes:
252261
* - $this->d->listItems : listItems from listitems.json, duplicated into separate arrays for $this->d->listItems->one, $this->d->listItems->two, $this->d->listItems->three... etc.
@@ -258,14 +267,14 @@ protected function generateViewAllPages() {
258267
protected function gatherData() {
259268

260269
// gather the data from the main source data.json
261-
if (file_exists(__DIR__."/../../source/_data/data.json")) {
262-
$this->d = (object) array_merge(array(), (array) json_decode(file_get_contents(__DIR__."/../../source/_data/data.json")));
270+
if (file_exists(__DIR__."/../../source/_data/_data.json")) {
271+
$this->d = (object) array_merge(array(), (array) json_decode(file_get_contents(__DIR__."/../../source/_data/_data.json")));
263272
}
264273

265274
// add list item data, makes 'listItems' a reserved word
266-
if (file_exists(__DIR__."/../../source/_data/listitems.json")) {
275+
if (file_exists(__DIR__."/../../source/_data/_listitems.json")) {
267276

268-
$listItems = (array) json_decode(file_get_contents(__DIR__."/../../source/_data/listitems.json"));
277+
$listItems = (array) json_decode(file_get_contents(__DIR__."/../../source/_data/_listitems.json"));
269278
$numbers = array("one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve");
270279

271280
$i = 0;
@@ -336,6 +345,30 @@ protected function gatherData() {
336345

337346
}
338347

348+
/**
349+
* Finds Media Queries in CSS files in the source/css/ dir
350+
*
351+
* @return {Array} an array of the appropriate MQs
352+
*/
353+
protected function gatherMQs() {
354+
355+
$mqs = array();
356+
357+
foreach(glob(__DIR__."/../../source/css/*.css") as $filename) {
358+
$data = file_get_contents($filename);
359+
preg_match_all("/(min|max)-width:( |)(([0-9]{1,5})(\.[0-9]{1,20}|)(px|em))/",$data,$matches);
360+
foreach ($matches[3] as $match) {
361+
if (!in_array($match,$mqs)) {
362+
$mqs[] = $match;
363+
}
364+
}
365+
}
366+
367+
sort($mqs);
368+
return $mqs;
369+
370+
}
371+
339372
/**
340373
* Gathers the partials for the nav drop down in Pattern Lab
341374
*
@@ -469,8 +502,9 @@ protected function gatherNavItems() {
469502
protected function gatherPatternPaths() {
470503

471504
// set-up vars
472-
$this->patternPaths = array();
473-
$this->patternTypes = array();
505+
$this->patternPaths = array();
506+
$this->patternTypes = array();
507+
$this->patternLineages = array();
474508

475509
// get the pattern types
476510
foreach(glob(__DIR__.$this->sp."/*",GLOB_ONLYDIR) as $patternType) {
@@ -482,14 +516,17 @@ protected function gatherPatternPaths() {
482516

483517
// find the patterns for the types
484518
foreach($this->patternTypes as $patternType) {
519+
485520
$patternTypePaths = array();
521+
$patternTypeClean = $this->getPatternName($patternType, false);
486522

487523
// find pattern paths for pattern subtypes
488524
foreach(glob(__DIR__.$this->sp.$patternType."/*/*.mustache") as $filename) {
489525
preg_match('/\/([A-z0-9-_]{1,})\.mustache$/',$filename,$matches);
490526
$pattern = $this->getPatternName($matches[1], false);
491527
if (($pattern[0] != "_") && (!isset($patternTypePaths[$pattern]))) {
492528
$patternTypePaths[$pattern] = $this->getPath($filename);
529+
$this->patternLineages[$patternTypeClean."-".$pattern] = $this->getLineage($filename);
493530
}
494531
}
495532

@@ -499,10 +536,10 @@ protected function gatherPatternPaths() {
499536
$pattern = $this->getPatternName($matches[1], false);
500537
if (($pattern[0] != "_") && (!isset($patternTypePaths[$pattern]))) {
501538
$patternTypePaths[$pattern] = $this->getPath($filename);
539+
$this->patternLineages[$patternTypeClean."-".$pattern] = $this->getLineage($filename);
502540
}
503541
}
504542

505-
$patternTypeClean = $this->getPatternName($patternType, false);
506543
$this->patternPaths[$patternTypeClean] = $patternTypePaths;
507544

508545
}
@@ -590,6 +627,19 @@ protected function gatherPartialsByMatch($patternType, $patternSubType) {
590627

591628
}
592629

630+
/**
631+
* Get the lineage for a given pattern by parsing it and matching mustache partials
632+
* @param {String} the filename for the pattern to be parsed
633+
*
634+
* @return {Array} a list of patterns
635+
*/
636+
protected function getLineage($filename) {
637+
$data = file_get_contents($filename);
638+
if (preg_match_all('/{{>([ ]+)?([A-Za-z0-9-]+)([ ]+)?}}/',$data,$matches)) {
639+
return $matches[2];
640+
}
641+
}
642+
593643
/**
594644
* Get the directory path for a given pattern or json file by parsing the file path
595645
* @param {String} the filepath for a directory that contained the match
@@ -693,9 +743,11 @@ protected function moveFile($s,$p) {
693743
* Moves static files that aren't directly related to Pattern Lab
694744
* @param {String} file name to be moved
695745
* @param {String} copy for the message to be printed out
746+
* @param {String} part of the file name to be found for replacement
747+
* @param {String} the replacement
696748
*/
697-
protected function moveStaticFile($fileName,$copy = "") {
698-
$this->moveFile($fileName,$fileName);
749+
protected function moveStaticFile($fileName,$copy = "", $find = "", $replace = "") {
750+
$this->moveFile($fileName,str_replace($find, $replace, $fileName));
699751
$this->updateChangeTime();
700752
if ($copy != "") {
701753
print $fileName." ".$copy."...\n";

builder/lib/generator.lib.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*!
4-
* Pattern Lab Generator Class - v0.3.3
4+
* Pattern Lab Generator Class - v0.3.5
55
*
66
* Copyright (c) 2013 Dave Olsen, http://dmolsen.com
77
* Licensed under the MIT license
@@ -11,7 +11,7 @@
1111
*
1212
*/
1313

14-
class Generator extends Builder {
14+
class Generatr extends Buildr {
1515

1616
/**
1717
* Use the Builder __construct to gather the config variables
@@ -37,6 +37,21 @@ public function generate() {
3737
// render out the index and style guide
3838
$this->generateMainPages();
3939

40+
// iterate over the data files and regenerate the entire site if they've changed
41+
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__."/../../source/_data/"), RecursiveIteratorIterator::SELF_FIRST);
42+
43+
// make sure dots are skipped
44+
$objects->setFlags(FilesystemIterator::SKIP_DOTS);
45+
46+
foreach($objects as $name => $object) {
47+
48+
$fileName = str_replace(__DIR__."/../../source/_data".DIRECTORY_SEPARATOR,"",$name);
49+
if (($fileName[0] != "_") && $object->isFile()) {
50+
$this->moveStaticFile("_data/".$fileName,"","_data","data");
51+
}
52+
53+
}
54+
4055
// iterate over all of the other files in the source directory and move them if their modified time has changed
4156
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__."/../../source/"), RecursiveIteratorIterator::SELF_FIRST);
4257

0 commit comments

Comments
 (0)