Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

chore: add embedded plunkers functionality #2194

Merged
merged 1 commit into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ www
npm-debug*.log*
*.plnkr.html
plnkr.html
*.eplnkr.html
eplnkr.html
*plnkr.no-link.html
public/docs/*/latest/guide/cheatsheet.json
protractor-results.txt
Expand Down
6 changes: 4 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ var STYLES_SOURCE_PATH = path.join(TOOLS_PATH, 'styles-builder/less');

var docShredder = require(path.resolve(TOOLS_PATH, 'doc-shredder/doc-shredder'));
var exampleZipper = require(path.resolve(TOOLS_PATH, '_example-zipper/exampleZipper'));
var plunkerBuilder = require(path.resolve(TOOLS_PATH, 'plunker-builder/plunkerBuilder'));
var regularPlunker = require(path.resolve(TOOLS_PATH, 'plunker-builder/regularPlunker'));
var embeddedPlunker = require(path.resolve(TOOLS_PATH, 'plunker-builder/embeddedPlunker'));
var fsUtils = require(path.resolve(TOOLS_PATH, 'fs-utils/fsUtils'));

const isSilent = !!argv.silent;
Expand Down Expand Up @@ -603,7 +604,8 @@ gulp.task('build-dart-api-docs', ['_shred-api-examples', 'dartdoc'], function()
});

gulp.task('build-plunkers', ['_copy-example-boilerplate'], function() {
return plunkerBuilder.buildPlunkers(EXAMPLES_PATH, LIVE_EXAMPLES_PATH, { errFn: gutil.log, build: argv.build });
regularPlunker.buildPlunkers(EXAMPLES_PATH, LIVE_EXAMPLES_PATH, { errFn: gutil.log, build: argv.build });
return embeddedPlunker.buildPlunkers(EXAMPLES_PATH, LIVE_EXAMPLES_PATH, { errFn: gutil.log, build: argv.build });
});

gulp.task('build-dart-cheatsheet', [], function() {
Expand Down
2 changes: 1 addition & 1 deletion public/_includes/_scripts-include.jade
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ script(src="//www.gstatic.com/feedback/api.js" type="text/javascript")

<!-- Twitter Widget -->
script.
(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}})(document,"script","twitter-wjs");
(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}})(document,"script","twitter-wjs");
6 changes: 3 additions & 3 deletions public/docs/ts/latest/guide/ngmodule.jade
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ a#bootstrap
:marked
The samples in this chapter demonstrate the dynamic bootstrapping approach.

<live-example plnkr="minimal.0">Try the live example.</live-example>
<live-example embedded plnkr="minimal.0">Try the live example.</live-example>


### Static bootstrapping with the Ahead-Of-Time (AOT) compiler
Expand Down Expand Up @@ -606,7 +606,7 @@ a#feature-modules
* No `ContactService` provider
* No `HighlightDirective` conflict

<live-example plnkr="contact.2">Try the live example of version 2.</live-example>
<live-example embedded plnkr="contact.2">Try the live example.</live-example>

a#lazy-load
.l-main-section
Expand Down Expand Up @@ -782,7 +782,7 @@ a#hero-module

The `CrisisModule` is much the same. There's nothing more to say that's new.

<live-example plnkr="pre-shared.3">Try the live example.</live-example>
<live-example embedded plnkr="pre-shared.3">Try the live example.</live-example>

a#shared-module
.l-main-section
Expand Down
1 change: 1 addition & 0 deletions public/resources/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
@import 'module/features';
@import 'module/docs-landing';
@import 'module/copy';
@import 'module/embedded-plunker';

/*
* PRINT STYLES
Expand Down
3 changes: 3 additions & 0 deletions public/resources/css/module/_embedded-plunker.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
live-example iframe {
height: 500px;
}
Binary file added public/resources/images/plunker/placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 40 additions & 16 deletions public/resources/js/directives/live-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* app this directive is contained in.
*
* Usage:
* <live-example [name="..."] [plnkr='...'] [noSource] [srcText="..."]>text</live-example>
* <live-example [name="..."] [plnkr='...'] [noSource] [embedded] [srcText="..."]>text</live-example>
* Example:
* <p>Run <live-example>Try the live example</live-example></p>.
* // ~/resources/live-examples/{chapter}/ts/plnkr.html
Expand All @@ -15,6 +15,12 @@
*
* <p>Run <live-example plnkr="minimal"></live-example></p>.
* // ~/resources/live-examples/{chapter}/ts/minimal.plnkr.html
*
* <live-example embedded></live-example>
* // ~/resources/live-examples/{chapter}/ts/eplnkr.html
*
* <live-example embedded plnkr="minimal"></live-example>
* // ~/resources/live-examples/{chapter}/ts/minimal.eplnkr.html
*/
angularIO.directive('liveExample', ['$location', function ($location) {

Expand All @@ -26,42 +32,60 @@ angularIO.directive('liveExample', ['$location', function ($location) {

function span(text) { return '<span>' + text + '</span>'; }

function embeddedTemplate(src, name) {
return '<div ng-if="embeddedShow">' +
'<iframe frameborder="0" width="100%" height="100%" name="' + name + '" src="' + src + '"></iframe>' +
'</div>' +
'<img ng-click="toggleEmbedded()" ng-if="!embeddedShow" src="/resources/images/plunker/placeholder.png" alt="plunker">';
}

return {
restrict: 'E',

scope: true,
compile: function (tElement, attrs) {
var text = tElement.text() || 'live example';
var ex = attrs.name || NgIoUtil.getExampleName($location);
var plnkr = '';
var embedded = attrs.hasOwnProperty('embedded');
var plnkr = embedded ? 'eplnkr' : 'plnkr';
var href, template;

if (attrs.plnkr) {
plnkr = attrs.plnkr + '.';
plnkr = attrs.plnkr + '.' + plnkr;
}

var isForDart = attrs.lang === 'dart' || NgIoUtil.isDoc($location, 'dart');
var isForJs = attrs.lang === 'js' || NgIoUtil.isDoc($location, 'js');
var exLang = isForDart ? 'dart' : isForJs ? 'js' : 'ts';
var href = isForDart
? 'http://angular-examples.github.io/' + ex
: '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + 'plnkr.html';

// Link to live example.
var template = a(text, { href: href, target: '_blank' });
if (attrs.hasOwnProperty('embedded') && !isForDart) {
href = '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html'
template = embeddedTemplate(href, plnkr);
} else {
var href = isForDart
? 'http://angular-examples.github.io/' + ex
: '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html'

// Link to live example.
var template = a(text, { href: href, target: '_blank' });

// The hosted example and sources are in different locations for Dart.
// Also show link to sources for Dart, unless noSource is specified.
if (isForDart && !attrs.hasOwnProperty('nosource')) {
var srcText = attrs.srcText || 'view source';
var srcHref = 'http://github.com/angular-examples/' + ex;
template = span(template + ' (' + a(srcText, { href: srcHref, target: '_blank' }) + ')');
// The hosted example and sources are in different locations for Dart.
// Also show link to sources for Dart, unless noSource is specified.
if (isForDart && !attrs.hasOwnProperty('nosource')) {
var srcText = attrs.srcText || 'view source';
var srcHref = 'http://github.com/angular-examples/' + ex;
template = span(template + ' (' + a(srcText, { href: srcHref, target: '_blank' }) + ')');
}
}

// UPDATE ELEMENT WITH NEW TEMPLATE
tElement.html(template);

// RETURN ELEMENT
return function (scope, element, attrs) { };
return function (scope, element, attrs) {
scope.toggleEmbedded = function() {
scope.embeddedShow = !scope.embeddedShow;
}
};
}
};
}]);
Loading