Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "fastboot", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Library for rendering Ember apps in node.js", | ||
@@ -41,3 +41,3 @@ "main": "src/index.js", | ||
"chai-as-promised": "^7.1.1", | ||
"ember-source": "2.16.2", | ||
"ember-source": "2.17.0", | ||
"express": "^4.15.4", | ||
@@ -44,0 +44,0 @@ "fs-promise": "^2.0.3", |
@@ -6,2 +6,5 @@ 'use strict'; | ||
const SHOEBOX_TAG_PATTERN = '<script type="fastboot/shoebox"'; | ||
const HTML_HEAD_REGEX = /^([\s\S]*<\/head>)([\s\S]*)/; | ||
/** | ||
@@ -50,2 +53,41 @@ * Represents the rendered result of visiting an Ember app at a particular URL. | ||
/** | ||
* Returns the HTML representation of the rendered route, inserted | ||
* into the application's `index.html`, split into chunks. | ||
* The first chunk contains the document's head, the second contains the body | ||
* until just before the shoebox tags (if there are any) and the last chunk | ||
* contains the shoebox tags and the closing `body` tag. If there are no | ||
* shoebox tags, there are only 2 chunks and the second one contains the | ||
* complete document body, including the closing `body` tag. | ||
* | ||
* @returns {Promise<Array<String>>} the application's DOM serialized to HTML, split into chunks | ||
*/ | ||
chunks() { | ||
return insertIntoIndexHTML(this._html, this._head, this._body, this._bodyAttributes).then((html) => { | ||
let docParts = html.match(HTML_HEAD_REGEX); | ||
if (!docParts || docParts.length === 1) { | ||
return [html]; | ||
} | ||
let head = docParts[1]; | ||
let body = docParts[2]; | ||
if (!head || !body) { | ||
throw new Error('Could not idenfity head and body of the document! Make sure the document is well formed.'); | ||
} | ||
let chunks = [head]; | ||
let bodyParts = body.split(SHOEBOX_TAG_PATTERN); | ||
let plainBody = bodyParts[0]; | ||
chunks.push(plainBody); | ||
let shoeboxes = bodyParts.splice(1); | ||
shoeboxes.forEach((shoebox) => { | ||
chunks.push(`${SHOEBOX_TAG_PATTERN}${shoebox}`); | ||
}); | ||
return chunks; | ||
}); | ||
} | ||
/** | ||
* Returns the serialized representation of DOM HEAD and DOM BODY | ||
@@ -52,0 +94,0 @@ * |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80802
975
17