diff --git a/core/lib/PatternLab/Builder.php b/core/lib/PatternLab/Builder.php
index db916e6..4cc2726 100644
--- a/core/lib/PatternLab/Builder.php
+++ b/core/lib/PatternLab/Builder.php
@@ -157,15 +157,15 @@ class Builder {
}
$pattern = $this->mpl->render($f,$d);
+ $escaped = htmlentities($pattern);
if ($this->addPatternHF) {
$patternHead = $this->mv->render($this->patternHead,$d);
$patternFoot = $this->mv->render($this->patternFoot,$d);
- $patternFoot = str_replace("{% patternHTML %}",htmlentities($pattern),$patternFoot);
$pattern = $patternHead.$pattern.$patternFoot;
}
- return $pattern;
+ return array($pattern,$escaped);
}
@@ -246,16 +246,8 @@ class Builder {
// make sure this pattern should be rendered
if ($pathInfo["render"]) {
- $r = $this->generatePatternFile($pathInfo["patternSrcPath"].".mustache",$pathInfo["patternPartial"]);
-
- // if the pattern directory doesn't exist create it
- $path = $pathInfo["patternDestPath"];
- if (!is_dir(__DIR__.$this->pp.$path)) {
- mkdir(__DIR__.$this->pp.$path);
- file_put_contents(__DIR__.$this->pp.$path."/".$path.".html",$r);
- } else {
- file_put_contents(__DIR__.$this->pp.$path."/".$path.".html",$r);
- }
+ // get the rendered, escaped, and mustache pattern
+ $this->generatePatternFile($pathInfo["patternSrcPath"].".mustache",$pathInfo["patternPartial"],$pathInfo["patternDestPath"]);
}
@@ -266,26 +258,40 @@ class Builder {
}
/**
- * Generates a pattern with a header & footer
+ * Generates a pattern with a header & footer, the escaped version of a pattern, the msutache template, and the css if appropriate
* @param {String} the filename of the file to be rendered
* @param {String} the pattern partial
- *
- * @return {String} the final rendered pattern including the standard header and footer for a pattern
+ * @param {String} path where the files need to be written too
*/
- private function generatePatternFile($f,$p) {
+ private function generatePatternFile($f,$p,$path) {
- $rf = $this->renderPattern($f,$p);
+ // render the pattern and return it as well as the encoded version
+ list($rf,$e) = $this->renderPattern($f,$p);
- // the footer isn't rendered as mustache but we have some variables there any way. find & replace.
+ // the core footer isn't rendered as mustache but we have some variables there any way. find & replace.
$rf = str_replace("{% patternPartial %}",$p,$rf);
$rf = str_replace("{% lineage %}",json_encode($this->patternLineages[$p]),$rf);
$rf = str_replace("{% lineager %}",json_encode($this->patternLineagesR[$p]),$rf);
- if ($this->enableCSS && isset($this->patternCSS[$p])) {
- $rf = str_replace("{% patternCSS %}",$this->patternCSS[$p],$rf);
+ // figure out what to put in the css section
+ $c = $this->enableCSS && isset($this->patternCSS[$p]) ? "true" : "false";
+ $rf = str_replace("{% cssEnabled %}",$c,$rf);
+
+ // get the original mustache template
+ $m = htmlentities(file_get_contents(__DIR__.$this->sp.$f));
+
+ // if the pattern directory doesn't exist create it
+ if (!is_dir(__DIR__.$this->pp.$path)) {
+ mkdir(__DIR__.$this->pp.$path);
}
- return $rf;
+ // write out the various pattern files
+ file_put_contents(__DIR__.$this->pp.$path."/".$path.".html",$rf);
+ file_put_contents(__DIR__.$this->pp.$path."/".$path.".escaped.html",$e);
+ file_put_contents(__DIR__.$this->pp.$path."/".$path.".mustache",$m);
+ if ($this->enableCSS && isset($this->patternCSS[$p])) {
+ file_put_contents(__DIR__.$this->pp.$path."/".$path.".css",htmlentities($this->patternCSS[$p]));
+ }
}
@@ -799,8 +805,9 @@ class Builder {
// add patterns to $this->patternPartials
foreach ($patternSubtypeValues["patternSubtypeItems"] as $patternSubtypeItem) {
- $patternCodeRaw = $this->renderPattern($patternSubtypeItem["patternSrcPath"],$patternSubtypeItem["patternPartial"]);
- $patternCodeEncoded = htmlentities($patternCodeRaw);
+ $patternCode = $this->renderPattern($patternSubtypeItem["patternSrcPath"],$patternSubtypeItem["patternPartial"]);
+ $patternCodeRaw = $patternCode[0];
+ $patternCodeEncoded = $patternCode[1];
$patternLineageExists = (count($this->patternLineages[$patternSubtypeItem["patternPartial"]]) > 0) ? true : false;
$patternLineages = $this->patternLineages[$patternSubtypeItem["patternPartial"]];
diff --git a/core/templates/index.mustache b/core/templates/index.mustache
index 8c731ac..1953c48 100644
--- a/core/templates/index.mustache
+++ b/core/templates/index.mustache
@@ -15,7 +15,7 @@
-
+
@@ -39,8 +39,57 @@
-
-
+
+
+
+
{{> ipAddress }}
{{> patternPaths }}
diff --git a/core/templates/pattern-header-footer/footer-pattern.html b/core/templates/pattern-header-footer/footer-pattern.html
index 1a426c2..ab89469 100644
--- a/core/templates/pattern-header-footer/footer-pattern.html
+++ b/core/templates/pattern-header-footer/footer-pattern.html
@@ -4,13 +4,6 @@
var patternPartial = "{% patternPartial %}";
var lineage = {% lineage %};
var lineageR = {% lineager %};
-
-
-
-
-
\ No newline at end of file
diff --git a/core/templates/pattern-header-footer/footer.html b/core/templates/pattern-header-footer/footer.html
index 0c083cc..8fdc344 100644
--- a/core/templates/pattern-header-footer/footer.html
+++ b/core/templates/pattern-header-footer/footer.html
@@ -2,11 +2,22 @@
(function() {
if (self != top) {
var cb = '{{ cacheBuster}}';
- var js = ["styleguide/js/postmessage.js","data/annotations.js","styleguide/js/annotations-pattern.js","styleguide/js/code-pattern.js"]
+ var js = [{"src": "styleguide/js/postmessage.js" }, { "src": "data/annotations.js", "dep": [{ "src": "styleguide/js/annotations-pattern.js" }]},{ "src": "styleguide/js/code-pattern.js"}];
var s = document.getElementById('pl-js-insert-{{ cacheBuster }}');
for (var i = 0; i < js.length; i++) {
var c = document.createElement('script');
- c.src = '../../'+js[i]+'?'+cb;
+ c.src = '../../'+js[i].src+'?'+cb;
+ if (js[i].dep !== undefined) {
+ c.onload = function(dep) {
+ return function() {
+ for (var k = 0; k < dep.length; k++) {
+ var d = document.createElement('script');
+ d.src = '../../'+dep[k].src+'?'+cb;
+ s.parentNode.insertBefore(d,s);
+ }
+ }
+ }(js[i].dep);
+ }
s.parentNode.insertBefore(c,s);
}
}
diff --git a/public/styleguide/js/code-pattern.js b/public/styleguide/js/code-pattern.js
index e85d3d4..65756ed 100644
--- a/public/styleguide/js/code-pattern.js
+++ b/public/styleguide/js/code-pattern.js
@@ -50,7 +50,7 @@ var codePattern = {
if (codePattern.codeOverlayActive) {
var targetOrigin = (window.location.protocol == "file:") ? "*" : window.location.protocol+"//"+window.location.host;
- var obj = { "codeOverlay": "on", "lineage": lineage, "lineageR": lineageR, "html": document.getElementById("sg-pattern-html").textContent, "css": document.getElementById("sg-pattern-css").textContent };
+ var obj = { "codeOverlay": "on", "lineage": lineage, "lineageR": lineageR, "codePatternPartial": patternPartial, "cssEnabled": cssEnabled };
parent.postMessage(obj,targetOrigin);
} else if (codePattern.codeEmbeddedActive) {
diff --git a/public/styleguide/js/code-viewer.js b/public/styleguide/js/code-viewer.js
index e52db9e..915e2f0 100644
--- a/public/styleguide/js/code-viewer.js
+++ b/public/styleguide/js/code-viewer.js
@@ -9,6 +9,10 @@
var codeViewer = {
codeActive: false,
+ tabActive: "e",
+ encoded: "",
+ mustache: "",
+ css: "",
onReady: function() {
@@ -54,7 +58,7 @@ var codeViewer = {
codeContainerInit: function() {
if (document.getElementById("sg-code-container") === null) {
- $('').html('Close
This pattern contains the following patterns:
This pattern is included in the following patterns: