Skip to content

Commit 5b8df34

Browse files
Foxandxsswardbell
authored andcommitted
chore: add embedded plunkers functionality (angular#2194)
1 parent 460e207 commit 5b8df34

File tree

12 files changed

+431
-331
lines changed

12 files changed

+431
-331
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ www
2525
npm-debug*.log*
2626
*.plnkr.html
2727
plnkr.html
28+
*.eplnkr.html
29+
eplnkr.html
2830
*plnkr.no-link.html
2931
public/docs/*/latest/guide/cheatsheet.json
3032
protractor-results.txt

gulpfile.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ var STYLES_SOURCE_PATH = path.join(TOOLS_PATH, 'styles-builder/less');
4545

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

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

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

609611
gulp.task('build-dart-cheatsheet', [], function() {

public/_includes/_scripts-include.jade

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ script(src="//www.gstatic.com/feedback/api.js" type="text/javascript")
6464

6565
<!-- Twitter Widget -->
6666
script.
67-
(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");
67+
(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");

public/docs/ts/latest/guide/ngmodule.jade

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ a#bootstrap
131131
:marked
132132
The samples in this chapter demonstrate the dynamic bootstrapping approach.
133133

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

136136

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

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

611611
a#lazy-load
612612
.l-main-section
@@ -782,7 +782,7 @@ a#hero-module
782782

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

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

787787
a#shared-module
788788
.l-main-section

public/resources/css/main.scss

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
@import 'module/features';
5656
@import 'module/docs-landing';
5757
@import 'module/copy';
58+
@import 'module/embedded-plunker';
5859

5960
/*
6061
* PRINT STYLES
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
live-example iframe {
2+
height: 500px;
3+
}
20.4 KB
Loading

public/resources/js/directives/live-example.js

+40-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* app this directive is contained in.
66
*
77
* Usage:
8-
* <live-example [name="..."] [plnkr='...'] [noSource] [srcText="..."]>text</live-example>
8+
* <live-example [name="..."] [plnkr='...'] [noSource] [embedded] [srcText="..."]>text</live-example>
99
* Example:
1010
* <p>Run <live-example>Try the live example</live-example></p>.
1111
* // ~/resources/live-examples/{chapter}/ts/plnkr.html
@@ -15,6 +15,12 @@
1515
*
1616
* <p>Run <live-example plnkr="minimal"></live-example></p>.
1717
* // ~/resources/live-examples/{chapter}/ts/minimal.plnkr.html
18+
*
19+
* <live-example embedded></live-example>
20+
* // ~/resources/live-examples/{chapter}/ts/eplnkr.html
21+
*
22+
* <live-example embedded plnkr="minimal"></live-example>
23+
* // ~/resources/live-examples/{chapter}/ts/minimal.eplnkr.html
1824
*/
1925
angularIO.directive('liveExample', ['$location', function ($location) {
2026

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

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

35+
function embeddedTemplate(src, name) {
36+
return '<div ng-if="embeddedShow">' +
37+
'<iframe frameborder="0" width="100%" height="100%" name="' + name + '" src="' + src + '"></iframe>' +
38+
'</div>' +
39+
'<img ng-click="toggleEmbedded()" ng-if="!embeddedShow" src="/resources/images/plunker/placeholder.png" alt="plunker">';
40+
}
41+
2942
return {
3043
restrict: 'E',
31-
44+
scope: true,
3245
compile: function (tElement, attrs) {
3346
var text = tElement.text() || 'live example';
3447
var ex = attrs.name || NgIoUtil.getExampleName($location);
35-
var plnkr = '';
48+
var embedded = attrs.hasOwnProperty('embedded');
49+
var plnkr = embedded ? 'eplnkr' : 'plnkr';
3650
var href, template;
3751

3852
if (attrs.plnkr) {
39-
plnkr = attrs.plnkr + '.';
53+
plnkr = attrs.plnkr + '.' + plnkr;
4054
}
4155

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

49-
// Link to live example.
50-
var template = a(text, { href: href, target: '_blank' });
60+
if (attrs.hasOwnProperty('embedded') && !isForDart) {
61+
href = '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html'
62+
template = embeddedTemplate(href, plnkr);
63+
} else {
64+
var href = isForDart
65+
? 'http://angular-examples.github.io/' + ex
66+
: '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html'
67+
68+
// Link to live example.
69+
var template = a(text, { href: href, target: '_blank' });
5170

52-
// The hosted example and sources are in different locations for Dart.
53-
// Also show link to sources for Dart, unless noSource is specified.
54-
if (isForDart && !attrs.hasOwnProperty('nosource')) {
55-
var srcText = attrs.srcText || 'view source';
56-
var srcHref = 'http://github.com/angular-examples/' + ex;
57-
template = span(template + ' (' + a(srcText, { href: srcHref, target: '_blank' }) + ')');
71+
// The hosted example and sources are in different locations for Dart.
72+
// Also show link to sources for Dart, unless noSource is specified.
73+
if (isForDart && !attrs.hasOwnProperty('nosource')) {
74+
var srcText = attrs.srcText || 'view source';
75+
var srcHref = 'http://github.com/angular-examples/' + ex;
76+
template = span(template + ' (' + a(srcText, { href: srcHref, target: '_blank' }) + ')');
77+
}
5878
}
5979

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

6383
// RETURN ELEMENT
64-
return function (scope, element, attrs) { };
84+
return function (scope, element, attrs) {
85+
scope.toggleEmbedded = function() {
86+
scope.embeddedShow = !scope.embeddedShow;
87+
}
88+
};
6589
}
6690
};
6791
}]);

0 commit comments

Comments
 (0)