Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Section tag and variable tag helpers refactoring

  • Loading branch information...
commit 365d7df4d0d318f803e7f2ce99e91bc7ec3f4cd6 1 parent ad0697f
@groue authored
Showing with 1,226 additions and 181 deletions.
  1. +1 −1  src/bin/buildGRMustacheAvailabilityMacros
  2. +12 −4 src/classes/GRMustache.h
  3. +80 −2 src/classes/GRMustacheAvailabilityMacros.h
  4. +1 −1  src/classes/GRMustacheCompiler_private.h
  5. +56 −0 src/classes/GRMustacheDynamicPartial.h
  6. +69 −0 src/classes/GRMustacheDynamicPartial.m
  7. +10 −6 src/classes/GRMustacheSection.h
  8. +21 −3 src/classes/GRMustacheSectionElement.m
  9. +7 −6 src/classes/GRMustacheSectionElement_private.h
  10. +15 −7 src/classes/GRMustacheSectionHelper.h
  11. +3 −0  src/classes/GRMustacheSectionHelper.m
  12. +98 −0 src/classes/GRMustacheSectionTagHelper.h
  13. +97 −0 src/classes/GRMustacheSectionTagHelper.m
  14. +90 −0 src/classes/GRMustacheSectionTagRenderingContext.h
  15. +81 −0 src/classes/GRMustacheSectionTagRenderingContext.m
  16. +58 −0 src/classes/GRMustacheSectionTagRenderingContext_private.h
  17. +3 −3 src/classes/GRMustacheSection_private.h
  18. +33 −8 src/classes/GRMustacheTemplateDelegate.h
  19. +8 −5 src/classes/GRMustacheVariable.h
  20. +20 −3 src/classes/GRMustacheVariableElement.m
  21. +1 −1  src/classes/GRMustacheVariableElement_private.h
  22. +12 −40 src/classes/GRMustacheVariableHelper.h
  23. +0 −44 src/classes/GRMustacheVariableHelper.m
  24. +98 −0 src/classes/GRMustacheVariableTagHelper.h
  25. +99 −0 src/classes/GRMustacheVariableTagHelper.m
  26. +74 −0 src/classes/GRMustacheVariableTagRenderingContext.h
  27. +74 −0 src/classes/GRMustacheVariableTagRenderingContext.m
  28. +57 −0 src/classes/GRMustacheVariableTagRenderingContext_private.h
  29. +2 −2 src/classes/GRMustacheVariable_private.h
  30. +45 −44 src/tests/Public/v5.0/{GRMustacheTemplateDelegateTest.m → GRMustacheTemplateDelegate5_0Test.m}
  31. 0  ...sts/Public/v5.0/{GRMustacheTemplateDelegateTest.mustache → GRMustacheTemplateDelegate5_0Test.mustache}
  32. +1 −0  src/tests/Public/v5.0/GRMustacheTemplateDelegate5_0Test_wrapper.mustache
  33. +0 −1  src/tests/Public/v5.0/GRMustacheTemplateDelegateTest_wrapper.mustache
View
2  src/bin/buildGRMustacheAvailabilityMacros
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
MAJOR_VERSION = 5
-MAX_MINOR_VERSION = 2
+MAX_MINOR_VERSION = 3
puts <<-LICENSE
// The MIT License
View
16 src/classes/GRMustache.h
@@ -90,14 +90,22 @@ typedef struct {
@end
-#import "GRMustacheSection.h"
#import "GRMustacheInvocation.h"
#import "GRMustacheTemplate.h"
#import "GRMustacheTemplateDelegate.h"
#import "GRMustacheTemplateRepository.h"
#import "GRMustacheFilter.h"
-#import "GRMustacheVariable.h"
-#import "GRMustacheVariableHelper.h"
-#import "GRMustacheSectionHelper.h"
+#import "GRMustacheDynamicPartial.h"
+#import "GRMustacheVariableTagHelper.h"
+#import "GRMustacheVariableTagRenderingContext.h"
+#import "GRMustacheSectionTagHelper.h"
+#import "GRMustacheSectionTagRenderingContext.h"
#import "GRMustacheError.h"
#import "GRMustacheVersion.h"
+
+// Compatibility with deprecated declarations
+
+#import "GRMustacheSectionHelper.h"
+#import "GRMustacheSection.h"
+#import "GRMustacheVariableHelper.h"
+#import "GRMustacheVariable.h"
View
82 src/classes/GRMustacheAvailabilityMacros.h
@@ -31,6 +31,7 @@
#define GRMUSTACHE_VERSION_5_0 5000
#define GRMUSTACHE_VERSION_5_1 5010
#define GRMUSTACHE_VERSION_5_2 5020
+#define GRMUSTACHE_VERSION_5_3 5030
@@ -38,10 +39,10 @@
/*
- * If max GRMustacheVersion not specified, assume 5.2
+ * If max GRMustacheVersion not specified, assume 5.3
*/
#ifndef GRMUSTACHE_VERSION_MAX_ALLOWED
-#define GRMUSTACHE_VERSION_MAX_ALLOWED GRMUSTACHE_VERSION_5_2
+#define GRMUSTACHE_VERSION_MAX_ALLOWED GRMUSTACHE_VERSION_5_3
#endif
/*
@@ -211,3 +212,80 @@
+/*
+ * AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER
+ *
+ * Used on declarations introduced in GRMustache 5.3
+ */
+#if GRMUSTACHE_VERSION_MAX_ALLOWED < GRMUSTACHE_VERSION_5_3
+#define AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER UNAVAILABLE_ATTRIBUTE
+#elif GRMUSTACHE_VERSION_MIN_REQUIRED < GRMUSTACHE_VERSION_5_3
+#define AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER WEAK_IMPORT_ATTRIBUTE
+#else
+#define AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER_BUT_DEPRECATED
+ *
+ * Used on declarations introduced in GRMustache 5.3,
+ * and deprecated in GRMustache 5.3
+ */
+#if GRMUSTACHE_VERSION_MIN_REQUIRED >= GRMUSTACHE_VERSION_5_3
+#define AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+#else
+#define AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER_BUT_DEPRECATED AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3
+ *
+ * Used on declarations introduced in GRMustache 5.0,
+ * but later deprecated in GRMustache 5.3
+ */
+#if GRMUSTACHE_VERSION_MIN_REQUIRED >= GRMUSTACHE_VERSION_5_3
+#define AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3 DEPRECATED_ATTRIBUTE
+#else
+#define AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3 AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3
+ *
+ * Used on declarations introduced in GRMustache 5.1,
+ * but later deprecated in GRMustache 5.3
+ */
+#if GRMUSTACHE_VERSION_MIN_REQUIRED >= GRMUSTACHE_VERSION_5_3
+#define AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3 DEPRECATED_ATTRIBUTE
+#else
+#define AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3 AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_GRMUSTACHE_VERSION_5_2_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3
+ *
+ * Used on declarations introduced in GRMustache 5.2,
+ * but later deprecated in GRMustache 5.3
+ */
+#if GRMUSTACHE_VERSION_MIN_REQUIRED >= GRMUSTACHE_VERSION_5_3
+#define AVAILABLE_GRMUSTACHE_VERSION_5_2_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3 DEPRECATED_ATTRIBUTE
+#else
+#define AVAILABLE_GRMUSTACHE_VERSION_5_2_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3 AVAILABLE_GRMUSTACHE_VERSION_5_2_AND_LATER
+#endif
+
+/*
+ * DEPRECATED_IN_GRMUSTACHE_VERSION_5_3_AND_LATER
+ *
+ * Used on types deprecated in GRMustache 5.3
+ */
+#if GRMUSTACHE_VERSION_MIN_REQUIRED >= GRMUSTACHE_VERSION_5_3
+#define DEPRECATED_IN_GRMUSTACHE_VERSION_5_3_AND_LATER DEPRECATED_ATTRIBUTE
+#else
+#define DEPRECATED_IN_GRMUSTACHE_VERSION_5_3_AND_LATER
+#endif
+
+
+
+
+
+
View
2  src/classes/GRMustacheCompiler_private.h
@@ -57,7 +57,7 @@
* - allows helpers to render alternate template strings that contain partials.
*
* @see GRMustacheTemplateRepository
- * @see GRMustacheSection
+ * @see GRMustacheSectionTagRenderingContext
*/
@property (nonatomic, assign) GRMustacheTemplateRepository *templateRepository GRMUSTACHE_API_INTERNAL;
View
56 src/classes/GRMustacheDynamicPartial.h
@@ -0,0 +1,56 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+#import "GRMustacheAvailabilityMacros.h"
+
+/**
+ * The GRMustacheDynamicPartial is a specific kind of GRMustacheVariableTagHelper
+ * that, given a partial template name, renders this template.
+ *
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/variable_tag_helpers.md
+ *
+ * @see GRMustacheVariableTagHelper protocol
+ *
+ * @since v5.1
+ */
+@interface GRMustacheDynamicPartial: NSObject {
+ NSString *_name;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// @name Creating Dynamic Partials
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Returns a GRMustacheDynamicPartial that renders a partial template named
+ * _name_.
+ *
+ * @param name A template name
+ *
+ * @return a GRMustacheDynamicPartial
+ *
+ * @since v5.1
+ */
++ (id)dynamicPartialWithName:(NSString *)name AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER;
+
+@end
View
69 src/classes/GRMustacheDynamicPartial.m
@@ -0,0 +1,69 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import "GRMustacheDynamicPartial.h"
+#import "GRMustacheVariableTagHelper.h"
+#import "GRMustacheVariableTagRenderingContext.h"
+#import "GRMustacheError.h"
+
+@interface GRMustacheDynamicPartial()<GRMustacheVariableTagHelper>
+- (id)initWithName:(NSString *)name;
+@end
+
+@implementation GRMustacheDynamicPartial
+
++ (id)dynamicPartialWithName:(NSString *)name
+{
+ return [[[GRMustacheDynamicPartial alloc] initWithName:name] autorelease];
+}
+
+- (void)dealloc
+{
+ [_name release];
+ [super dealloc];
+}
+
+- (id)initWithName:(NSString *)name
+{
+ self = [super init];
+ if (self) {
+ _name = [name retain];
+ }
+ return self;
+}
+
+// =============================================================================
+#pragma mark - <GRMustacheVariableTagHelper>
+
+- (NSString *)renderForVariableTagInContext:(GRMustacheVariableTagRenderingContext *)context
+{
+ NSError *error;
+ NSString *rendering = [context renderTemplateNamed:_name error:&error];
+ if (!rendering) {
+ [NSException raise:GRMustacheRenderingException format:@"%@", [error localizedDescription]];
+ }
+ return rendering;
+}
+
+@end
+
+
View
16 src/classes/GRMustacheSection.h
@@ -29,13 +29,14 @@
*
* You will be provided with GRMustacheSection objects when implementing
* mustache lambda sections with objects conforming to the
- * GRMustacheSectionHelper protocol.
+ * deprecated GRMustacheSectionHelper protocol.
*
- * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/section_helpers.md
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/section_tag_helpers.md
*
- * @see GRMustacheSectionHelper protocol
+ * @see GRMustacheSectionTagHelper
*
* @since v1.3
+ * @deprecated v5.3
*/
@interface GRMustacheSection: NSObject {
@private
@@ -54,8 +55,9 @@
* `{{tags}}`.
*
* @since v2.0
+ * @deprecated v5.3
*/
-@property (nonatomic, readonly) NSString *innerTemplateString AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
+@property (nonatomic, readonly) NSString *innerTemplateString AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3;
////////////////////////////////////////////////////////////////////////////////
@@ -68,8 +70,9 @@
* @return A string containing the rendered inner content.
*
* @since v2.0
+ * @deprecated v5.3
*/
-- (NSString *)render AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
+- (NSString *)render AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3;
////////////////////////////////////////////////////////////////////////////////
@@ -87,7 +90,8 @@
* @return A string containing the rendering of the template string.
*
* @since v4.3
+ * @deprecated v5.3
*/
-- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
+- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3;
@end
View
24 src/classes/GRMustacheSectionElement.m
@@ -22,13 +22,18 @@
#import "GRMustacheSectionElement_private.h"
#import "GRMustacheExpression_private.h"
-#import "GRMustacheSectionHelper.h"
+#import "GRMustacheSectionTagHelper.h"
#import "GRMustacheRenderingElement_private.h"
#import "GRMustacheTemplate_private.h"
-#import "GRMustacheSection_private.h"
+#import "GRMustacheSectionTagRenderingContext_private.h"
#import "GRMustacheTemplateDelegate.h"
#import "GRMustacheRuntime_private.h"
+// Compatibility with deprecated declarations
+
+#import "GRMustacheSectionHelper.h"
+#import "GRMustacheSection_private.h"
+
@interface GRMustacheSectionElement()
@property (nonatomic, retain, readonly) GRMustacheExpression *expression;
@@ -75,7 +80,7 @@ - (void)renderInnerElementsInBuffer:(NSMutableString *)buffer withRuntime:(GRMus
- (void)renderInBuffer:(NSMutableString *)buffer withRuntime:(GRMustacheRuntime *)runtime
{
id value = [_expression evaluateInRuntime:runtime asFilterValue:NO];
- [runtime delegateValue:value interpretation:GRMustacheInterpretationSection forRenderingToken:_expression.token usingBlock:^(id value) {
+ [runtime delegateValue:value interpretation:GRMustacheSectionTagInterpretation forRenderingToken:_expression.token usingBlock:^(id value) {
GRMustacheRuntime *sectionRuntime = runtime;
@@ -137,6 +142,19 @@ - (void)renderInBuffer:(NSMutableString *)buffer withRuntime:(GRMustacheRuntime
}
return;
}
+ else if ([value conformsToProtocol:@protocol(GRMustacheSectionTagHelper)])
+ {
+ // Helper
+ if (!_inverted) {
+ GRMustacheRuntime *helperRuntime = [sectionRuntime runtimeByAddingContextObject:value];
+ GRMustacheSectionTagRenderingContext *context = [GRMustacheSectionTagRenderingContext contextWithSectionElement:self runtime:helperRuntime];
+ NSString *rendering = [(id<GRMustacheSectionTagHelper>)value renderForSectionTagInContext:context];
+ if (rendering) {
+ [buffer appendString:rendering];
+ }
+ }
+ return;
+ }
else if ([value conformsToProtocol:@protocol(GRMustacheSectionHelper)])
{
// Helper
View
13 src/classes/GRMustacheSectionElement_private.h
@@ -69,16 +69,17 @@
* runtime.
* @param templateRepository A Template repository that allows helpers to
* render alternate template strings through
- * GRMustacheSection objects.
+ * GRMustacheSectionTagRenderingContext objects.
* @param templateString A Mustache template string
* @param innerRange The range of the inner template string of the
* section in _templateString_, that allows helpers
* to get the section's inner template string through
- * GRMustacheSection objects.
+ * GRMustacheSectionTagRenderingContext objects.
* @param inverted YES if the section is {{^inverted}}.
* Otherwise, NO.
- * @param overridable YES if the section can override a super template
- * section.
+ * @param overridable YES if the section can override another section,
+ * or be overriden, in the context of overridable
+ * partials.
* @param innerElements An array of GRMustacheRenderingElement that make
* the section.
*
@@ -86,10 +87,10 @@
*
* @see GRMustacheExpression
* @see GRMustacheRuntime
- * @see GRMustacheSection
+ * @see GRMustacheSectionTagRenderingContext
* @see GRMustacheTemplateRepository
* @see GRMustacheRuntime
- * @see GRMustacheSectionHelper protocol
+ * @see GRMustacheSectionTagHelper protocol
*/
+ (id)sectionElementWithExpression:(GRMustacheExpression *)expression templateRepository:(GRMustacheTemplateRepository *)templateRepository templateString:(NSString *)templateString innerRange:(NSRange)innerRange inverted:(BOOL)inverted overridable:(BOOL)overridable innerElements:(NSArray *)innerElements GRMUSTACHE_API_INTERNAL;
View
22 src/classes/GRMustacheSectionHelper.h
@@ -30,7 +30,9 @@
#pragma mark - <GRMustacheSectionHelper>
/**
- * The protocol for implementing Mustache "lambda" sections.
+ * Deprecated protocol. Use GRMustacheSectionTagHelper protocol instead.
+ *
+ * The deprecated protocol for implementing Mustache "lambda" sections.
*
* The responsability of a GRMustacheSectionHelper is to render a Mustache
* section such as `{{#bold}}...{{/bold}}`.
@@ -39,9 +41,12 @@
* GRMustache invokes the `renderSection:` method of the helper, and inserts the
* raw return value in the template rendering.
*
- * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/section_helpers.md
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/section_tag_helpers.md
*
* @since v1.9
+ * @deprecated v5.3
+ *
+ * @see GRMustacheSectionTagHelper
*/
@protocol GRMustacheSectionHelper<NSObject>
@required
@@ -58,8 +63,9 @@
* @return The rendering of the section
*
* @since v2.0
+ * @deprecated v5.3
*/
-- (NSString *)renderSection:(GRMustacheSection *)section AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER;
+- (NSString *)renderSection:(GRMustacheSection *)section AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3;
@end
@@ -70,12 +76,13 @@
* The GRMustacheSectionHelper class helps building mustache helpers without
* writing a custom class that conforms to the GRMustacheSectionHelper protocol.
*
- * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/section_helpers.md
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/section_tag_helpers.md
*
* @see GRMustacheSectionHelper protocol
*
* @since v2.0
- */
+ * @deprecated v5.3
+ */
@interface GRMustacheSectionHelper: NSObject<GRMustacheSectionHelper>
////////////////////////////////////////////////////////////////////////////////
@@ -91,14 +98,15 @@
* @return a GRMustacheSectionHelper object.
*
* @since v2.0
+ * @deprecated v5.3
*/
-+ (id)helperWithBlock:(NSString *(^)(GRMustacheSection* section))block AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER;
++ (id)helperWithBlock:(NSString *(^)(GRMustacheSection* section))block AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3;
@end
// =============================================================================
-#pragma mark - Compatibility layer
+#pragma mark - Compatibility with deprecated declarations
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
View
3  src/classes/GRMustacheSectionHelper.m
@@ -103,7 +103,10 @@ @implementation GRMustacheHelper
+ (id)helperWithBlock:(NSString *(^)(GRMustacheSection* section))block
{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return [GRMustacheSectionHelper helperWithBlock:block];
+#pragma clang diagnostic pop
}
@end
View
98 src/classes/GRMustacheSectionTagHelper.h
@@ -0,0 +1,98 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+#import "GRMustacheAvailabilityMacros.h"
+
+@class GRMustacheSectionTagRenderingContext;
+
+
+// =============================================================================
+#pragma mark - <GRMustacheSectionTagHelper>
+
+/**
+ * The protocol for implementing Section tag helpers.
+ *
+ * The responsability of a GRMustacheSectionTagHelper is to render a Mustache
+ * section such as `{{#bold}}...{{/bold}}`.
+ *
+ * When the data given to a Mustache section is a GRMustacheSectionTagHelper,
+ * GRMustache invokes the `renderForSectionTagInContext:` method of the helper,
+ * and inserts the raw return value in the final rendering.
+ *
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/section_tag_helpers.md
+ *
+ * @since v1.9
+ */
+@protocol GRMustacheSectionTagHelper<NSObject>
+@required
+
+////////////////////////////////////////////////////////////////////////////////
+/// @name Rendering Sections
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Returns the rendering of a Mustache section.
+ *
+ * @param context A section tag rendering context
+ *
+ * @return The rendering of the section
+ *
+ * @since v2.0
+ */
+- (NSString *)renderForSectionTagInContext:(GRMustacheSectionTagRenderingContext *)context AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER;
+@end
+
+
+// =============================================================================
+#pragma mark - GRMustacheSectionTagHelper
+
+/**
+ * The GRMustacheSectionTagHelper class helps building mustache helpers without
+ * writing a custom class that conforms to the GRMustacheSectionTagHelper protocol.
+ *
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/section_tag_helpers.md
+ *
+ * @see GRMustacheSectionTagHelper protocol
+ *
+ * @since v2.0
+ */
+@interface GRMustacheSectionTagHelper: NSObject<GRMustacheSectionTagHelper>
+
+////////////////////////////////////////////////////////////////////////////////
+/// @name Creating Helpers
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Returns a GRMustacheSectionTagHelper object that executes the provided block
+ * when rendering a Mustache section.
+ *
+ * @param block The block that renders a section.
+ *
+ * @return a GRMustacheSectionTagHelper object.
+ *
+ * @since v2.0
+ */
++ (id)helperWithBlock:(NSString *(^)(GRMustacheSectionTagRenderingContext* context))block AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER;
+
+@end
+
View
97 src/classes/GRMustacheSectionTagHelper.m
@@ -0,0 +1,97 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import "GRMustacheSectionTagHelper.h"
+#import "GRMustacheSectionTagRenderingContext.h"
+
+
+// =============================================================================
+#pragma mark - Private concrete class GRMustacheBlockSectionTagHelper
+
+/**
+ * Private subclass of GRMustacheSectionTagHelper that render sections by calling
+ * a block.
+ */
+@interface GRMustacheBlockSectionTagHelper: GRMustacheSectionTagHelper {
+@private
+ NSString *(^_block)(GRMustacheSectionTagRenderingContext* context);
+}
+- (id)initWithBlock:(NSString *(^)(GRMustacheSectionTagRenderingContext* context))block;
+@end
+
+
+// =============================================================================
+#pragma mark - GRMustacheSectionTagHelper
+
+@implementation GRMustacheSectionTagHelper
+
++ (id)helperWithBlock:(NSString *(^)(GRMustacheSectionTagRenderingContext* context))block
+{
+ return [[[GRMustacheBlockSectionTagHelper alloc] initWithBlock:block] autorelease];
+}
+
+#pragma mark <GRMustacheSectionTagHelper>
+
+- (NSString *)renderForSectionTagInContext:(GRMustacheSectionTagRenderingContext *)context
+{
+ return [context render];
+}
+
+@end
+
+
+// =============================================================================
+#pragma mark - Private concrete class GRMustacheBlockSectionTagHelper
+
+@implementation GRMustacheBlockSectionTagHelper
+
+- (id)initWithBlock:(NSString *(^)(GRMustacheSectionTagRenderingContext* context))block
+{
+ self = [self init];
+ if (self) {
+ _block = [block copy];
+ }
+ return self;
+}
+
+
+- (void)dealloc
+{
+ [_block release];
+ [super dealloc];
+}
+
+#pragma mark <GRMustacheSectionTagHelper>
+
+- (NSString *)renderForSectionTagInContext:(GRMustacheSectionTagRenderingContext *)context
+{
+ NSString *rendering = nil;
+
+ if (_block) {
+ rendering = _block(context);
+ }
+
+ return rendering;
+}
+
+@end
+
View
90 src/classes/GRMustacheSectionTagRenderingContext.h
@@ -0,0 +1,90 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+#import "GRMustacheAvailabilityMacros.h"
+
+/**
+ * You will be provided with GRMustacheSectionTagRenderingContext objects when
+ * implementing variable tag helpers with objects conforming to the
+ * GRMustacheSectionTagHelper protocol.
+ *
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/section_tag_helpers.md
+ *
+ * @see GRMustacheSectionTagHelper protocol
+ *
+ * @since v1.3
+ */
+@interface GRMustacheSectionTagRenderingContext: NSObject {
+@private
+ id _sectionElement;
+ id _runtime;
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+/// @name Accessing the literal inner content
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * The literal inner content of the section, with unprocessed Mustache
+ * `{{tags}}`.
+ *
+ * @since v2.0
+ */
+@property (nonatomic, readonly) NSString *innerTemplateString AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER;
+
+
+////////////////////////////////////////////////////////////////////////////////
+/// @name Rendering the inner content
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Renders the inner content of the receiver with the current rendering context.
+ *
+ * @return A string containing the rendered inner content.
+ *
+ * @since v2.0
+ */
+- (NSString *)render AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER;
+
+
+////////////////////////////////////////////////////////////////////////////////
+/// @name Rendering another template string
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Renders a template string with the current rendering context.
+ *
+ * @param string A template string
+ * @param outError If there is an error loading or parsing template and
+ * partials, upon return contains an NSError object that
+ * describes the problem.
+ *
+ * @return A string containing the rendering of the template string.
+ *
+ * @since v4.3
+ */
+- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER;
+
+@end
View
81 src/classes/GRMustacheSectionTagRenderingContext.m
@@ -0,0 +1,81 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import "GRMustacheSectionTagRenderingContext_private.h"
+#import "GRMustacheSectionElement_private.h"
+#import "GRMustacheRuntime_private.h"
+#import "GRMustacheTemplate_private.h"
+#import "GRMustacheTemplateRepository_private.h"
+
+@interface GRMustacheSectionTagRenderingContext()
+- (id)initWithSectionElement:(GRMustacheSectionElement *)sectionElement runtime:(GRMustacheRuntime *)runtime;
+@end
+
+@implementation GRMustacheSectionTagRenderingContext
+
++ (id)contextWithSectionElement:(GRMustacheSectionElement *)sectionElement runtime:(GRMustacheRuntime *)runtime
+{
+ return [[[GRMustacheSectionTagRenderingContext alloc] initWithSectionElement:sectionElement runtime:runtime] autorelease];
+}
+
+- (void)dealloc
+{
+ [_sectionElement release];
+ [_runtime release];
+ [super dealloc];
+}
+
+- (id)initWithSectionElement:(GRMustacheSectionElement *)sectionElement runtime:(GRMustacheRuntime *)runtime
+{
+ self = [super init];
+ if (self) {
+ _sectionElement = [sectionElement retain];
+ _runtime = [runtime retain];
+ }
+ return self;
+}
+
+- (NSString *)render
+{
+ NSMutableString *buffer = [NSMutableString string];
+ [_sectionElement renderInnerElementsInBuffer:buffer withRuntime:_runtime];
+ return buffer;
+}
+
+- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError
+{
+ GRMustacheTemplate *template = [_sectionElement.templateRepository templateFromString:string error:outError];
+ if (!template) {
+ return nil;
+ }
+
+ NSMutableString *buffer = [NSMutableString string];
+ [template renderInBuffer:buffer withRuntime:_runtime];
+ return buffer;
+}
+
+- (NSString *)innerTemplateString
+{
+ return _sectionElement.innerTemplateString;
+}
+
+@end
View
58 src/classes/GRMustacheSectionTagRenderingContext_private.h
@@ -0,0 +1,58 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+#import "GRMustacheAvailabilityMacros_private.h"
+
+@class GRMustacheSectionElement;
+@class GRMustacheRuntime;
+
+// Documented in GRMustacheSectionTagRenderingContext.h
+@interface GRMustacheSectionTagRenderingContext: NSObject {
+@private
+ GRMustacheSectionElement *_sectionElement;
+ GRMustacheRuntime *_runtime;
+}
+
+// Documented in GRMustacheSectionTagRenderingContext.h
+@property (nonatomic, readonly) NSString *innerTemplateString GRMUSTACHE_API_PUBLIC;
+
+// Documented in GRMustacheSectionTagRenderingContext.h
+- (NSString *)render GRMUSTACHE_API_PUBLIC;
+
+// Documented in GRMustacheSectionTagRenderingContext.h
+- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError GRMUSTACHE_API_PUBLIC;
+
+/**
+ * Builds and returns a context suitable for GRMustacheSectionTagHelper.
+ *
+ * @param sectionElement The underlying sectionElement.
+ * @param runtime A runtime.
+ *
+ * @return A section rendering context.
+ *
+ * @see GRMustacheSectionTagHelper protocol
+ * @see GRMustacheSectionElement
+ * @see GRMustacheRuntime
+ */
++ (id)contextWithSectionElement:(GRMustacheSectionElement *)sectionElement runtime:(GRMustacheRuntime *)runtime GRMUSTACHE_API_INTERNAL;
+@end
View
6 src/classes/GRMustacheSection_private.h
@@ -34,13 +34,13 @@
}
// Documented in GRMustacheSection.h
-@property (nonatomic, readonly) NSString *innerTemplateString GRMUSTACHE_API_PUBLIC;
+@property (nonatomic, readonly) NSString *innerTemplateString GRMUSTACHE_API_PUBLIC_BUT_DEPRECATED;
// Documented in GRMustacheSection.h
-- (NSString *)render GRMUSTACHE_API_PUBLIC;
+- (NSString *)render GRMUSTACHE_API_PUBLIC_BUT_DEPRECATED;
// Documented in GRMustacheSection.h
-- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError GRMUSTACHE_API_PUBLIC;
+- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError GRMUSTACHE_API_PUBLIC_BUT_DEPRECATED;
/**
* Builds and returns a section suitable for GRMustacheSectionHelper.
View
41 src/classes/GRMustacheTemplateDelegate.h
@@ -37,24 +37,49 @@
*/
typedef enum {
/**
- * The value is interpreted for section rendering, such as
+ * The value is interpreted by a Mustache section tag such as
* `{{#name}}...{{/name}}`. Whether it is a NSNumber, an object conforming
* to the NSFastEnumeration protocol, an object conforming to the
- * GRMustacheSectionHelper protocol, or any other value, the section will
+ * GRMustacheSectionTagHelper protocol, or any other value, the section will
* render differently.
*
- * @since v4.1
+ * @since v5.3
+ */
+ GRMustacheSectionTagInterpretation = 0,
+
+ /**
+ * The value is interpreted by a Mustache variable tag such as `{{name}}`.
+ * Whether it is an object conforming to the GRMustacheVariableTagHelper
+ * protocol, or another object, the tag will render differently.
+ *
+ * @since v5.3
*/
- GRMustacheInterpretationSection,
+ GRMustacheVariableTagInterpretation,
+
+ // Deprecated values
+
+ /**
+ * The value is interpreted by a Mustache section tag such as
+ * `{{#name}}...{{/name}}`. Whether it is a NSNumber, an object conforming
+ * to the NSFastEnumeration protocol, an object conforming to the
+ * GRMustacheSectionTagHelper protocol, or any other value, the section will
+ * render differently.
+ *
+ * @since v4.1
+ * @deprecated v5.3
+ */
+ GRMustacheInterpretationSection AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3 = GRMustacheSectionTagInterpretation,
+
/**
- * The value is interpreted for variable substitution, for tags such as
- * `{{name}}`. Whether it is an object conforming to the GRMustacheVariable
- * protocol, or another object, the variable will render differently.
+ * The value is interpreted by a Mustache variable tag such as `{{name}}`.
+ * Whether it is an object conforming to the GRMustacheVariableTagHelper
+ * protocol, or another object, the tag will render differently.
*
* @since v4.1
+ * @deprecated v5.3
*/
- GRMustacheInterpretationVariable,
+ GRMustacheInterpretationVariable AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3 = GRMustacheVariableTagInterpretation,
} GRMustacheInterpretation;
View
13 src/classes/GRMustacheVariable.h
@@ -30,13 +30,14 @@
*
* You will be provided with GRMustacheVariable objects when implementing
* mustache lambda sections with objects conforming to the
- * GRMustacheVariableHelper protocol.
+ * deprecated GRMustacheVariableHelper protocol.
*
- * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/variable_helpers.md
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/variable_tag_helpers.md
*
- * @see GRMustacheVariableHelper protocol
+ * @see GRMustacheVariableTagHelper
*
* @since v5.1
+ * @deprecated v5.3
*/
@interface GRMustacheVariable : NSObject {
@private
@@ -55,8 +56,9 @@
* @return A string containing the rendering of the template string.
*
* @since v5.1
+ * @deprecated v5.3
*/
-- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER;
+- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3;
/**
@@ -70,7 +72,8 @@
* @return A string containing the rendering of the partial template.
*
* @since v5.1
+ * @deprecated v5.3
*/
-- (NSString *)renderTemplateNamed:(NSString *)name error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER;
+- (NSString *)renderTemplateNamed:(NSString *)name error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3;
@end
View
23 src/classes/GRMustacheVariableElement.m
@@ -21,14 +21,19 @@
// THE SOFTWARE.
#import "GRMustacheVariableElement_private.h"
-#import "GRMustacheVariableHelper.h"
-#import "GRMustacheVariable_private.h"
+#import "GRMustacheVariableTagHelper.h"
+#import "GRMustacheVariableTagRenderingContext_private.h"
#import "GRMustacheExpression_private.h"
#import "GRMustacheTemplate_private.h"
#import "GRMustacheRuntime_private.h"
#import "GRMustacheSectionElement_private.h"
#import "GRMustacheImplicitIteratorExpression_private.h"
+// Compatibility with deprecated declarations
+
+#import "GRMustacheVariableHelper.h"
+#import "GRMustacheVariable_private.h"
+
@interface GRMustacheVariableElement()
- (id)initWithExpression:(GRMustacheExpression *)expression templateRepository:(GRMustacheTemplateRepository *)templateRepository raw:(BOOL)raw;
- (NSString *)htmlEscape:(NSString *)string;
@@ -55,7 +60,7 @@ - (void)dealloc
- (void)renderInBuffer:(NSMutableString *)buffer withRuntime:(GRMustacheRuntime *)runtime
{
id value = [_expression evaluateInRuntime:runtime asFilterValue:NO];
- [runtime delegateValue:value interpretation:GRMustacheInterpretationVariable forRenderingToken:_expression.token usingBlock:^(id value) {
+ [runtime delegateValue:value interpretation:GRMustacheVariableTagInterpretation forRenderingToken:_expression.token usingBlock:^(id value) {
// Interpret value
@@ -83,6 +88,18 @@ - (void)renderInBuffer:(NSMutableString *)buffer withRuntime:(GRMustacheRuntime
}
[_enumerableSectionElement renderInBuffer:buffer withRuntime:runtime];
}
+ else if ([value conformsToProtocol:@protocol(GRMustacheVariableTagHelper)])
+ {
+ // Helper
+
+ GRMustacheRuntime *helperRuntime = [runtime runtimeByAddingContextObject:value];
+ GRMustacheVariableTagRenderingContext *context = [GRMustacheVariableTagRenderingContext contextWithTemplateRepository:_templateRepository runtime:helperRuntime];
+ NSString *rendering = [(id<GRMustacheVariableTagHelper>)value renderForVariableTagInContext:context];
+ if (rendering) {
+ // Never HTML escape helpers
+ [buffer appendString:rendering];
+ }
+ }
else if ([value conformsToProtocol:@protocol(GRMustacheVariableHelper)])
{
// Helper
View
2  src/classes/GRMustacheVariableElement_private.h
@@ -29,7 +29,7 @@
/**
* A GRMustacheVariableElement is a rendering element that renders variable
- * substitution tags such as `{{name}}` and `{{{name}}}`.
+ * tags such as `{{name}}` and `{{{name}}}`.
*
* For instance, the template string "{{name}} is {{age}} years old." would give
* two GRMustacheVariableElement instances:
View
52 src/classes/GRMustacheVariableHelper.h
@@ -30,7 +30,9 @@
#pragma mark - <GRMustacheVariableHelper>
/**
- * The protocol for implementing Mustache "lambda" variable tags.
+ * Deprecated protocol. Use GRMustacheVariableTagHelper protocol instead.
+ *
+ * The deprecated protocol for implementing Mustache "lambda" variable tags.
*
* The responsability of a GRMustacheVariableHelper is to render a Mustache
* variable tag such as `{{name}}`.
@@ -39,9 +41,12 @@
* GRMustache invokes the `renderVariable:` method of the helper, and inserts
* the raw return value in the template rendering.
*
- * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/variable_helpers.md
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/variable_tag_helpers.md
*
* @since v5.1
+ * @deprecated v5.3
+ *
+ * @see GRMustacheVariableTagHelper
*/
@protocol GRMustacheVariableHelper<NSObject>
@required
@@ -58,8 +63,9 @@
* @return The rendering of the variable
*
* @since v5.1
+ * @deprecated v5.3
*/
-- (NSString *)renderVariable:(GRMustacheVariable *)variable AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER;
+- (NSString *)renderVariable:(GRMustacheVariable *)variable AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3;
@end
@@ -71,11 +77,12 @@
* writing a custom class that conforms to the GRMustacheVariableHelper
* protocol.
*
- * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/variable_helpers.md
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/variable_tag_helpers.md
*
* @see GRMustacheVariableHelper protocol
*
* @since v5.1
+ * @deprecated v5.3
*/
@interface GRMustacheVariableHelper: NSObject<GRMustacheVariableHelper>
@@ -93,42 +100,7 @@
*
* @since v5.1
*/
-+ (id)helperWithBlock:(NSString *(^)(GRMustacheVariable* variable))block AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER;
++ (id)helperWithBlock:(NSString *(^)(GRMustacheVariable* variable))block AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER_BUT_DEPRECATED_IN_GRMUSTACHE_VERSION_5_3;
@end
-
-// =============================================================================
-#pragma mark - GRMustacheDynamicPartial
-
-/**
- * The GRMustacheDynamicPartial is a specific kind of GRMustacheVariableHelper
- * that, given a partial template name, renders this template.
- *
- * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/variable_helpers.md
- *
- * @see GRMustacheVariableHelper protocol
- *
- * @since v5.1
- */
-@interface GRMustacheDynamicPartial: NSObject<GRMustacheVariableHelper> {
- NSString *_name;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// @name Creating Dynamic Partials
-////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Returns a GRMustacheDynamicPartial that renders a partial template named
- * _name_.
- *
- * @param name A template name
- *
- * @return a GRMustacheDynamicPartial
- *
- * @since v5.1
- */
-+ (id)dynamicPartialWithName:(NSString *)name AVAILABLE_GRMUSTACHE_VERSION_5_1_AND_LATER;
-
-@end
View
44 src/classes/GRMustacheVariableHelper.m
@@ -61,50 +61,6 @@ - (NSString *)renderVariable:(GRMustacheVariable *)variable
// =============================================================================
-#pragma mark - GRMustacheDynamicPartial
-
-@interface GRMustacheDynamicPartial()
-- (id)initWithName:(NSString *)name;
-@end
-
-@implementation GRMustacheDynamicPartial
-
-+ (id)dynamicPartialWithName:(NSString *)name
-{
- return [[[GRMustacheDynamicPartial alloc] initWithName:name] autorelease];
-}
-
-- (void)dealloc
-{
- [_name release];
- [super dealloc];
-}
-
-- (id)initWithName:(NSString *)name
-{
- self = [super init];
- if (self) {
- _name = [name retain];
- }
- return self;
-}
-
-#pragma mark <GRMustacheVariableHelper>
-
-- (NSString *)renderVariable:(GRMustacheVariable *)variable
-{
- NSError *error;
- NSString *rendering = [variable renderTemplateNamed:_name error:&error];
- if (!rendering) {
- [NSException raise:GRMustacheRenderingException format:@"%@", [error localizedDescription]];
- }
- return rendering;
-}
-
-@end
-
-
-// =============================================================================
#pragma mark - Private concrete class GRMustacheBlockVariableHelper
@implementation GRMustacheBlockVariableHelper
View
98 src/classes/GRMustacheVariableTagHelper.h
@@ -0,0 +1,98 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+#import "GRMustacheAvailabilityMacros.h"
+
+@class GRMustacheVariableTagRenderingContext;
+
+
+// =============================================================================
+#pragma mark - <GRMustacheVariableTagHelper>
+
+/**
+ * The protocol for implementing Mustache "lambda" variable tags.
+ *
+ * The responsability of a GRMustacheVariableTagHelper is to render a Mustache
+ * variable tag such as `{{name}}`.
+ *
+ * When the data given to a Mustache variable tag is a GRMustacheVariableTagHelper,
+ * GRMustache invokes the `renderForVariableTagInContext:` method of the helper,
+ * and inserts the raw return value in the final rendering.
+ *
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/variable_tag_helpers.md
+ *
+ * @since v5.1
+ */
+@protocol GRMustacheVariableTagHelper<NSObject>
+@required
+
+////////////////////////////////////////////////////////////////////////////////
+/// @name Rendering Variable tags
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Returns the rendering of a Mustache variable tag.
+ *
+ * @param context A variable tag rendering context
+ *
+ * @return The rendering of the variable tag
+ *
+ * @since v5.1
+ */
+- (NSString *)renderForVariableTagInContext:(GRMustacheVariableTagRenderingContext *)context AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER;
+@end
+
+
+// =============================================================================
+#pragma mark - GRMustacheVariableTagHelper
+
+/**
+ * The GRMustacheVariableTagHelper class helps building mustache helpers without
+ * writing a custom class that conforms to the GRMustacheVariableTagHelper
+ * protocol.
+ *
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/variable_tag_helpers.md
+ *
+ * @see GRMustacheVariableTagHelper protocol
+ *
+ * @since v5.1
+ */
+@interface GRMustacheVariableTagHelper: NSObject<GRMustacheVariableTagHelper>
+
+////////////////////////////////////////////////////////////////////////////////
+/// @name Creating Helpers
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Returns a GRMustacheVariableTagHelper object that executes the provided block
+ * when rendering a variable tag.
+ *
+ * @param block The block that renders a variable tag.
+ *
+ * @return a GRMustacheVariableTagHelper object.
+ *
+ * @since v5.1
+ */
++ (id)helperWithBlock:(NSString *(^)(GRMustacheVariableTagRenderingContext* context))block AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER;
+
+@end
View
99 src/classes/GRMustacheVariableTagHelper.m
@@ -0,0 +1,99 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import "GRMustacheVariableTagHelper.h"
+#import "GRMustacheVariableTagRenderingContext.h"
+#import "GRMustacheError.h"
+
+
+// =============================================================================
+#pragma mark - Private concrete class GRMustacheBlockVariableTagHelper
+
+/**
+ * Private subclass of GRMustacheVariableTagHelper that render variable tags by
+ * calling a block.
+ */
+@interface GRMustacheBlockVariableTagHelper: GRMustacheVariableTagHelper {
+@private
+ NSString *(^_block)(GRMustacheVariableTagRenderingContext* context);
+}
+- (id)initWithBlock:(NSString *(^)(GRMustacheVariableTagRenderingContext* context))block;
+@end
+
+
+// =============================================================================
+#pragma mark - GRMustacheVariableTagHelper
+
+@implementation GRMustacheVariableTagHelper
+
++ (id)helperWithBlock:(NSString *(^)(GRMustacheVariableTagRenderingContext* context))block
+{
+ return [[[GRMustacheBlockVariableTagHelper alloc] initWithBlock:block] autorelease];
+}
+
+#pragma mark <GRMustacheVariableTagHelper>
+
+- (NSString *)renderForVariableTagInContext:(GRMustacheVariableTagRenderingContext *)context
+{
+ return [self description];
+}
+
+@end
+
+
+// =============================================================================
+#pragma mark - Private concrete class GRMustacheBlockVariableTagHelper
+
+@implementation GRMustacheBlockVariableTagHelper
+
+- (id)initWithBlock:(NSString *(^)(GRMustacheVariableTagRenderingContext* context))block
+{
+ self = [self init];
+ if (self) {
+ _block = [block copy];
+ }
+ return self;
+}
+
+
+- (void)dealloc
+{
+ [_block release];
+ [super dealloc];
+}
+
+#pragma mark <GRMustacheVariableTagHelper>
+
+- (NSString *)renderForVariableTagInContext:(GRMustacheVariableTagRenderingContext *)context
+{
+ NSString *rendering = nil;
+
+ if (_block) {
+ rendering = _block(context);
+ }
+
+ return rendering;
+}
+
+@end
+
+
View
74 src/classes/GRMustacheVariableTagRenderingContext.h
@@ -0,0 +1,74 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+#import "GRMustacheAvailabilityMacros.h"
+
+@class GRMustacheTemplateRepository;
+
+/**
+ * You will be provided with GRMustacheVariableTagRenderingContext objects when
+ * implementing variable tag helpers with objects conforming to the
+ * GRMustacheVariableTagHelper protocol.
+ *
+ * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/variable_tag_helpers.md
+ *
+ * @see GRMustacheVariableTagHelper protocol
+ *
+ * @since v5.1
+ */
+@interface GRMustacheVariableTagRenderingContext : NSObject {
+@private
+ GRMustacheTemplateRepository *_templateRepository;
+ id _runtime;
+}
+
+/**
+ * Renders a template string.
+ *
+ * @param string A template string
+ * @param outError If there is an error loading or parsing template and
+ * partials, upon return contains an NSError object that
+ * describes the problem.
+ *
+ * @return A string containing the rendering of the template string.
+ *
+ * @since v5.1
+ */
+- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER;
+
+
+/**
+ * Renders a partial template.
+ *
+ * @param name The name of the partial template.
+ * @param outError If there is an error loading or parsing template and
+ * partials, upon return contains an NSError object that
+ * describes the problem.
+ *
+ * @return A string containing the rendering of the partial template.
+ *
+ * @since v5.1
+ */
+- (NSString *)renderTemplateNamed:(NSString *)name error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_3_AND_LATER;
+
+@end
View
74 src/classes/GRMustacheVariableTagRenderingContext.m
@@ -0,0 +1,74 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import "GRMustacheVariableTagRenderingContext_private.h"
+#import "GRMustacheRuntime_private.h"
+#import "GRMustacheTemplate_private.h"
+#import "GRMustacheTemplateRepository_private.h"
+
+@interface GRMustacheVariableTagRenderingContext()
+- (id)initWithTemplateRepository:(GRMustacheTemplateRepository *)templateRepository runtime:(GRMustacheRuntime *)runtime;
+@end
+
+@implementation GRMustacheVariableTagRenderingContext
+
++ (id)contextWithTemplateRepository:(GRMustacheTemplateRepository *)templateRepository runtime:(GRMustacheRuntime *)runtime
+{
+ return [[[GRMustacheVariableTagRenderingContext alloc] initWithTemplateRepository:templateRepository runtime:runtime] autorelease];
+}
+
+- (void)dealloc
+{
+ [_templateRepository release];
+ [_runtime release];
+ [super dealloc];
+}
+
+- (id)initWithTemplateRepository:(GRMustacheTemplateRepository *)templateRepository runtime:(GRMustacheRuntime *)runtime
+{
+ self = [super init];
+ if (self) {
+ _templateRepository = [templateRepository retain];
+ _runtime = [runtime retain];
+ }
+ return self;
+}
+
+- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError
+{
+ GRMustacheTemplate *template = [_templateRepository templateFromString:string error:outError];
+ if (!template) {
+ return nil;
+ }
+
+ NSMutableString *buffer = [NSMutableString string];
+ [template renderInBuffer:buffer withRuntime:_runtime];
+ return buffer;
+}
+
+- (NSString *)renderTemplateNamed:(NSString *)name error:(NSError **)outError
+{
+ NSString *templateString = [NSString stringWithFormat:@"{{>%@}}", name];
+ return [self renderTemplateString:templateString error:outError];
+}
+
+@end
View
57 src/classes/GRMustacheVariableTagRenderingContext_private.h
@@ -0,0 +1,57 @@
+// The MIT License
+//
+// Copyright (c) 2012 Gwendal Roué
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+#import "GRMustacheAvailabilityMacros_private.h"
+
+@class GRMustacheTemplateRepository;
+@class GRMustacheRuntime;
+
+// Documented in GRMustacheVariableTagRenderingContext.h
+@interface GRMustacheVariableTagRenderingContext : NSObject {
+@private
+ GRMustacheTemplateRepository *_templateRepository;
+ GRMustacheRuntime *_runtime;
+}
+
+// Documented in GRMustacheVariableTagRenderingContext.h
+- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError GRMUSTACHE_API_PUBLIC;
+
+// Documented in GRMustacheVariableTagRenderingContext.h
+- (NSString *)renderTemplateNamed:(NSString *)name error:(NSError **)outError GRMUSTACHE_API_PUBLIC;
+
+/**
+ * Builds and returns a context suitable for GRMustacheVariableTagHelper.
+ *
+ * @param templateRepository A Template repository that allows helpers to
+ * render template strings through
+ * renderTemplateString:error: and
+ * renderTemplateNamed:error: methods.
+ * @param runtime A runtime.
+ *
+ * @return A variable tag rendering context.
+ *
+ * @see GRMustacheVariableTagHelper protocol
+ * @see GRMustacheRuntime
+ */
++ (id)contextWithTemplateRepository:(GRMustacheTemplateRepository *)templateRepository runtime:(GRMustacheRuntime *)runtime GRMUSTACHE_API_INTERNAL;
+@end
View
4 src/classes/GRMustacheVariable_private.h
@@ -34,10 +34,10 @@
}
// Documented in GRMustacheVariable.h
-- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError GRMUSTACHE_API_PUBLIC;
+- (NSString *)renderTemplateString:(NSString *)string error:(NSError **)outError GRMUSTACHE_API_PUBLIC_BUT_DEPRECATED;
// Documented in GRMustacheVariable.h
-- (NSString *)renderTemplateNamed:(NSString *)name error:(NSError **)outError GRMUSTACHE_API_PUBLIC;
+- (NSString *)renderTemplateNamed:(NSString *)name error:(NSError **)outError GRMUSTACHE_API_PUBLIC_BUT_DEPRECATED;
/**
* Builds and returns a variable suitable for GRMustacheVariableHelper.
View
89 ...lic/v5.0/GRMustacheTemplateDelegateTest.m → .../v5.0/GRMustacheTemplateDelegate5_0Test.m
@@ -23,10 +23,10 @@
#define GRMUSTACHE_VERSION_MAX_ALLOWED GRMUSTACHE_VERSION_5_0
#import "GRMustachePublicAPITest.h"
-@interface GRMustacheTemplateDelegateTest : GRMustachePublicAPITest
+@interface GRMustacheTemplateDelegate5_0Test : GRMustachePublicAPITest
@end
-@implementation GRMustacheTemplateDelegateTest
+@implementation GRMustacheTemplateDelegate5_0Test
- (void)testTemplateWillRenderIsCalledForTemplate
{
@@ -78,7 +78,7 @@ - (void)testTemplateWillRenderIsNotCalledForPartial
};
GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBundle:self.testBundle];
- GRMustacheTemplate *template = [repository templateFromString:@"{{>GRMustacheTemplateDelegateTest}}" error:NULL];
+ GRMustacheTemplate *template = [repository templateFromString:@"{{>GRMustacheTemplateDelegate5_0Test}}" error:NULL];
template.delegate = delegate;
[template render];
@@ -98,7 +98,7 @@ - (void)testTemplateDidRenderIsNotCalledForPartial
};
GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBundle:self.testBundle];
- GRMustacheTemplate *template = [repository templateFromString:@"{{>GRMustacheTemplateDelegateTest}}" error:NULL];
+ GRMustacheTemplate *template = [repository templateFromString:@"{{>GRMustacheTemplateDelegate5_0Test}}" error:NULL];
template.delegate = delegate;
[template render];
@@ -167,8 +167,8 @@ - (void)testInterpretReturnValueOfInvocationWithVariable
STAssertEqualObjects(rendering, @"---delegate---", @"");
STAssertEquals(preRenderingTemplate, template, @"", @"");
STAssertEquals(postRenderingTemplate, template, @"", @"");
- STAssertEquals(preRenderingInterpretation, GRMustacheInterpretationVariable, @"", @"");
- STAssertEquals(postRenderingInterpretation, GRMustacheInterpretationVariable, @"", @"");
+ STAssertEquals(preRenderingInterpretation, GRMustacheVariableTagInterpretation, @"", @"");
+ STAssertEquals(postRenderingInterpretation, GRMustacheVariableTagInterpretation, @"", @"");
STAssertEqualObjects(preRenderingValue, @"value", @"");
STAssertEqualObjects(postRenderingValue, @"delegate", @"");
}
@@ -201,8 +201,8 @@ - (void)testInterpretReturnValueOfInvocationWithUnrenderedSection
STAssertEqualObjects(rendering, @"<>", @"");
STAssertEquals(templateWillRenderCount, (NSUInteger)1, @"");
STAssertEquals(templateDidRenderCount, (NSUInteger)1, @"");
- STAssertEquals(preRenderingInterpretation, GRMustacheInterpretationSection, @"", @"");
- STAssertEquals(postRenderingInterpretation, GRMustacheInterpretationSection, @"", @"");
+ STAssertEquals(preRenderingInterpretation, GRMustacheSectionTagInterpretation, @"", @"");
+ STAssertEquals(postRenderingInterpretation, GRMustacheSectionTagInterpretation, @"", @"");
STAssertEquals(preRenderingTemplate, template, @"", @"");
STAssertEquals(postRenderingTemplate, template, @"", @"");
}
@@ -275,10 +275,10 @@ - (void)testInterpretReturnValueOfInvocationWithRenderedSectionContainingVariabl
STAssertEqualObjects(preRenderingValue2, (id)nil, @"");
STAssertEqualObjects(postRenderingValue1, @"delegate", @"");
STAssertEqualObjects(postRenderingValue2, @(YES), @"");
- STAssertEquals(preRenderingInterpretation1, GRMustacheInterpretationSection, @"", @"");
- STAssertEquals(preRenderingInterpretation2, GRMustacheInterpretationVariable, @"", @"");
- STAssertEquals(postRenderingInterpretation1, GRMustacheInterpretationVariable, @"", @"");
- STAssertEquals(postRenderingInterpretation2, GRMustacheInterpretationSection, @"", @"");
+ STAssertEquals(preRenderingInterpretation1, GRMustacheSectionTagInterpretation, @"", @"");
+ STAssertEquals(preRenderingInterpretation2, GRMustacheVariableTagInterpretation, @"", @"");
+ STAssertEquals(postRenderingInterpretation1, GRMustacheVariableTagInterpretation, @"", @"");
+ STAssertEquals(postRenderingInterpretation2, GRMustacheSectionTagInterpretation, @"", @"");
}
- (void)testDelegateInterpretsRenderedValue
@@ -535,12 +535,12 @@ - (void)testInvocationDescriptionContainsResourceBasedTemplatePath
description = [invocation description];
};
- GRMustacheTemplate *template = [GRMustacheTemplate templateFromResource:@"GRMustacheTemplateDelegateTest" bundle:self.testBundle error:NULL];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromResource:@"GRMustacheTemplateDelegate5_0Test" bundle:self.testBundle error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
{
@@ -551,12 +551,12 @@ - (void)testInvocationDescriptionContainsResourceBasedTemplatePath
};
GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBundle:self.testBundle];
- GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegateTest" error:NULL];
+ GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegate5_0Test" error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
}
@@ -570,12 +570,12 @@ - (void)testInvocationDescriptionContainsURLBasedTemplatePath
description = [invocation description];
};
- GRMustacheTemplate *template = [GRMustacheTemplate templateFromContentsOfURL:[self.testBundle URLForResource:@"GRMustacheTemplateDelegateTest" withExtension:@"mustache"] error:NULL];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromContentsOfURL:[self.testBundle URLForResource:@"GRMustacheTemplateDelegate5_0Test" withExtension:@"mustache"] error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
{
@@ -586,12 +586,12 @@ - (void)testInvocationDescriptionContainsURLBasedTemplatePath
};
GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBaseURL:[self.testBundle resourceURL]];
- GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegateTest" error:NULL];
+ GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegate5_0Test" error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
}
@@ -605,12 +605,12 @@ - (void)testInvocationDescriptionContainsPathBasedTemplatePath
description = [invocation description];
};
- GRMustacheTemplate *template = [GRMustacheTemplate templateFromContentsOfFile:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"] error:NULL];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromContentsOfFile:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"] error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
{
@@ -621,12 +621,12 @@ - (void)testInvocationDescriptionContainsPathBasedTemplatePath
};
GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithDirectory:[self.testBundle resourcePath]];
- GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegateTest" error:NULL];
+ GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegate5_0Test" error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
}
@@ -640,12 +640,12 @@ - (void)testInvocationDescriptionContainsResourceBasedPartialPath
description = [invocation description];
};
- GRMustacheTemplate *template = [GRMustacheTemplate templateFromResource:@"GRMustacheTemplateDelegateTest_wrapper" bundle:self.testBundle error:NULL];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromResource:@"GRMustacheTemplateDelegate5_0Test_wrapper" bundle:self.testBundle error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
{
@@ -656,12 +656,12 @@ - (void)testInvocationDescriptionContainsResourceBasedPartialPath
};
GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBundle:self.testBundle];
- GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegateTest_wrapper" error:NULL];
+ GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegate5_0Test_wrapper" error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
{
@@ -672,12 +672,12 @@ - (void)testInvocationDescriptionContainsResourceBasedPartialPath
};
GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBundle:self.testBundle];
- GRMustacheTemplate *template = [repository templateFromString:@"{{>GRMustacheTemplateDelegateTest}}" error:NULL];
+ GRMustacheTemplate *template = [repository templateFromString:@"{{>GRMustacheTemplateDelegate5_0Test}}" error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
}
@@ -691,12 +691,12 @@ - (void)testInvocationDescriptionContainsURLBasedPartialPath
description = [invocation description];
};
- GRMustacheTemplate *template = [GRMustacheTemplate templateFromContentsOfURL:[self.testBundle URLForResource:@"GRMustacheTemplateDelegateTest_wrapper" withExtension:@"mustache"] error:NULL];
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromContentsOfURL:[self.testBundle URLForResource:@"GRMustacheTemplateDelegate5_0Test_wrapper" withExtension:@"mustache"] error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
{
@@ -707,12 +707,12 @@ - (void)testInvocationDescriptionContainsURLBasedPartialPath
};
GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBaseURL:[self.testBundle resourceURL]];
- GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegateTest_wrapper" error:NULL];
+ GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegate5_0Test_wrapper" error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
{
@@ -723,12 +723,12 @@ - (void)testInvocationDescriptionContainsURLBasedPartialPath
};
GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBaseURL:[self.testBundle resourceURL]];
- GRMustacheTemplate *template = [repository templateFromString:@"{{>GRMustacheTemplateDelegateTest}}" error:NULL];
+ GRMustacheTemplate *template = [repository templateFromString:@"{{>GRMustacheTemplateDelegate5_0Test}}" error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
}
@@ -742,12 +742,13 @@ - (void)testInvocationDescriptionContainsPathBasedPartialPath
description = [invocation description];
};
- GRMustacheTemplate *template = [GRMustacheTemplate templateFromContentsOfFile:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest_wrapper" ofType:@"mustache"] error:NULL];
+ NSError *error;
+ GRMustacheTemplate *template = [GRMustacheTemplate templateFromContentsOfFile:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test_wrapper" ofType:@"mustache"] error:&error];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
{
@@ -758,12 +759,12 @@ - (void)testInvocationDescriptionContainsPathBasedPartialPath
};
GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithDirectory:[self.testBundle resourcePath]];
- GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegateTest_wrapper" error:NULL];
+ GRMustacheTemplate *template = [repository templateForName:@"GRMustacheTemplateDelegate5_0Test_wrapper" error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
{
@@ -774,12 +775,12 @@ - (void)testInvocationDescriptionContainsPathBasedPartialPath
};
GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithDirectory:[self.testBundle resourcePath]];
- GRMustacheTemplate *template = [repository templateFromString:@"{{>GRMustacheTemplateDelegateTest}}" error:NULL];
+ GRMustacheTemplate *template = [repository templateFromString:@"{{>GRMustacheTemplateDelegate5_0Test}}" error:NULL];
template.delegate = delegate;
[template render];
STAssertNotNil(description, @"");
- NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegateTest" ofType:@"mustache"]];
+ NSRange range = [description rangeOfString:[self.testBundle pathForResource:@"GRMustacheTemplateDelegate5_0Test" ofType:@"mustache"]];
STAssertTrue(range.location != NSNotFound, @"");
}
}
@@ -821,8 +822,8 @@ - (void)testSectionDelegate
STAssertEquals(templateDidRenderCount, (NSUInteger)0, @"");
STAssertEquals(preRenderingTemplate, template, @"");
STAssertEquals(postRenderingTemplate, template, @"");
- STAssertEquals(preRenderingInterpretation, GRMustacheInterpretationVariable, @"");
- STAssertEquals(postRenderingInterpretation, GRMustacheInterpretationVariable, @"");
+ STAssertEquals(preRenderingInterpretation, GRMustacheVariableTagInterpretation, @"");
+ STAssertEquals(postRenderingInterpretation, GRMustacheVariableTagInterpretation, @"");
STAssertEqualObjects(preRenderingValue, @"foo", @"");
STAssertEqualObjects(postRenderingValue, @"delegate", @"");
}
View
0  ...0/GRMustacheTemplateDelegateTest.mustache → ...RMustacheTemplateDelegate5_0Test.mustache
File renamed without changes
View
1  src/tests/Public/v5.0/GRMustacheTemplateDelegate5_0Test_wrapper.mustache
@@ -0,0 +1 @@
+{{>GRMustacheTemplateDelegate5_0Test}}
View
1  src/tests/Public/v5.0/GRMustacheTemplateDelegateTest_wrapper.mustache
@@ -1 +0,0 @@
-{{>GRMustacheTemplateDelegateTest}}
Please sign in to comment.
Something went wrong with that request. Please try again.