-
Notifications
You must be signed in to change notification settings - Fork 39
split and rejoin styles in HtmlSplitter and HtmlRejoiner #40
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -311,8 +311,8 @@ class HtmlSplitter extends Transform { | |
for (let i = 0; i < scriptTags.length; i++) { | ||
let scriptTag = scriptTags[i]; | ||
let source = dom5.getTextContent(scriptTag); | ||
let typeAtribute = dom5.getAttribute(scriptTag, 'type'); | ||
let extension = typeAtribute && extensionsForType[typeAtribute] || 'js'; | ||
let typeAttribute = dom5.getAttribute(scriptTag, 'type'); | ||
let extension = typeAttribute && extensionsForType[typeAttribute] || 'js'; | ||
let childFilename = `${osPath.basename(filePath)}_script_${i}.${extension}`; | ||
let childPath = osPath.join(osPath.dirname(filePath), childFilename); | ||
scriptTag.childNodes = []; | ||
|
@@ -327,6 +327,24 @@ class HtmlSplitter extends Transform { | |
this.push(scriptFile); | ||
} | ||
|
||
for (let i = 0; i < styleTags.length; i++) { | ||
let styleTag = styleTags[i]; | ||
let source = dom5.getTextContent(styleTag); | ||
let extension = 'css'; | ||
let childFilename = `${osPath.basename(filePath)}_style_${i}.${extension}`; | ||
let childPath = osPath.join(osPath.dirname(filePath), childFilename); | ||
styleTag.childNodes = []; | ||
dom5.setAttribute(styleTag, 'src', childFilename); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will make a tag like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not saying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True If a @sorvell is there any valid transformation that externalizes a |
||
let styleFile = new File({ | ||
cwd: file.cwd, | ||
base: file.base, | ||
path: childPath, | ||
contents: new Buffer(source), | ||
}); | ||
this._project.addSplitPath(filePath, childPath); | ||
this.push(styleFile); | ||
} | ||
|
||
let splitContents = dom5.serialize(doc); | ||
let newFile = new File({ | ||
cwd: file.cwd, | ||
|
@@ -356,6 +374,11 @@ class HtmlRejoiner extends Transform { | |
pred.hasAttr('src') | ||
); | ||
|
||
static isExternalStyle = pred.AND( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be used on line 425 but is missing. Will change it to match a |
||
pred.hasTagName('style'), | ||
pred.hasAttr('src') | ||
); | ||
|
||
_project: PolymerProject; | ||
|
||
constructor(project: PolymerProject) { | ||
|
@@ -412,6 +435,17 @@ class HtmlRejoiner extends Transform { | |
} | ||
} | ||
|
||
for (let i = 0; i < styleTags.length; i++) { | ||
let styleTag = styleTags[i]; | ||
let srcAttribute = dom5.getAttribute(styleTag, 'src'); | ||
let stylePath = osPath.join(osPath.dirname(splitFile.path), srcAttribute); | ||
if (splitFile.parts.has(stylePath)) { | ||
let styleSource = splitFile.parts.get(stylePath); | ||
dom5.setTextContent(styleTag, styleSource); | ||
dom5.removeAttribute(styleTag, 'src'); | ||
} | ||
} | ||
|
||
let joinedContents = dom5.serialize(doc); | ||
|
||
return new File({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha, nice catch