47
47
import java .util .Map .Entry ;
48
48
import java .util .Set ;
49
49
50
+ import com .github .jknack .handlebars .Decorator ;
50
51
import com .github .jknack .handlebars .Handlebars ;
51
52
import com .github .jknack .handlebars .Helper ;
52
53
import com .github .jknack .handlebars .HelperRegistry ;
@@ -64,8 +65,10 @@ public class DefaultHelperRegistry implements HelperRegistry {
64
65
/**
65
66
* The helper registry.
66
67
*/
67
- private final Map <String , Helper <?>> helpers =
68
- new HashMap <String , Helper <?>>();
68
+ private final Map <String , Helper <?>> helpers = new HashMap <String , Helper <?>>();
69
+
70
+ /** Decorators. */
71
+ private final Map <String , Decorator > decorators = new HashMap <>();
69
72
70
73
/**
71
74
* A Handlebars.js implementation.
@@ -222,7 +225,27 @@ private static void registerBuiltinsHelpers(final HelperRegistry registry) {
222
225
registry .registerHelper ("i18n" , I18nHelper .i18n );
223
226
registry .registerHelper ("i18nJs" , I18nHelper .i18nJs );
224
227
registry .registerHelper (LookupHelper .NAME , LookupHelper .INSTANCE );
225
- registry .registerHelper ("inline" , InlineHelper .INSTANCE );
228
+
229
+ // decorator
230
+ registry .registerDecorator ("inline" , InlineDecorator .INSTANCE );
231
+ }
232
+
233
+ @ Override
234
+ public Decorator decorator (final String name ) {
235
+ notEmpty (name , "A decorator's name is required." );
236
+ return decorators .get (name );
237
+ }
238
+
239
+ @ Override
240
+ public HelperRegistry registerDecorator (final String name , final Decorator decorator ) {
241
+ notEmpty (name , "A decorator's name is required." );
242
+ notNull (decorator , "A decorator is required." );
243
+
244
+ Decorator old = decorators .put (name , decorator );
245
+ if (old != null ) {
246
+ Handlebars .warn ("Decorator '%s' has been replaced by '%s'" , name , decorator );
247
+ }
248
+ return this ;
226
249
}
227
250
228
251
}
0 commit comments