From ac4a25cd258f0c46ba5766a04f65c1189ea4caa0 Mon Sep 17 00:00:00 2001 From: Scott Nath Date: Tue, 28 Jul 2015 11:52:53 -0400 Subject: [PATCH 1/2] iframe url with 'patterns' bugfix --- README.md | 9 ++++++++ builder/patternlab.js | 5 +++++ config.json | 3 ++- public/styleguide/js/postmessage.js | 22 ++++++++++++++++--- .../pattern-header-footer/footer.html | 3 ++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f17943092..e4cd09725 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,15 @@ As you can see, it's a much easier way of linking patterns to one another. Coupled with exported css (much easier to extract with existing tools like [grunt-contrib-copy](https://github.com/gruntjs/grunt-contrib-copy)), pattern export can help to maintain the relevancy of the design system by directly placing partials in a directory of your choosing. +##### baseurl + +If your instance of Pattern Lab lives in a subdirectory of your server, for instance on github pages (ex: yourusername.github.io/patterns-demo/), then add the baseurl here. The baseurl is everything after the hostname - ie: `patterns-demo` + +``` +"baseurl" : "/patterns-demo" +``` + +Default: blank ##### Verbose Mode `patternlab.json` is a file created for debugging purposes. Set `debug` to true in `.config.json` to see all the secrets. diff --git a/builder/patternlab.js b/builder/patternlab.js index d0f457f5c..ca7a08a9e 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -174,6 +174,11 @@ var entity_encoder = new he(); pattern.patternPartial = renderPattern(pattern.template, patternlab.data, patternlab.partials); } + // check for baseurl in config.json + if(patternlab.config.baseurl){ + pattern.baseurl = patternlab.config.baseurl; + } + //add footer info before writing var patternFooter = renderPattern(patternlab.footer, pattern); diff --git a/config.json b/config.json index c82acc58e..f0b2f6a74 100644 --- a/config.json +++ b/config.json @@ -32,5 +32,6 @@ "homepage-emergency" : "inprogress" }, "patternExportKeys": [], - "patternExportDirectory": "./pattern_exports/" + "patternExportDirectory": "./pattern_exports/", + "baseurl" : "" } diff --git a/public/styleguide/js/postmessage.js b/public/styleguide/js/postmessage.js index f5d65321b..76e482d3f 100644 --- a/public/styleguide/js/postmessage.js +++ b/public/styleguide/js/postmessage.js @@ -86,10 +86,26 @@ function receiveIframeMessage(event) { if (data.path !== undefined) { if (patternPartial !== "") { - + + if(baseurl){ + // create main site url + var siteurl = window.location.protocol+"//"+window.location.host; + // add a trailing slash if it doesn't exist + siteurl = siteurl.replace(/\/?$/, '/'); + // remove a begining slash for baseurl if it exists + baseurl = baseurl.replace(/^\//, ''); + // connect baseurl to siteurl + siteurl = siteurl + baseurl; + // add a trailing slash if it doesn't exist + siteurl = siteurl.replace(/\/?$/, '/'); + // build our final path + path = siteurl+data.path+'?'+Date.now(); + } else { // handle patterns and the view all page - var re = /patterns\/(.*)$/; - path = window.location.protocol+"//"+window.location.host+window.location.pathname.replace(re,'')+data.path+'?'+Date.now(); + var re = /patterns\/(.*)$/; + path = window.location.protocol+"//"+window.location.host+window.location.pathname.replace(re,'')+data.path+'?'+Date.now(); + } + window.location.replace(path); } else { diff --git a/source/_patternlab-files/pattern-header-footer/footer.html b/source/_patternlab-files/pattern-header-footer/footer.html index f66f45b92..2234cfd9f 100644 --- a/source/_patternlab-files/pattern-header-footer/footer.html +++ b/source/_patternlab-files/pattern-header-footer/footer.html @@ -11,7 +11,8 @@ var patternPartial = "{{ patternGroup }}-{{ patternName }}"; var lineage = [{{{ lineage }}}]; var lineageR = [{{{ lineageR }}}]; - var patternState = "{{patternState}}" + var patternState = "{{patternState}}"; + var baseurl = "{{{baseurl}}}"; var cssEnabled = false; //TODO From 977983cb50cc861c923442798dddad3bbfa36152 Mon Sep 17 00:00:00 2001 From: Scott Nath Date: Tue, 28 Jul 2015 12:47:58 -0400 Subject: [PATCH 2/2] view all pages include baseurl now --- builder/patternlab.js | 9 +++++++-- source/_patternlab-files/styleguide.mustache | 3 ++- source/_patternlab-files/viewall.mustache | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/builder/patternlab.js b/builder/patternlab.js index ca7a08a9e..13df6730a 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -204,13 +204,18 @@ var entity_encoder = new he(); patternlab.patternPaths = {}; patternlab.viewAllPaths = {}; + var baseurl; + // check for baseurl in config.json + if(patternlab.config.baseurl){ + baseurl = patternlab.config.baseurl; + } //find mediaQueries var media_hunter = new mh(); media_hunter.find_media_queries(patternlab); //build the styleguide var styleguideTemplate = fs.readFileSync('./source/_patternlab-files/styleguide.mustache', 'utf8'); - var styleguideHtml = renderPattern(styleguideTemplate, {partials: patternlab.patterns}); + var styleguideHtml = renderPattern(styleguideTemplate, {partials: patternlab.patterns, baseurl: baseurl}); fs.outputFileSync('./public/styleguide/html/styleguide.html', styleguideHtml); //build the viewall pages @@ -235,7 +240,7 @@ var entity_encoder = new he(); } var viewAllTemplate = fs.readFileSync('./source/_patternlab-files/viewall.mustache', 'utf8'); - var viewAllHtml = renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial}); + var viewAllHtml = renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial, baseurl: baseurl}); fs.outputFileSync('./public/patterns/' + pattern.flatPatternPath + '/index.html', viewAllHtml); } } diff --git a/source/_patternlab-files/styleguide.mustache b/source/_patternlab-files/styleguide.mustache index 81e7e55f9..e4a9e5479 100644 --- a/source/_patternlab-files/styleguide.mustache +++ b/source/_patternlab-files/styleguide.mustache @@ -53,9 +53,10 @@ diff --git a/source/_patternlab-files/viewall.mustache b/source/_patternlab-files/viewall.mustache index 32db975f2..a0c4805be 100644 --- a/source/_patternlab-files/viewall.mustache +++ b/source/_patternlab-files/viewall.mustache @@ -53,9 +53,10 @@