Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit c2cb3b5

Browse files
committed
docs(formatter): fix and edit per comments on 0e0f8d6
Closes #1036
1 parent 8846c0c commit c2cb3b5

15 files changed

+77
-62
lines changed

lib/core/annotation_src.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,16 @@ abstract class DetachAware {
547547
}
548548

549549
/**
550-
* Use the @[Formatter] class annotation to register a new formatter.
550+
* Use the @[Formatter] class annotation to identify a class as a formatter.
551551
*
552552
* A formatter is a pure function that performs a transformation on input data from an expression.
553553
* For more on formatters in Angular, see the documentation for the
554554
* [angular:formatter](#angular-formatter) library.
555555
*
556-
* Usage:
556+
* A formatter class must have a call method with at least one parameter, which specifies the value to format. Any
557+
* additional parameters are treated as arguments of the formatter.
558+
*
559+
* **Usage**
557560
*
558561
* // Declaration
559562
* @Formatter(name:'myFormatter')

lib/formatter/arrayify.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
part of angular.formatter_internal;
22

33
/**
4-
* Given a Map, returns a list of items which have `key` and `value` property.
4+
* Transforms a Map into an array so that the map can be used with `ng-repeat`.
55
*
6-
* Usage:
6+
* Example:
77
*
88
* <div ng-repeat="item in {'key1': 'value1', 'key2':'value2'} | arrayify">
99
* {{item.key}}: {{item.value}}

lib/formatter/currency.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ part of angular.formatter_internal;
77
* see the [angular:formatter](#angular-formatter) library.
88
*
99
*
10-
* Usage:
10+
* # Usage
11+
*
12+
* expression | currency[:symbol[:leading]]
13+
*
14+
* # Example
15+
*
16+
* {{ 1234 | currency }} // output is $1,234.00
17+
* {{ 1234 | currency:'CAD' }} // output is CAD1,234.00
18+
* {{ 1234 | currency:'CAD':false }} // output is 1,234.00CAD
1119
*
12-
* {{ numeric_expression | currency[:symbol[:leading]] }}
1320
*
1421
*/
1522
@Formatter(name:'currency')
@@ -22,8 +29,8 @@ class Currency implements Function {
2229
*
2330
* - `value`: the value to format as currency.
2431
* - `symbol`: the currency symbol to use. If no symbol is specified, `$` is used.
25-
* - `leading`: when set to false, places the symbol after the number instead of before
26-
* it.
32+
* - `leading`: false places the symbol after the number instead of before
33+
* it. (By default, leading is true.)
2734
*/
2835
call(value, [symbol = r'$', leading = true]) {
2936
if (value is String) value = double.parse(value);

lib/formatter/date.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ part of angular.formatter_internal;
55
*
66
* Usage:
77
*
8-
* {{ date_expression | date[:format] }}
8+
* date_expression | date[:format]
99
*
1010
* Here `format` may be specified explicitly, or by using one of the following predefined
1111
* localizable names:

lib/formatter/filter.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ typedef bool _Equals(a, b);
88
* Selects a subset of items from the provided [List] and returns it as a new
99
* [List].
1010
*
11-
* Usage:
11+
* # Usage
1212
*
13-
* <div ng-repeat="item in items | filter:_expression_[:_comparator_]">
13+
* filter: expression[:comparator]
1414
*
15-
* In addition to the `expression`, which is used to select a subset from the list,
16-
* you can also specify a `comparator` to specify how the operation is performed. 
15+
* In addition to the expression, which is used to select a subset from the list,
16+
* you can also specify a comparator to specify how the operation is performed. 
1717
*
18-
*
19-
* `expression` can be of the following types:
18+
* The expression can be of the following types:
2019
*
2120
* - [String], [bool] and [num]:  Only items in the list that directly
2221
* match this expression, items that are Maps with any value matching this
@@ -36,7 +35,7 @@ typedef bool _Equals(a, b);
3635
* `true`.
3736
*
3837
*
39-
* `comparator` is optional and can be one of the following:
38+
* The comparator is optional and can be one of the following:
4039
*
4140
* - `bool comparator(expected, actual)`:  The function will be called with the
4241
* object value and the predicate value to compare and should return true if

lib/formatter/json.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
part of angular.formatter_internal;
22

33
/**
4-
* Converts a JavaScript object into a JSON string.
4+
* Converts an object into a JSON string.
55
*
66
* This formatter is mostly useful for debugging.
77
*
8-
* Usage:
8+
* Note that the object to convert must be directly encodable to JSON (a
9+
* number, boolean, string, null, list or a map with string keys). To convert other objects, the
10+
* [toEncodable](http://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-convert
11+
* .JsonCodec#id_encode) function must be used first.
912
*
10-
* {{ json_expression | json }}
13+
* # Usage
14+
*
15+
* json_expression | json
1116
*/
1217
@Formatter(name:'json')
1318
class Json implements Function {

lib/formatter/limit_to.dart

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@ part of angular.formatter_internal;
66
*
77
* The number of elements to return is specified by the `limitTo` parameter.
88
*
9-
* Usage:
10-
*
11-
* {{ expression | limitTo:_number_ }}
12-
*
13-
*
14-
* <div ng-repeat="item in expression | limitTo:_number_">{{item}}</div>
9+
* # Usage
1510
*
11+
* expression | limitTo:number
1612
*
1713
* Where the input expression is a [List] or [String], and `limitTo` is:
1814
*
@@ -25,15 +21,14 @@ part of angular.formatter_internal;
2521
* When operating on a [List], the returned list is always a copy even when all
2622
* the elements are being returned.
2723
*
28-
* Example:
24+
* # Examples
2925
*
30-
* - `{{ 'abcdefghij' | limitTo: 4 }}``'abcd'`
31-
* - `{{ 'abcdefghij' | limitTo: -4 }}``'ghij'`
32-
* - `{{ 'abcdefghij' | limitTo: -100 }}``'abcdefghij'`
26+
* {{ 'abcdefghij' | limitTo: 4 }} // output is 'abcd'
27+
* {{ 'abcdefghij' | limitTo: -4 }} // output is 'ghij'
28+
* {{ 'abcdefghij' | limitTo: -100 }} // output is 'abcdefghij'
3329
*
34-
* <br>
3530
*
36-
* This [ng-repeat] directive:
31+
* This `ng-repeat` directive:
3732
*
3833
* <li ng-repeat="i in 'abcdefghij' | limitTo:-2">{{i}}</li>
3934
*

lib/formatter/lowercase.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ part of angular.formatter_internal;
33
/**
44
* Converts a string to lowercase.
55
*
6-
* Usage:
6+
* # Usage
77
*
8-
* {{ lowercase_expression | lowercase }}
8+
* expression | lowercase
99
*/
1010
@Formatter(name:'lowercase')
1111
class Lowercase implements Function {

lib/formatter/module.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/**
2-
*
32
* Formatters for [angular.dart](#angular/angular), a web framework for Dart. A formatter is a
43
* pure function that performs a transformation on input data from an expression.
54
*
@@ -13,17 +12,16 @@
1312
*
1413
* For example:
1514
*
16-
* {{ _some_expression_ | json }}
15+
* {{ expression | json }}
1716
*
1817
* or, in a repeater:
1918
*
20-
* <div ng-repeat="item in items | filter:_predicate_">
21-
*
22-
*
19+
* <div ng-repeat="item in items | limitTo:2">
2320
*/
2421
library angular.formatter;
2522

2623
export "package:angular/formatter/module_internal.dart" show
24+
FormatterModule,
2725
Currency,
2826
Date,
2927
Filter,

lib/formatter/module_internal.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ part 'order_by.dart';
1919
part 'uppercase.dart';
2020
part 'stringify.dart';
2121

22+
/**
23+
* This module registers all the Angular formatters.
24+
*
25+
* When instantiating an Angular application through applicationFactory,
26+
* FormatterModule is automatically included.
27+
*/
2228
class FormatterModule extends Module {
2329
FormatterModule() {
2430
bind(Arrayify);

lib/formatter/number.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ part of angular.formatter_internal;
66
* If the input is not a number, an empty string is returned.
77
*
88
*
9-
* Usage:
9+
* # Usage
1010
*
11-
* {{ number_expression | number[:fractionSize] }}
11+
* expression | number[:fractionSize]
1212
*
1313
*/
1414
@Formatter(name:'number')
@@ -22,7 +22,7 @@ class Number {
2222
* - `value`: the value to format
2323
* - `fractionSize`: Number of decimal places to round the number to.
2424
*
25-
* When fractionSize is not provided, fraction size is computed from the current locale's number
25+
* When `fractionSize` is not provided, fraction size is computed from the current locale's number
2626
* formatting pattern. In the case of the default locale, it will be 3.
2727
*
2828
*/

lib/formatter/order_by.dart

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@ part of angular.formatter_internal;
33
typedef dynamic _Mapper(dynamic e);
44

55
/**
6-
* Orders the the elements of an object by a predicate expression.
6+
* Orders the the elements of a list using a predicate.
77
*
8-
* Usage:
8+
* # Usage
99
*
10-
* <div ng-repeat="item in items | orderBy: [+/-]_expression_[:true]">
10+
* expression | orderBy: predicate[:true]
1111
*
12+
* The input to orderBy must be an [Iterable] object. The predicate may be specified as:
1213
*
13-
* The input must be an [Iterable] object. The expression may be specified as:
14-
*
15-
* - `+`: sort the elements in asending order. This is the default comparator.
16-
* - `-`: sort the elements in descending order.
17-
* - **a string expression**: sort on a decorated/transformed value, such as "lastName",
18-
* or to sort non-primitives values.
14+
* - **a string**: a string containing an expression, such as "user.lastName", used to order the list.
1915
* - **a custom callable expression**: an expression that will be called to transform the element
20-
* before a sort.
21-
* - **a list**: the list may consist of either string or callable expressions. A list expression
22-
* indicates a list of fallback expressions to use when a comparision results in the items
23-
* being equal.
16+
* before a sort.
17+
* - **a list**: the list may consist of either strings or callable expressions. A list expression
18+
* indicates a list of fallback expressions to use when a comparision results in the items
19+
* being equal.
2420
*
25-
* If the expression is explicitly empty(`orderBy:```), the elements are sorted in
21+
* If the expression is explicitly empty(`orderBy:''`), the elements are sorted in
2622
* ascending order, using the default comparator, `+`.
2723
*
28-
* Last, by appending `:true`, you can set "descending order" to true,
29-
* which has the same effect as the `-` comparator.
24+
* A string expression in the predicate can be prefixed to indicate sort order:
25+
*
26+
* - `+`: sort the elements in asending order. This is the default.
27+
* - `-`: sort the elements in descending order.
28+
*
29+
* Alternately, by appending `true`, you can set "descending order" to true, which has the same effect as the `-`
30+
* prefix.
3031
*
3132
* # Examples
3233
*
@@ -85,7 +86,7 @@ typedef dynamic _Mapper(dynamic e);
8586
* If you want to list the authors sorted by `lastName`, you would use
8687
*
8788
* <li ng-repeat="author in authors | orderBy:'lastName'">
88-
* {{author.lastName}}, {{author.firstName
89+
* {{author.lastName}}, {{author.firstName}}
8990
* </li>
9091
*
9192
* The string expression, `'lastName'`, indicates that the sort should be on the

lib/formatter/stringify.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ part of angular.formatter_internal;
66
* Null objects are converted to an empty string.
77
*
88
*
9-
* Usage:
9+
* # Usage:
1010
*
11-
* {{ expression | stringify }}
11+
* expression | stringify
1212
*/
1313
@Formatter(name:'stringify')
1414
class Stringify implements Function {

lib/formatter/uppercase.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ part of angular.formatter_internal;
33
/**
44
* Converts a string to uppercase.
55
*
6-
* Usage:
6+
* # Usage:
77
*
8-
* {{ uppercase_expression | uppercase }}
8+
* expression | uppercase
99
*/
1010
@Formatter(name:'uppercase')
1111
class Uppercase implements Function {

test/angular_spec.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ main() {
213213
"angular.formatter_internal.Currency",
214214
"angular.formatter_internal.Date",
215215
"angular.formatter_internal.Filter",
216+
"angular.formatter_internal.FormatterModule",
216217
"angular.formatter_internal.Json",
217218
"angular.formatter_internal.LimitTo",
218219
"angular.formatter_internal.Lowercase",

0 commit comments

Comments
 (0)