Skip to content

Commit 6d53808

Browse files
committed
improve jsdocs
- improve json filter example - improve filter overview doc - improving validator overview jsdocs - simplify number filter examples and make them live + add specs - various doc fixes
1 parent a7e8a50 commit 6d53808

File tree

3 files changed

+66
-40
lines changed

3 files changed

+66
-40
lines changed

src/Angular.js

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,22 @@ var _undefined = undefined,
167167
*
168168
* <doc:example>
169169
* <doc:source>
170-
* Change me: &lt;input type="text" name="number" ng:validate="integer" value="123"&gt;
170+
* Change me: &lt;input type="text" name="number" ng:validate="integer" value="123"&gt;
171171
* </doc:source>
172+
* <doc:scenario>
173+
* it('should validate the default number string', function() {
174+
* expect(element('input[name=number]').attr('class')).
175+
* not().toMatch(/ng-validation-error/);
176+
* });
177+
* it('should not validate "foo"', function() {
178+
* input('number').enter('foo');
179+
* expect(element('input[name=number]').attr('class')).
180+
* toMatch(/ng-validation-error/);
181+
* });
182+
* </doc:scenario>
172183
* </doc:example>
173184
*
185+
*
174186
* # Writing your own Validators
175187
* Writing your own validator is easy. To make a function available as a
176188
* validator, just define the JavaScript function on the `angular.validator`
@@ -187,13 +199,10 @@ var _undefined = undefined,
187199
* In this example we have written a upsTrackingNo validator.
188200
* It marks the input text "valid" only when the user enters a well-formed
189201
* UPS tracking number.
190-
*
191-
* <pre>
192-
* angular.validator('upsTrackingNo', function(input, format) {
193-
* var regexp = new RegExp("^" + format.replace(/9/g, '\\d') + "$");
194-
* return input.match(regexp) ? "" : "The format must match " + format;
195-
* });
196-
* </pre>
202+
*
203+
* @css ng-validation-error
204+
* When validation fails, this css class is applied to the binding, making its borders red by
205+
* default.
197206
*
198207
* @example
199208
* <script>
@@ -205,7 +214,19 @@ var _undefined = undefined,
205214
* <input type="text" name="trackNo" size="40"
206215
* ng:validate="upsTrackingNo:'1Z 999 999 99 9999 999 9'"
207216
* value="1Z 123 456 78 9012 345 6"/>
208-
*
217+
*
218+
* @scenario
219+
* it('should validate correct UPS tracking number', function() {
220+
* expect(element('input[name=trackNo]').attr('class')).
221+
* not().toMatch(/ng-validation-error/);
222+
* });
223+
*
224+
* it('should not validate in correct UPS tracking number', function() {
225+
* input('trackNo').enter('foo');
226+
* expect(element('input[name=trackNo]').attr('class')).
227+
* toMatch(/ng-validation-error/);
228+
* });
229+
*
209230
*/
210231
angularValidator = extensionMap(angular, 'validator'),
211232

@@ -278,10 +299,12 @@ var _undefined = undefined,
278299
return out;
279300
});
280301
</script>
281-
<span ng:non-bindable="true">{{"hello"|reverse}}</span>: {{"hello"|reverse}}<br>
282-
<span ng:non-bindable="true">{{"hello"|reverse:true}}</span>: {{"hello"|reverse:true}}<br>
283-
<span ng:non-bindable="true">{{"hello"|reverse:true:"blue"}}</span>:
284-
{{"hello"|reverse:true:"blue"}}
302+
303+
<input name="text" type="text" value="hello" /><br>
304+
No filter: {{text}}<br>
305+
Reverse: {{text|reverse}}<br>
306+
Reverse + uppercase: {{text|reverse:true}}<br>
307+
Reverse + uppercase + blue: {{text|reverse:true:"blue"}}
285308
286309
*/
287310
angularFilter = extensionMap(angular, 'filter'),
@@ -324,7 +347,7 @@ var _undefined = undefined,
324347
* </pre>
325348
*
326349
* @example
327-
* <script>
350+
* <script type="text/javascript">
328351
* function reverse(text) {
329352
* var reversed = [];
330353
* for (var i = 0; i < text.length; i++) {

src/filters.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
it('should update', function(){
2424
input('amount').enter('-1234');
2525
expect(binding('amount | currency')).toBe('$-1,234.00');
26-
// TODO: implement
27-
// expect(binding('amount')).toHaveColor('red'); //what about toHaveCssClass instead?
26+
expect(element('span[ng\\:bind="amount | currency"]').attr('class')).
27+
toMatch(/ng-format-negative/);
2828
});
2929
*/
3030
angularFilter.currency = function(amount){
@@ -47,17 +47,23 @@ angularFilter.currency = function(amount){
4747
* @returns {string} Number rounded to decimalPlaces and places a “,” after each third digit.
4848
*
4949
* @example
50-
<span ng:non-bindable>{{1234.56789 | number}}</span>: {{1234.56789 | number}}<br/>
51-
<span ng:non-bindable>{{1234.56789 | number:0}}</span>: {{1234.56789 | number:0}}<br/>
52-
<span ng:non-bindable>{{1234.56789 | number:2}}</span>: {{1234.56789 | number:2}}<br/>
53-
<span ng:non-bindable>{{-1234.56789 | number:4}}</span>: {{-1234.56789 | number:4}}
54-
*
50+
Enter number: <input name='val' value='1234.56789' /><br/>
51+
Default formatting: {{val | number}}<br/>
52+
No fractions: {{val | number:0}}<br/>
53+
Negative number: {{-val | number:4}}
54+
5555
* @scenario
5656
it('should format numbers', function(){
57-
expect(binding('1234.56789 | number')).toBe('1,234.57');
58-
expect(binding('1234.56789 | number:0')).toBe('1,235');
59-
expect(binding('1234.56789 | number:2')).toBe('1,234.57');
60-
expect(binding('-1234.56789 | number:4')).toBe('-1,234.5679');
57+
expect(binding('val | number')).toBe('1,234.57');
58+
expect(binding('val | number:0')).toBe('1,235');
59+
expect(binding('-val | number:4')).toBe('-1,234.5679');
60+
});
61+
62+
it('should update', function(){
63+
input('val').enter('3374.333');
64+
expect(binding('val | number')).toBe('3,374.33');
65+
expect(binding('val | number:0')).toBe('3,374');
66+
expect(binding('-val | number:4')).toBe('-3,374.3330');
6167
});
6268
*/
6369
angularFilter.number = function(number, fractionSize){
@@ -238,12 +244,19 @@ angularFilter.date = function(date, format) {
238244
*
239245
* @css ng-monospace Always applied to the encapsulating element.
240246
*
241-
* @example
242-
<span ng:non-bindable>{{ {a:1, b:[]} | json }}</span>: <pre>{{ {a:1, b:[]} | json }}</pre>
247+
* @example:
248+
<input type="text" name="objTxt" value="{a:1, b:[]}"
249+
ng:eval="obj = $eval(objTxt)"/>
250+
<pre>{{ obj | json }}</pre>
243251
*
244252
* @scenario
245253
it('should jsonify filtered objects', function() {
246-
expect(binding('{{ {a:1, b:[]} | json')).toBe('{\n "a":1,\n "b":[]}');
254+
expect(binding('obj | json')).toBe('{\n "a":1,\n "b":[]}');
255+
});
256+
257+
it('should update', function() {
258+
input('objTxt').enter('[1, 2, 3]');
259+
expect(binding('obj | json')).toBe('[1,2,3]');
247260
});
248261
*
249262
*/
@@ -401,8 +414,8 @@ and one more: ftp://127.0.0.1/.</textarea>
401414
<td><div ng:bind="snippet"></div></td>
402415
</tr>
403416
</table>
404-
*
405-
* @scenario
417+
418+
@scenario
406419
it('should linkify the snippet with urls', function(){
407420
expect(using('#linky-filter').binding('snippet | linky')).
408421
toBe('Pretty text with some links:\n' +

src/validators.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,6 @@ extend(angularValidator, {
321321
*
322322
* @css ng-input-indicator-wait, ng-validation-error
323323
*
324-
* @exampleDescription
325-
* <pre>
326-
* function myValidator (inputToValidate, validationDone) {
327-
* // simulate delayed response, validate on even input length
328-
* setTimeout(function(){
329-
* validationDone(inputToValidate.length % 2);
330-
* }, 500);
331-
* };
332-
* </pre>
333-
*
334324
* @example
335325
* <script>
336326
* function myValidator(inputToValidate, validationDone) {

0 commit comments

Comments
 (0)