Skip to content

Commit 4e0ad4d

Browse files
committed
Support for configuring a default pattern in config.json
1 parent d7535dc commit 4e0ad4d

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

builder/patternlab.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,11 @@ var patternlab_engine = function (config) {
473473
var viewAllPathsPartialHtml = pattern_assembler.renderPattern(viewAllPathsTemplate, {'viewallpaths': JSON.stringify(patternlab.viewAllPaths)});
474474

475475
//render the patternlab template, with all partials
476-
var patternlabSiteHtml = pattern_assembler.renderPattern(patternlabSiteTemplate, {}, {
476+
debugger;
477+
478+
var patternlabSiteHtml = pattern_assembler.renderPattern(patternlabSiteTemplate, {
479+
defaultPattern: patternlab.config.defaultPattern || 'all'
480+
}, {
477481
'ishControls': ishControlsPartialHtml,
478482
'patternNav': patternNavPartialHtml,
479483
'patternPaths': patternPathsPartialHtml,

config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"templates",
2727
"pages"
2828
],
29+
"defaultPattern": "all",
2930
"ignored-extensions" : ["scss", "DS_Store", "less"],
3031
"ignored-directories" : ["scss"],
3132
"debug": false,

core/styleguide/js/styleguide.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,16 +469,18 @@
469469
}
470470

471471
// load the iframe source
472-
var patternName = "all";
472+
var patternName = window.defaultPattern || "all";
473473
var patternPath = "";
474-
var iFramePath = window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+"styleguide/html/styleguide.html";
474+
var iFramePath = window.location.protocol + "//" + window.location.host + window.location.pathname.replace("index.html","") + "styleguide/html/styleguide.html";
475+
476+
// if we were passed some url parameters, deal with it
475477
if ((oGetVars.p != undefined) || (oGetVars.pattern != undefined)) {
476478
patternName = (oGetVars.p != undefined) ? oGetVars.p : oGetVars.pattern;
477-
patternPath = urlHandler.getFileName(patternName);
478-
iFramePath = (patternPath != "") ? window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+patternPath : iFramePath;
479479
}
480480

481481
if (patternName != "all") {
482+
patternPath = urlHandler.getFileName(patternName);
483+
iFramePath = (patternPath != "") ? window.location.protocol + "//" + window.location.host + window.location.pathname.replace("index.html","") + patternPath : iFramePath;
482484
document.getElementById("title").innerHTML = "Pattern Lab - "+patternName;
483485
history.replaceState({ "pattern": patternName }, null, null);
484486
}

source/_patternlab-files/index.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<link rel="stylesheet" href="styleguide/css/vendor/prism.css" media="all" />
1111
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
1212
<script>window.jQuery || document.write('<script src="styleguide/js/vendor/jquery.js"><\/script>')</script>
13+
<script>window.defaultPattern = '{{defaultPattern}}';</script>
1314
</head>
1415
<body id="patternlab-body">>
1516
<!--Style Guide Header-->
@@ -21,7 +22,7 @@
2122
</div>
2223
</header>
2324
<!--End Style Guide Header-->
24-
25+
2526
<!-- Iframe -->
2627
<div id="sg-vp-wrap">
2728
<div id="sg-cover"></div>
@@ -91,4 +92,4 @@
9192
<script src="styleguide/js/pattern-finder.js"></script>
9293

9394
</body>
94-
</html>
95+
</html>

0 commit comments

Comments
 (0)