Skip to content

Commit 43a4ff4

Browse files
committed
Example snippets now have full html snippets
1 parent 6b8ed42 commit 43a4ff4

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

docs/doc_widgets.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
(function(){
2+
3+
var angularJsUrl;
4+
var scripts = document.getElementsByTagName("script");
5+
var filename = /(.*\/)angular([^\/]*)/;
6+
for(var j = 0; j < scripts.length; j++) {
7+
var src = scripts[j].src;
8+
if (src && src.match(filename)) {
9+
angularJsUrl = src;
10+
}
11+
}
12+
13+
214
var HTML_TEMPLATE =
3-
'<!DOCTYPE HTML>\n' +
15+
'<!doctype html>\n' +
416
'<html xmlns:ng="http://angularjs.org">\n' +
5-
' <head>\n' +
6-
' <title>Angular Example</title>\n' +
7-
' <script type="text/javascript"\n' +
8-
' src="../angular.js" ng:autobind></script>\n' +
9-
' </head>\n' +
10-
' <body>\n' +
17+
' <script type="text/javascript" ng:autobind\n' +
18+
' src="' + angularJsUrl + '"></script>\n' +
19+
' <body>\n' +
1120
'_HTML_SOURCE_\n' +
12-
' </body>\n' +
21+
' </body>\n' +
1322
'</html>';
1423

1524
angular.widget('doc:example', function(element){
@@ -20,16 +29,20 @@
2029
exampleSrc = example.text(),
2130
scenario = element.find('doc\\:scenario').eq(0);
2231

32+
var code = indent(exampleSrc);
2333
var tabs = angular.element(
2434
'<ul class="doc-example">' +
2535
'<li class="doc-example-heading"><h3>Source</h3></li>' +
26-
'<li class="doc-example-source" ng:non-bindable><pre class="brush: js; brush: xml;"></pre></li>' +
36+
'<li class="doc-example-source" ng:non-bindable>' +
37+
'<pre class="brush: js; html-script: true; highlight: [' +
38+
code.hilite + ']; toolbar: false;"></pre></li>' +
2739
'<li class="doc-example-heading"><h3>Live Preview</h3></li>' +
2840
'<li class="doc-example-live">' + exampleSrc +'</li>' +
2941
'<li class="doc-example-heading"><h3>Scenario Test</h3></li>' +
3042
'<li class="doc-example-scenario"><pre class="brush: js">' + scenario.text() + '</pre></li>' +
3143
'</ul>');
32-
tabs.find('li.doc-example-source > pre').text(exampleSrc);
44+
45+
tabs.find('li.doc-example-source > pre').text(HTML_TEMPLATE.replace('_HTML_SOURCE_', code.html));
3346

3447
element.html('');
3548
element.append(tabs);
@@ -46,4 +59,17 @@
4659
SyntaxHighlighter.highlight();
4760
};
4861
});
62+
63+
function indent(text) {
64+
var lines = text.split(/\n/);
65+
var lineNo = [];
66+
while (lines[0].match(/^\s*$/)) lines.shift();
67+
while (lines[lines.length - 1].match(/^\s*$/)) lines.pop();
68+
for ( var i = 0; i < lines.length; i++) {
69+
lines[i] = ' ' + lines[i];
70+
lineNo.push(6 + i);
71+
}
72+
return {html: lines.join('\n'), hilite: lineNo.join(',') };
73+
};
74+
4975
})();

0 commit comments

Comments
 (0)