Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building code snippets as dependencies of other snippets #554

Merged
merged 3 commits into from
Sep 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion scripts/docs/snippet-adapter/snippetadapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,28 @@ module.exports = function snippetAdapter( data ) {
cssFiles.unshift( path.join( data.relativeOutputPath, data.snippetPath, 'snippet.css' ) );
}

// If the snippet is a dependency of a parent snippet, append JS and CSS to HTML and save to disk.
if ( data.isDependency ) {
let htmlFile = fs.readFileSync( data.snippetSource.html ).toString();

if ( wasCSSGenerated ) {
htmlFile += '<link rel="stylesheet" href="snippet.css" type="text/css">';
}

htmlFile += '<script src="snippet.js"></script>';

fs.writeFileSync( path.join( outputPath, 'snippet.html' ), htmlFile );
}

return {
html: fs.readFileSync( data.snippetSource.html ),
assets: {
js: [
path.join( data.relativeOutputPath, data.snippetPath, 'snippet.js' )
],
css: cssFiles
}
},
dependencies: snippetConfig.dependencies
};
} );
};
Expand Down