From c2f2587a79aeb77aad66f081cf924a79348a698e Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 19 Jan 2011 15:42:11 -0800 Subject: fixed example rendering, add tests for it. --- docs/angular.formatter.ngdoc | 16 +++++++-------- docs/angular.service.ngdoc | 10 ++++----- docs/angular.validator.ngdoc | 18 ++++++++-------- docs/angular.widget.ngdoc | 18 ++++++++-------- docs/service.template | 2 +- docs/spec/domSpec.js | 24 ++++++++++++++++++++++ docs/spec/ngdocSpec.js | 10 +++++++++ docs/spec/writerSpec.js | 8 ++++---- docs/src/gen-docs.js | 2 +- docs/src/ngdoc.js | 5 +++-- docs/src/reader.js | 2 +- docs/src/templates/doc_widgets.css | 2 +- docs/src/templates/doc_widgets.js | 16 +++++++-------- docs/src/templates/docs-scenario.html | 2 +- docs/src/templates/docs.js | 8 ++++---- .../templates/syntaxhighlighter/shBrushJScript.js | 6 +++--- docs/src/templates/syntaxhighlighter/shBrushXml.js | 10 ++++----- docs/src/templates/syntaxhighlighter/shCore.css | 2 +- docs/src/templates/syntaxhighlighter/shCore.js | 2 +- .../templates/syntaxhighlighter/shThemeDefault.css | 2 +- docs/src/writer.js | 12 +++++------ 21 files changed, 106 insertions(+), 71 deletions(-) create mode 100644 docs/spec/domSpec.js (limited to 'docs') diff --git a/docs/angular.formatter.ngdoc b/docs/angular.formatter.ngdoc index ba28471f..2f4433cf 100644 --- a/docs/angular.formatter.ngdoc +++ b/docs/angular.formatter.ngdoc @@ -8,13 +8,13 @@ The formatters are responsible for translating user readable text in an input wi data model stored in an application. # Writting your own Formatter -Writing your own formatter is easy. Just register a pair of JavaScript functions with -`angular.formatter`. One function for parsing user input text to the stored form, +Writing your own formatter is easy. Just register a pair of JavaScript functions with +`angular.formatter`. One function for parsing user input text to the stored form, and one for formatting the stored data to user-visible text. -Here is an example of a "reverse" formatter: The data is stored in uppercase and in -reverse, while it is displayed in lower case and non-reversed. User edits are -automatically parsed into the internal form and data changes are automatically +Here is an example of a "reverse" formatter: The data is stored in uppercase and in +reverse, while it is displayed in lower case and non-reversed. User edits are +automatically parsed into the internal form and data changes are automatically formatted to the viewed form.
@@ -56,11 +56,11 @@ angular.formatter('reverse', {
});
-Formatted:
+Formatted:
-Stored:
+Stored:
{{data}}
@@ -69,7 +69,7 @@ Stored:
it('should store reverse', function(){
expect(element('.doc-example input:first').val()).toEqual('angular');
expect(element('.doc-example input:last').val()).toEqual('RALUGNA');
-
+
this.addFutureAction('change to XYZ', function($window, $document, done){
$document.elements('.doc-example input:last').val('XYZ').trigger('change');
done();
diff --git a/docs/angular.service.ngdoc b/docs/angular.service.ngdoc
index a34142bb..4e4810f9 100644
--- a/docs/angular.service.ngdoc
+++ b/docs/angular.service.ngdoc
@@ -76,7 +76,7 @@ window alert.
};
}, {$inject: ['$window']});
-
+
And here is a unit test for this service. We use Jasmine spy (mock) instead of real browser's alert.
var mock, notify;
@@ -85,7 +85,7 @@ beforeEach(function() {
mock = {alert: jasmine.createSpy()};
notify = angular.service('notify')(mock);
});
-
+
it('should not alert first two notifications', function() {
notify('one');
notify('two');
@@ -134,7 +134,7 @@ function myController($loc, $log) {
};
}
// which services to inject ?
-myController.$inject = ['$location', '$log'];
+myController.$inject = ['$location', '$log'];
@example
@@ -149,13 +149,13 @@ myController.$inject = ['$location', '$log'];
}
};
}, {$inject: ['$window']});
-
+
function myController(notifyService) {
this.callNotify = function(msg) {
notifyService(msg);
};
}
-
+
myController.$inject = ['notify'];
diff --git a/docs/angular.validator.ngdoc b/docs/angular.validator.ngdoc
index acd3caf2..fccdc5a0 100644
--- a/docs/angular.validator.ngdoc
+++ b/docs/angular.validator.ngdoc
@@ -4,7 +4,7 @@
@namespace Namespace for all filters.
@description
# Overview
-Validators are a standard way to check the user input against a specific criteria. For
+Validators are a standard way to check the user input against a specific criteria. For
example, you might need to check that an input field contains a well-formed phone number.
# Syntax
@@ -29,10 +29,10 @@ Attach a validator on user input widgets using the `ng:validate` attribute.
# Writing your own Validators
-Writing your own validator is easy. To make a function available as a
-validator, just define the JavaScript function on the `angular.validator`
-object.
@@ -38,7 +38,7 @@ angular.widget('my:watch', function(compileElement) {
# Attribute Widget
-Let's implement the same widget, but this time as an attribute
+Let's implement the same widget, but this time as an attribute
that can be added to any existing DOM element.
<div my-watch="name">text</div>
@@ -70,4 +70,4 @@ angular.widget('@my:watch', function(expression, compileElement) {
});
-
\ No newline at end of file
+
diff --git a/docs/service.template b/docs/service.template
index c28bddc9..639990ed 100644
--- a/docs/service.template
+++ b/docs/service.template
@@ -54,4 +54,4 @@
{{#scenario}}{{{scenario}}} {{/scenario}}
-{{/example}}
\ No newline at end of file
+{{/example}}
diff --git a/docs/spec/domSpec.js b/docs/spec/domSpec.js
new file mode 100644
index 00000000..af1a8faa
--- /dev/null
+++ b/docs/spec/domSpec.js
@@ -0,0 +1,24 @@
+var DOM = require('dom.js').DOM;
+
+describe('dom', function(){
+ describe('example', function(){
+ it('should render code, live, test', function(){
+ var dom = new DOM();
+ dom.example('desc', 'src', 'scenario');
+ expect(dom.toString()).toEqual('Example
\ndescsrc \nscenario \n \n');
+ });
+
+ it('should render non-live, test with description', function(){
+ var dom = new DOM();
+ dom.example('desc', 'src', false);
+ expect(dom.toString()).toEqual('Example
\ndescsrc
\n\n');
+ });
+
+ it('should render non-live, test', function(){
+ var dom = new DOM();
+ dom.example('desc', 'src', false);
+ expect(dom.toString()).toContain('src
');
+ });
+
+ });
+});
diff --git a/docs/spec/ngdocSpec.js b/docs/spec/ngdocSpec.js
index 7d024cb5..2bea6e9a 100644
--- a/docs/spec/ngdocSpec.js
+++ b/docs/spec/ngdocSpec.js
@@ -279,6 +279,16 @@ describe('ngdoc', function(){
doc.parse();
expect(doc.html()).toContain('some\n text');
});
+
+ it('should render description in related method', function(){
+ var doc = new Doc();
+ doc.ngdoc = 'service';
+ doc.methods = [new Doc('@ngdoc method\n@exampleDescription MDesc\n@example MExmp').parse()];
+ doc.properties = [new Doc('@ngdoc property\n@exampleDescription PDesc\n@example PExmp').parse()];
+ expect(doc.html()).toContain('
MDesc
MExmp
');
+ expect(doc.html()).toContain('PDesc
PExmp
');
+ });
+
});
describe('@deprecated', function() {
diff --git a/docs/spec/writerSpec.js b/docs/spec/writerSpec.js
index 1a722ca6..8354ad5d 100644
--- a/docs/spec/writerSpec.js
+++ b/docs/spec/writerSpec.js
@@ -2,17 +2,17 @@ var writer = require('writer.js');
describe('writer', function(){
describe('toString', function(){
var toString = writer.toString;
-
+
it('should merge string', function(){
expect(toString('abc')).toEqual('abc');
});
-
+
it('should merge obj', function(){
expect(toString({a:1})).toEqual('{"a":1}');
});
-
+
it('should merge array', function(){
expect(toString(['abc',{}])).toEqual('abc{}');
});
});
-});
\ No newline at end of file
+});
diff --git a/docs/src/gen-docs.js b/docs/src/gen-docs.js
index 0dee586b..1c03a0f1 100644
--- a/docs/src/gen-docs.js
+++ b/docs/src/gen-docs.js
@@ -38,7 +38,7 @@ var writes = callback.chain(function(){
writer.copy('jquery.min.js', writes.waitFor());
});
writes.onDone(function(){
- console.log('DONE. Generated ' + docs.length + ' pages in ' +
+ console.log('DONE. Generated ' + docs.length + ' pages in ' +
(now()-start) + 'ms.' );
});
work.onDone(writes);
diff --git a/docs/src/ngdoc.js b/docs/src/ngdoc.js
index 8481f7dc..daa44fef 100644
--- a/docs/src/ngdoc.js
+++ b/docs/src/ngdoc.js
@@ -76,6 +76,7 @@ Doc.prototype = {
this.description = markdown(this.description);
this['this'] = markdown(this['this']);
this.exampleDescription = markdown(this.exampleDescription || this.exampleDesc);
+ return this;
function flush(){
if (atName) {
@@ -144,13 +145,13 @@ Doc.prototype = {
dom.h(method.shortName + '(' + signature.join(', ') + ')', method, function(){
dom.html(method.description);
method.html_usage_parameters(dom);
- dom.example(method.example, false);
+ dom.example(method.exampleDescription, method.example, false);
});
});
dom.h('Properties', self.properties, function(property){
dom.h(property.name, function(){
dom.text(property.description);
- dom.example(property.example, false);
+ dom.example(property.exampleDescription, property.example, false);
});
});
diff --git a/docs/src/reader.js b/docs/src/reader.js
index 8f9f22c3..5a653cd6 100644
--- a/docs/src/reader.js
+++ b/docs/src/reader.js
@@ -88,4 +88,4 @@ function findNgDocInJsFile(file, callback) {
-exports.collect = collect;
\ No newline at end of file
+exports.collect = collect;
diff --git a/docs/src/templates/doc_widgets.css b/docs/src/templates/doc_widgets.css
index 8361f105..9f007f0e 100644
--- a/docs/src/templates/doc_widgets.css
+++ b/docs/src/templates/doc_widgets.css
@@ -32,4 +32,4 @@ li.doc-example-live {
div.syntaxhighlighter {
padding-bottom: 1px !important; /* fix to remove unnecessary scrollbars http://is.gd/gSMgC */
-}
\ No newline at end of file
+}
diff --git a/docs/src/templates/doc_widgets.js b/docs/src/templates/doc_widgets.js
index 18aeeacb..2d1ab8c6 100644
--- a/docs/src/templates/doc_widgets.js
+++ b/docs/src/templates/doc_widgets.js
@@ -1,5 +1,5 @@
(function(){
-
+
var angularJsUrl;
var scripts = document.getElementsByTagName("script");
var filename = /(.*\/)angular([^\/]*)/;
@@ -10,7 +10,7 @@
}
}
-
+
var HTML_TEMPLATE =
'\n' +
'\n' +
@@ -32,15 +32,15 @@
var tabs = angular.element(
'' +
'Source
' +
- '- ' +
- '
' +
+ '
' +
'Live Preview
' +
'- ' + exampleSrc +'
' +
'Scenario Test
' +
'' + scenario.text() + '
' +
'
');
-
+
tabs.find('li.doc-example-source > pre').text(HTML_TEMPLATE.replace('_HTML_SOURCE_', code.html));
element.html('');
@@ -54,7 +54,7 @@
alert(e);
}
});
-
+
function indent(text) {
var lines = text.split(/\n/);
var lineNo = [];
@@ -66,5 +66,5 @@
}
return {html: lines.join('\n'), hilite: lineNo.join(',') };
};
-
-})();
\ No newline at end of file
+
+})();
diff --git a/docs/src/templates/docs-scenario.html b/docs/src/templates/docs-scenario.html
index c75155c5..bc244d5d 100644
--- a/docs/src/templates/docs-scenario.html
+++ b/docs/src/templates/docs-scenario.html
@@ -7,4 +7,4 @@
-