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

Commit 67ac18d

Browse files
committed
Merge branch 'dev' of https://github.com/pattern-lab/patternlab-php into dev
2 parents e443f95 + 81d5f58 commit 67ac18d

24 files changed

+1311
-67
lines changed

CHANGELOG

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

3+
PL-v0.6.0 (in progress)
4+
- ADD: a UI list of the current media query widths from the CSS
5+
- ADD: a pattern's "lineage" now displays in the UI under code view
6+
- ADD: annotations can be added to DOM elements of patterns
7+
- ADD: separate annotation views on the list view and pattern details views
8+
- ADD: generate() now "cleans" public/ before generating the site by deleting most everything
9+
- ADD: added support for the css rule saver library
10+
- ADD: can use a flag to generate the specific CSS that is used in a pattern. shows on code view when available.
11+
- ADD: mark-up for a pattern is now included in the UI under code view
12+
- FIX: can open the "raw" version of a pattern in a new window
13+
- FIX: frame resizing bar properly supports decimals
14+
- FIX: the checkboxes for the websocket-based features, page follow & auto-reload, now work
15+
- FIX: postmessage calls now centralized and refactored
16+
- FIX: units appear in the toolbar when using Hay! mode
17+
- FIX: patterns shouldn't be cached
18+
- THX: thanks to @benedfit for the MQ idea which he originally named "phases"
19+
- THX: thanks to @alienlebarge for the "clean public/" idea
20+
21+
PL-v0.3.6
22+
- FIX: added a delay to the watcher so the CPU doesn't get maxed
23+
- THX: thanks to martin berglund for the heads up
24+
325
PL-v0.3.5
426
- ADD: an explicit MIT license
527
- FIX: updated .gitignore so that it's more flexible

builder/builder.php

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

33
/*!
4-
* Pattern Lab Builder CLI - v0.3.5
4+
* Pattern Lab Builder CLI - v0.3.6
55
*
66
* Copyright (c) 2013 Dave Olsen, http://dmolsen.com
77
* Licensed under the MIT license
@@ -27,18 +27,24 @@
2727
require __DIR__."/lib/Mustache/Autoloader.php";
2828
Mustache_Autoloader::register();
2929

30+
// load css rule saver
31+
require __DIR__."/lib/css-rule-saver/css-rule-saver.php";
32+
3033
// make sure this script is being accessed from the command line
3134
if (php_sapi_name() == 'cli') {
3235

33-
$args = getopt("gw");
36+
$args = getopt("gwc");
3437

3538
if (isset($args["g"])) {
3639

3740
// initiate the g (generate) switch
3841

3942
// iterate over the source directory and generate the site
4043
$g = new Generatr();
41-
$g->generate();
44+
45+
// check to see if CSS for patterns should be parsed & outputted
46+
(isset($args["c"])) ? $g->generate(true) : $g->generate();
47+
4248
print "your site has been generated...\n";
4349

4450
} else if (isset($args["w"])) {

builder/lib/builder.lib.php

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

33
/*!
4-
* Pattern Lab Builder Class - v0.3.5
4+
* Pattern Lab Builder Class - v0.3.6
55
*
66
* Copyright (c) 2013 Dave Olsen, http://dmolsen.com
77
* Licensed under the MIT license
@@ -28,6 +28,9 @@ class Buildr {
2828
protected $patternTypesRegex; // the simple regex for the pattern types. used in getPath()
2929
protected $navItems; // the items for the nav. includes view all links
3030
protected $viewAllPaths; // the paths to the view all pages
31+
protected $enableCSS; // decide if we'll enable CSS parsing
32+
protected $patternCSS; // an array to hold the CSS generated for patterns
33+
protected $cssRuleSaver; // where css rule saver will be initialized
3134

3235
/**
3336
* When initializing the Builder class or the sub-classes make sure the base properties are configured
@@ -62,9 +65,16 @@ public function __construct() {
6265
// generate patternTypes as well as patternPaths
6366
$this->gatherPatternPaths();
6467

68+
// generate patternLineages
69+
$this->gatherLineages();
70+
6571
// get nav items
6672
$this->gatherNavItems();
6773

74+
// provide the default for enable CSS. performance hog so it should be run infrequently
75+
$this->enableCSS = false;
76+
$this->patternCSS = array();
77+
6878
}
6979

7080
/**
@@ -188,6 +198,15 @@ private function generatePatternFile($f) {
188198
$pp = $this->getPatternPartial($f);
189199
$fr = str_replace("{{ patternPartial }}",$pp,$fr);
190200
$fr = str_replace("{{ lineage }}",json_encode($this->patternLineages[$pp]),$fr);
201+
$fr = str_replace("{{ patternHTML }}",$rf,$fr);
202+
203+
// set-up the mark-up for CSS Rule Saver so it can figure out which rules to save
204+
if ($this->enableCSS) {
205+
$this->cssRuleSaver->loadHTML($rf,false);
206+
$patternCSS = $this->cssRuleSaver->saveRules();
207+
$this->patternCSS[$pp] = $patternCSS;
208+
$fr = str_replace("{{ patternCSS }}",$patternCSS,$fr);
209+
}
191210

192211
return $hr."\n".$rf."\n".$fr;
193212

@@ -343,7 +362,38 @@ protected function gatherData() {
343362

344363
}
345364

346-
}
365+
}
366+
367+
/**
368+
* Finds the Lineages for the patterns
369+
*
370+
* @return {Array} an array of patterns with their lineages
371+
*/
372+
protected function gatherLineages() {
373+
$this->patternLineages = array();
374+
375+
foreach($this->patternPaths as $patternType => $patterns) {
376+
377+
foreach ($patterns as $pattern => $filename) {
378+
379+
$patternLineage = array();
380+
$foundLineages = $this->getLineage($filename);
381+
382+
if (count($foundLineages) > 0) {
383+
foreach ($foundLineages as $lineage) {
384+
$patternBits = explode("-",$lineage,2); // BUG: this is making an assumption
385+
$path = str_replace("/","-",$this->patternPaths[$patternBits[0]][$patternBits[1]]);
386+
$patternLineage[] = array("lineagePattern" => $lineage, "lineagePath" => "../../patterns/".$path."/".$path.".html");
387+
}
388+
}
389+
390+
$this->patternLineages[$patternType."-".$pattern] = $patternLineage;
391+
392+
}
393+
394+
}
395+
396+
}
347397

348398
/**
349399
* Finds Media Queries in CSS files in the source/css/ dir
@@ -356,7 +406,7 @@ protected function gatherMQs() {
356406

357407
foreach(glob(__DIR__."/../../source/css/*.css") as $filename) {
358408
$data = file_get_contents($filename);
359-
preg_match_all("/(min|max)-width:( |)(([0-9]{1,5})(\.[0-9]{1,20}|)(px|em))/",$data,$matches);
409+
preg_match_all("/(min|max)-width:([ ]+)?(([0-9]{1,5})(\.[0-9]{1,20}|)(px|em))/",$data,$matches);
360410
foreach ($matches[3] as $match) {
361411
if (!in_array($match,$mqs)) {
362412
$mqs[] = $match;
@@ -498,13 +548,13 @@ protected function gatherNavItems() {
498548
*
499549
* @return {Array} populates $this->patternPaths
500550
* @return {Array} populates $this->patternTypes
551+
* @return {Array} populates $this->patternLineages
501552
*/
502553
protected function gatherPatternPaths() {
503554

504555
// set-up vars
505556
$this->patternPaths = array();
506557
$this->patternTypes = array();
507-
$this->patternLineages = array();
508558

509559
// get the pattern types
510560
foreach(glob(__DIR__.$this->sp."/*",GLOB_ONLYDIR) as $patternType) {
@@ -526,7 +576,6 @@ protected function gatherPatternPaths() {
526576
$pattern = $this->getPatternName($matches[1], false);
527577
if (($pattern[0] != "_") && (!isset($patternTypePaths[$pattern]))) {
528578
$patternTypePaths[$pattern] = $this->getPath($filename);
529-
$this->patternLineages[$patternTypeClean."-".$pattern] = $this->getLineage($filename);
530579
}
531580
}
532581

@@ -536,7 +585,6 @@ protected function gatherPatternPaths() {
536585
$pattern = $this->getPatternName($matches[1], false);
537586
if (($pattern[0] != "_") && (!isset($patternTypePaths[$pattern]))) {
538587
$patternTypePaths[$pattern] = $this->getPath($filename);
539-
$this->patternLineages[$patternTypeClean."-".$pattern] = $this->getLineage($filename);
540588
}
541589
}
542590

@@ -569,12 +617,26 @@ protected function gatherPartials() {
569617
if (file_exists(__DIR__."/".$this->sp.$path.".mustache")) {
570618

571619
// create the pattern name & link, render the partial, and stick it all into the pattern array
572-
$patternParts = explode("/",$path);
573-
$patternName = $this->getPatternName($patternParts[2]);
574-
$patternLink = str_replace("/","-",$path)."/".str_replace("/","-",$path).".html";
575-
$patternPartial = $this->renderPattern($path.".mustache");
576-
$p["partials"][] = array("patternName" => ucwords($patternName), "patternLink" => $patternLink, "patternPartialPath" => $patternType."-".$pattern, "patternPartial" => $patternPartial);
620+
$patternParts = explode("/",$path);
621+
$patternName = $this->getPatternName($patternParts[2]);
622+
$patternLink = str_replace("/","-",$path)."/".str_replace("/","-",$path).".html";
623+
$patternCode = $this->renderPattern($path.".mustache");
624+
$patternPartial = $this->getPatternPartial($path);
625+
$patternLineageExists = (count($this->patternLineages[$patternPartial]) > 0) ? true : false;
626+
$patternLineages = $this->patternLineages[$patternPartial];
627+
$patternCSSExists = $this->enableCSS;
628+
$patternCSS = ($this->enableCSS) ? $this->patternCSS[$patternPartial] : "";
577629

630+
$p["partials"][] = array("patternName" => ucwords($patternName),
631+
"patternLink" => $patternLink,
632+
"patternPartialPath" => $patternType."-".$pattern,
633+
"patternPartial" => $patternCode,
634+
"patternCSS" => $patternCSS,
635+
"patternLineageExists" => $patternLineageExists,
636+
"patternLineages" => $patternLineages,
637+
"patternCSSExists" => $patternCSSExists,
638+
"patternCSS" => $patternCSS
639+
);
578640
}
579641

580642
}
@@ -614,10 +676,25 @@ protected function gatherPartialsByMatch($patternType, $patternSubType) {
614676
if ($patternParts[2][0] != "_") {
615677

616678
// create the pattern name & link, render the partial, and stick it all into the pattern array
617-
$patternName = $this->getPatternName($patternParts[2]);
618-
$patternLink = str_replace("/","-",$path)."/".str_replace("/","-",$path).".html";
619-
$patternPartial = $this->renderPattern($path.".mustache");
620-
$p["partials"][] = array("patternName" => ucwords($patternName), "patternLink" => $patternLink, "patternPartialPath" => str_replace(" ","-",$patternTypeClean)."-".str_replace(" ","-",$patternName), "patternPartial" => $patternPartial);
679+
$patternName = $this->getPatternName($patternParts[2]);
680+
$patternLink = str_replace("/","-",$path)."/".str_replace("/","-",$path).".html";
681+
$patternCode = $this->renderPattern($path.".mustache");
682+
$patternPartial = $this->getPatternPartial($path);
683+
$patternLineages = $this->patternLineages[$patternPartial];
684+
$patternLineageExists = (count($patternLineages) > 0) ? true : false;
685+
$patternCSSExists = $this->enableCSS;
686+
$patternCSS = ($this->enableCSS) ? $this->patternCSS[$patternPartial] : "";
687+
688+
$p["partials"][] = array("patternName" => ucwords($patternName),
689+
"patternLink" => $patternLink,
690+
"patternPartialPath" => str_replace(" ","-",$patternTypeClean)."-".str_replace(" ","-",$patternName),
691+
"patternPartial" => $patternCode,
692+
"patternCSS" => $patternCSS,
693+
"patternLineageExists" => $patternLineageExists,
694+
"patternLineages" => $patternLineages,
695+
"patternCSSExists" => $patternCSSExists,
696+
"patternCSS" => $patternCSS
697+
);
621698

622699
}
623700

@@ -634,10 +711,11 @@ protected function gatherPartialsByMatch($patternType, $patternSubType) {
634711
* @return {Array} a list of patterns
635712
*/
636713
protected function getLineage($filename) {
637-
$data = file_get_contents($filename);
714+
$data = file_get_contents(__DIR__.$this->sp.$filename.".mustache");
638715
if (preg_match_all('/{{>([ ]+)?([A-Za-z0-9-]+)([ ]+)?}}/',$data,$matches)) {
639716
return $matches[2];
640717
}
718+
return array();
641719
}
642720

643721
/**
@@ -842,6 +920,19 @@ protected function ignoreDir($fileName) {
842920
return false;
843921
}
844922

923+
/**
924+
* Loads the CSS from source/css/ into CSS Rule Saver to be used for code view
925+
*/
926+
protected function initializeCSSRuleSaver() {
927+
928+
$this->cssRuleSaver = new cssRuleSaver;
929+
930+
foreach(glob(__DIR__."/../../source/css/*.css") as $filename) {
931+
$this->cssRuleSaver->loadCSS($filename);
932+
}
933+
934+
}
935+
845936
/**
846937
* Print out the data var. For debugging purposes
847938
*

builder/lib/css-rule-saver/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 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.

0 commit comments

Comments
 (0)