From 7c67b2fb6afbc18f3593c64a5f339f04f9003f3c Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Thu, 25 Oct 2012 20:57:15 +0530 Subject: [PATCH] feat(docs): add plunkr support Add option to edit source in Angular Docs in Plunkr in addition to JsFiddle --- docs/src/templates/js/docs.js | 58 ++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/docs/src/templates/js/docs.js b/docs/src/templates/js/docs.js index 2fd50e75ed5f..58be9df997f0 100644 --- a/docs/src/templates/js/docs.js +++ b/docs/src/templates/js/docs.js @@ -30,9 +30,16 @@ docsApp.directive.code = function() { docsApp.directive.sourceEdit = function(getEmbeddedTemplate) { return { - template: '\n', + template: '
' + + '' + + ' Edit' + + '' + + '', scope: true, - controller: function($scope, $attrs, openJsFiddle) { + controller: function($scope, $attrs, openJsFiddle, openPlunkr) { var sources = { module: $attrs.sourceEdit, deps: read($attrs.sourceEditDeps), @@ -45,7 +52,11 @@ docsApp.directive.sourceEdit = function(getEmbeddedTemplate) { $scope.fiddle = function(e) { e.stopPropagation(); openJsFiddle(sources); - } + }; + $scope.plunkr = function(e) { + e.stopPropagation(); + openPlunkr(sources); + }; } } @@ -145,8 +156,47 @@ docsApp.serviceFactory.formPostData = function($document) { }; }; +docsApp.serviceFactory.openPlunkr = function(templateMerge, formPostData, angularUrls) { + return function(content) { + var allFiles = [].concat(content.js, content.css, content.html); + var indexHtmlContent = '\n' + + '\n' + + ' \n' + + ' \n' + + '{{scriptDeps}}\n' + + ' \n' + + ' \n\n' + + '{{indexContents}}' + + '\n\n \n' + + '\n'; + var scriptDeps = ''; + angular.forEach(content.deps, function(file) { + if (file.name !== 'angular.js') { + scriptDeps += ' \n' + } + }); + indexProp = { + angularJSUrl: angularUrls['angular.js'], + scriptDeps: scriptDeps, + indexContents: content.html[0].content + }; + var postData = {}; + angular.forEach(allFiles, function(file, index) { + if (file.content && file.name != 'index.html') { + postData['files[' + file.name + ']'] = file.content; + } + }); + + postData['files[index.html]'] = templateMerge(indexHtmlContent, indexProp); + + postData.description = 'AngularJS Example Plunkr'; + + formPostData('http://plnkr.co/edit/?p=preview', postData); + }; +}; + +docsApp.serviceFactory.openJsFiddle = function(templateMerge, formPostData, angularUrls) { -docsApp.serviceFactory.openJsFiddle = function(templateMerge, getEmbeddedTemplate, formPostData, angularUrls) { var HTML = '
\n{{html:2}}
', CSS = ' \n' + '{{head:0}}