Permalink
Browse files

Obsolete number formatting and localization sample code

  • Loading branch information...
1 parent 422c55a commit bd53b5fd930399c69cc11231de369ef008142525 @groue committed Feb 13, 2013
Showing with 22 additions and 6,525 deletions.
  1. +2 −2 Guides/compatibility.md
  2. +8 −63 Guides/delegate.md
  3. +1 −1 Guides/filters.md
  4. +1 −3 Guides/rendering_objects.md
  5. +1 −2 Guides/runtime.md
  6. +3 −13 Guides/sample_code/README.md
  7. +2 −2 Guides/sample_code/indexes.md
  8. +1 −372 Guides/sample_code/localization.md
  9. +0 −319 Guides/sample_code/localization/GRMustacheLocalization.xcodeproj/project.pbxproj
  10. +0 −29 Guides/sample_code/localization/GRMustacheLocalization/GRAppDelegate.h
  11. +0 −173 Guides/sample_code/localization/GRMustacheLocalization/GRAppDelegate.m
  12. +0 −34 Guides/sample_code/localization/GRMustacheLocalization/GRMustacheLocalization-Info.plist
  13. +0 −7 Guides/sample_code/localization/GRMustacheLocalization/GRMustacheLocalization-Prefix.pch
  14. +0 −57 Guides/sample_code/localization/GRMustacheLocalization/LocalizingHelper.h
  15. +0 −152 Guides/sample_code/localization/GRMustacheLocalization/LocalizingHelper.m
  16. +0 −5 Guides/sample_code/localization/GRMustacheLocalization/en.lproj/Localizable.strings
  17. +0 −4,666 Guides/sample_code/localization/GRMustacheLocalization/en.lproj/MainMenu.xib
  18. +0 −14 Guides/sample_code/localization/GRMustacheLocalization/main.m
  19. +1 −183 Guides/sample_code/number_formatting.md
  20. +0 −269 Guides/sample_code/number_formatting/GRMustacheNumberFormatting.xcodeproj/project.pbxproj
  21. +0 −27 Guides/sample_code/number_formatting/GRMustacheNumberFormatting/Document.h
  22. +0 −85 Guides/sample_code/number_formatting/GRMustacheNumberFormatting/Document.m
  23. +0 −7 ...es/sample_code/number_formatting/GRMustacheNumberFormatting/GRMustacheNumberFormatting-Prefix.pch
  24. +0 −35 Guides/sample_code/number_formatting/GRMustacheNumberFormatting/main.m
  25. +2 −4 README.md
  26. +0 −1 TODO.txt
View
@@ -144,9 +144,9 @@ Tag delegates
GRMustache's [tag delegates](delegate.md), unknown to the Mustache specification, let you observe, and possibly alter the rendering of the Mustache tags.
-Tag delegates may be used for formatting values in a spec-compliant way (see sample code in [Tag Delegates Guide](delegate.md)). They may also be used for putting Mustache on steroids, as in the [Localization Sample Code](sample_code/localization.md).
+Tag delegates may be used for formatting values in a spec-compliant way (see sample code in [Tag Delegates Guide](delegate.md)). They may also at the core of many items of the [standard library](standard_library.md).
-As such, they are an ambiguous tool. You will have to know when you cross the line.
+They are an ambiguous tool. You will have to know when you cross the line.
[up](../../../../GRMustache#documentation), [next](configuration.md)
View
@@ -150,67 +150,17 @@ You can, for instance, provide default rendering for missing values:
[[Document new] render];
```
-### Altering the rendering of tags in a section
-
-As stated above, when a section renders an object that conforms to the `GRMustacheTagDelegate` protocol, this object observes the rendering of all tags inside the section.
-
-The [Localization Sample Code](sample_code/localization.md) will give us an example, but let's have fun with numbers, and have Mustache format all numbers in a section attached to a `NSNumberFormatter` instance:
-
-```objc
-// Have NSNumberFormatter conform to the GRMustacheTagDelegate protocol,
-// so that a formatter can format all numbers in a section:
-@interface NSNumberFormatter(Document)<GRMustacheTagDelegate>
-@end
-
-@implementation NSNumberFormatter(Document)
-
-- (id)mustacheTag:(GRMustacheTag *)tag willRenderObject:(id)object
-{
- // Format all numbers that happen to be rendered by variable tags such as
- // `{{ count }}`.
- //
- // We avoid messing with sections, since they rely on boolean values of
- // numbers.
-
- if (tag.type == GRMustacheTagTypeVariable && [object isKindOfClass:[NSNumber class]]) {
- return [self stringFromNumber:object];
- }
- return object;
-}
-
-@end
-
-NSString *templateString = @"x = {{x}}\n"
- @"{{#percent}}x = {{x}}{{/percent}}\n"
- @"{{#decimal}}x = {{x}}{{/decimal}}";
-GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:templateString error:NULL];
-
-NSNumberFormatter *percentFormatter = [NSNumberFormatter new];
-percentFormatter.numberStyle = NSNumberFormatterPercentStyle;
-
-NSNumberFormatter *decimalFormatter = [NSNumberFormatter new];
-decimalFormatter.numberStyle = NSNumberFormatterDecimalStyle;
-
-id data = @{
- @"x": @(0.5),
- @"percent": percentFormatter,
- @"decimal": decimalFormatter
-};
-
-// On a French system:
-// x = 0.5
-// x = 50 %
-// x = 0,5
-NSString *rendering = [template renderObject:data error:NULL];
-```
-
Tag Delegates as Cross-Platform Filters
---------------------------------------
-Let's consider again the number formatting example above. We were able to render `{{#percent}}x = {{x}}{{/percent}}` as `x = 50 %`: The tag delegate attached to the `percent` has formatted the number `x` as a percentage.
+Tag delegates can observe, but also *alter* the rendering of all tags inside a section or the full template.
+
+Let's consider the behavior of NSFormatter in GRMustache. They are able to format all variable tags inside a section (check the [NSFormatter Guide](NSFormatter.md)).
-You could also use [filters](filters.md) in order to format numbers: `x = {{ percent(x) }}` would render just as well.
+For example, `{{#percent}}x = {{x}}{{/percent}}` renders as `x = 50 %` when `percent` is attached to an NSNumberFormatter. That is because formatters are *tag delegates*.
+
+We could also use [filters](filters.md) in order to format numbers: `x = {{ percent(x) }}` would render just as well.
However, `{{#percent}}x = {{x}}{{/percent}}` has one advantage over `x = {{ percent(x) }}`: it uses plain Mustache syntax, and is compatible with [other Mustache implementations](https://github.com/defunkt/mustache/wiki/Other-Mustache-implementations).
@@ -222,7 +172,7 @@ With such a common template, it's now a matter of providing different data, depe
// data for GRMustache
{
"x": 0.5,
- "percent": the_formating_tag_delegate
+ "percent": (some well-configured NSNumberFormatter)
}
// data for other Mustache implementations
@@ -276,6 +226,7 @@ NSString *rendering = [GRMustacheTemplate renderObject:data
The final rendering is "JOHANNES KEPLER".
+
Compatibility with other Mustache implementations
-------------------------------------------------
@@ -284,10 +235,4 @@ The [Mustache specification](https://github.com/mustache/spec) does not have the
**As a consequence, if your goal is to design templates that remain compatible with [other Mustache implementations](https://github.com/defunkt/mustache/wiki/Other-Mustache-implementations), use `GRMustacheTagDelegate` with great care.**
-Sample code
------------
-
-The [Localization Sample Code](sample_code/localization.md) uses tag delegates for localizing portions of a template.
-
-
[up](../../../../GRMustache#documentation), [next](rendering_objects.md)
View
@@ -179,7 +179,7 @@ Instead, have a look at tag delegates, especially the [Tag Delegates as Cross-Pl
Sample code
-----------
-Custom filters are used by the [Formatted Numbers](sample_code/number_formatting.md) and [Collection Indexes](sample_code/indexes.md) sample codes. Go check inspiration there.
+Custom filters are used in the [Collection Indexes](sample_code/indexes.md) sample code. Go check inspiration there.
[up](../../../../GRMustache#documentation), [next](delegate.md)
@@ -419,7 +419,7 @@ Many useful things.
When GRMustache renders `{{ name }}`, it looks for the `name` key in the [context stack](runtime.md): for the title and names of our movies and people to render, movies and people must enter the context stack. This is the reason for the derivation of new contexts, using the `contextByAddingObject:` method, before partials are rendered.
- There is also a `contextByAddingTagDelegate:` method, that is documented in the [Delegates Guide](delegate.md). An interesting usage of this method is demonstrated in the [Localization Sample Code](sample_code/localization.md).
+ There is also a `contextByAddingTagDelegate:` method, that is illustrated in the [Delegates Guide](delegate.md).
Example: Render collections of objects
@@ -483,8 +483,6 @@ You *can* write specification-compliant "Mustache lambdas" with rendering object
Sample code
-----------
-The [Localization Sample Code](sample_code/localization.md) uses the `GRMustacheRendering` protocol for localizing portions of template.
-
The [Collection Indexes Sample Code](sample_code/indexes.md) uses the `GRMustacheRendering` protocol for rendering indexes of an array items.
[up](../../../../GRMustache#documentation), [next](protected_contexts.md)
View
@@ -239,7 +239,6 @@ Such sections are fully documented in the [Rendering Objects Guide](rendering_ob
```objc
id data = @{
- @"localize": [LocalizingHelper new],
@"name1": @"Gustave",
@"name2": @"Henriett" };
@@ -252,7 +251,7 @@ NSString *rendering = [GRMustacheTemplate renderObject:data
error:NULL];
```
-This fancy `LocalizingHelper` class is described in the [Localization Sample Code](sample_code/localization.md).
+The `localize` key is attached to a rendering object that is built in the [standard library](standard_library.md) shipped with GRMustache.
### Other sections
@@ -1,18 +1,8 @@
-[up](../../../../../GRMustache#documentation), [next](number_formatting.md)
+[up](../../../../../GRMustache#documentation), [next](indexes.md)
Sample code
===========
-- [Number Formatting](number_formatting.md)
+**[Collection Indexes](indexes.md)**: How to have GRMustache render array indexes, render sections for the first or the last element, for odd or even elements, etc.: *discussion, downloadable Xcode project*.
- How to format numbers: *discussion, downloadable Xcode project*.
-
-- [Collection Indexes](indexes.md)
-
- How to have GRMustache render array indexes, render sections for the first or the last element, for odd or even elements, etc.: *discussion, downloadable Xcode project*.
-
-- [Localization](localization.md)
-
- How to have GRMustache localize portions of your templates: *discussion, downloadable Xcode project*.
-
-[up](../../../../../GRMustache#documentation), [next](number_formatting.md)
+[up](../../../../../GRMustache#documentation), [next](indexes.md)
@@ -1,4 +1,4 @@
-[up](../../../../tree/master/Guides/sample_code), [next](localization.md)
+[up](../../../../tree/master/Guides/sample_code), [next](../forking.md)
Collection Indexes
==================
@@ -153,4 +153,4 @@ Writing [filters](../filters.md) that return [rendering objects](../rendering_ob
**[Download the code](../../../../tree/master/Guides/sample_code/indexes)**
-[up](../../../../tree/master/Guides/sample_code), [next](localization.md)
+[up](../../../../tree/master/Guides/sample_code), [next](../forking.md)
Oops, something went wrong.

0 comments on commit bd53b5f

Please sign in to comment.