浏览代码

Merge pull request #554 from ckeditor/t/553

Internal: Support building code snippets as dependencies of other snippets (e.g. to be used in an iframe). Closes #553.
Aleksander Nowodzinski 8 年之前
父节点
当前提交
a955285cd9
共有 1 个文件被更改,包括 15 次插入1 次删除
  1. 15 1
      scripts/docs/snippet-adapter/snippetadapter.js

+ 15 - 1
scripts/docs/snippet-adapter/snippetadapter.js

@@ -58,6 +58,19 @@ 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: {
@@ -65,7 +78,8 @@ module.exports = function snippetAdapter( data ) {
 						path.join( data.relativeOutputPath, data.snippetPath, 'snippet.js' )
 					],
 					css: cssFiles
-				}
+				},
+				dependencies: snippetConfig.dependencies
 			};
 		} );
 };