Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c8197b4

Browse files
matskomhevery
authored andcommitted
feat(ngdocs): external links to github, plunkr and jsfiddle available for code examples
1 parent b6e5972 commit c8197b4

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

docs/src/ngdoc.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Doc.prototype = {
105105
IS_URL = /^(https?:\/\/|ftps?:\/\/|mailto:|\.|\/)/,
106106
IS_ANGULAR = /^(api\/)?(angular|ng|AUTO)\./,
107107
IS_HASH = /^#/,
108-
parts = trim(text).split(/(<pre>[\s\S]*?<\/pre>|<doc:example(\S*).*?>[\s\S]*?<\/doc:example>|<example[^>]*>[\s\S]*?<\/example>)/),
108+
parts = trim(text).split(/(<pre.*?>[\s\S]*?<\/pre>|<doc:example(\S*).*?>[\s\S]*?<\/doc:example>|<example[^>]*>[\s\S]*?<\/example>)/),
109109
seq = 0,
110110
placeholderMap = {};
111111

@@ -191,9 +191,9 @@ Doc.prototype = {
191191

192192
return placeholder(example.toHtml());
193193
}).
194-
replace(/^<pre>([\s\S]*?)<\/pre>/mi, function(_, content){
194+
replace(/^<pre(.*?)>([\s\S]*?)<\/pre>/mi, function(_, attrs, content){
195195
return placeholder(
196-
'<pre class="prettyprint linenums">' +
196+
'<pre'+attrs+' class="prettyprint linenums">' +
197197
content.replace(/</g, '&lt;').replace(/>/g, '&gt;') +
198198
'</pre>');
199199
}).

docs/src/templates/css/docs.css

+19
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,22 @@ ul.events > li > h3 {
241241
.type-hint-number {
242242
background:rgb(189, 63, 66);
243243
}
244+
245+
.syntax-links {
246+
background:#eee;
247+
border:1px solid #ddd;
248+
text-align:right;
249+
padding:1em;
250+
border-bottom:0;
251+
border-top-left-radius:4px;
252+
border-top-right-radius:4px;
253+
}
254+
255+
.syntax-links a {
256+
margin-left:10px;
257+
}
258+
259+
.syntax-links + pre {
260+
border-top-left-radius:0;
261+
border-top-right-radius:0;
262+
}

src/bootstrap/bootstrap.js

+42
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,48 @@ directive.dropdownToggle =
4848
};
4949
}];
5050

51+
directive.syntax = function() {
52+
return {
53+
restrict: 'A',
54+
link: function(scope, element, attrs) {
55+
function makeLink(type, text, link, icon) {
56+
return '<a href="' + link + '" class="btn syntax-' + type + '" target="_blank" rel="nofollow">' +
57+
'<span class="' + icon + '"></span> ' + text +
58+
'</a>';
59+
};
60+
var html = '<nav class="syntax-links">';
61+
var types = {
62+
'github' : {
63+
text : 'View on Github',
64+
key : 'syntaxGithub',
65+
icon : 'icon-github'
66+
},
67+
'plunkr' : {
68+
text : 'View on Plunkr',
69+
key : 'syntaxPlunkr',
70+
icon : 'icon-arrow-down'
71+
},
72+
'jsfiddle' : {
73+
text : 'View on JSFiddle',
74+
key : 'syntaxFiddle',
75+
icon : 'icon-cloud'
76+
}
77+
};
78+
for(var type in types) {
79+
var data = types[type];
80+
var link = attrs[data.key];
81+
if(link) {
82+
html += makeLink(type, data.text, link, data.icon);
83+
}
84+
};
85+
html += '</nav>';
86+
var nav = angular.element(html);
87+
var node = element[0];
88+
var par = node.parentNode;
89+
par.insertBefore(nav[0], node);
90+
}
91+
}
92+
}
5193

5294
directive.tabbable = function() {
5395
return {

0 commit comments

Comments
 (0)