11/*
22 * The MIT License (MIT)
33 *
4- * Copyright 2016 Valentyn Kolesnikov
4+ * Copyright 2015-2017 Valentyn Kolesnikov
55 *
66 * Permission is hereby granted, free of charge, to any person obtaining a copy
77 * of this software and associated documentation files (the "Software"), to deal
@@ -230,47 +230,6 @@ public void template4() {
230230 $ .templateSettings (new HashMap <String , String >() { { put ("interpolate" , "<%=([\\ s\\ S]+?)%>" ); } });
231231 }
232232
233- /*
234- var list = "<% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>";
235- _.template(list, {people: ['moe', 'curly', 'larry']});
236- => "<li>moe</li><li>curly</li><li>larry</li>"
237- */
238- @ Test
239- public void templateEach () {
240- String list = "<% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>" ;
241- Template <Map <String , Object >> compiled = $ .template (list );
242- assertEquals (" <li>moe</li> <li>curly</li> <li>larry</li> " ,
243- compiled .apply (new LinkedHashMap <String , Object >() { {
244- put ("people" , asList ("moe" , "curly" , "larry" )); } }));
245- String list2 = "<% _.each(people2, function(name) { %> <li><%= name %></li> <% }); %>" ;
246- Template <Map <String , Object >> compiled2 = $ .template (list2 );
247- assertEquals ("<% _.each(people2, function(name) { %> <li><%= name %></li> <% }); %>" ,
248- compiled2 .apply (new LinkedHashMap <String , Object >() { {
249- put ("people" , asList ("moe" , "curly" , "larry" )); } }));
250- $ .templateSettings (new HashMap <String , String >() { { put ("interpolate" , "\\ {\\ {=([\\ s\\ S]+?)\\ }\\ }" );
251- put ("evaluate" , "\\ {\\ {([\\ s\\ S]+?)\\ }\\ }" ); } });
252- String list3 = "{{ _.each(people, function(name) { }} <li>{{= name }}</li> {{ }); }}" ;
253- Template <Map <String , Object >> compiled3 = $ .template (list3 );
254- assertEquals (" <li>moe</li> <li>curly</li> <li>larry</li> " ,
255- compiled3 .apply (new LinkedHashMap <String , Object >() { {
256- put ("people" , asList ("moe" , "curly" , "larry" )); } }));
257- $ .templateSettings (new HashMap <String , String >() { { put ("interpolate" , "<%=([\\ s\\ S]+?)%>" );
258- put ("evaluate" , "<%([\\ s\\ S]+?)%>" ); } });
259- }
260-
261- @ Test
262- public void templateEach2 () {
263- $ .templateSettings (new HashMap <String , String >() { { put ("interpolate" , "\\ $\\ {([\\ s\\ S]+?)\\ }" );
264- put ("evaluate" , "\\ {\\ {([\\ s\\ S]+?)\\ }\\ }" ); } });
265- String list = "{{ _.each(items, function(item) { }} <li>${ item }</li> {{ }); }}" ;
266- Template <Map <String , Object >> compiled3 = $ .template (list );
267- assertEquals (" <li>moe</li> <li>curly</li> <li>larry</li> " ,
268- compiled3 .apply (new LinkedHashMap <String , Object >() { {
269- put ("items" , asList ("moe" , "curly" , "larry" )); } }));
270- $ .templateSettings (new HashMap <String , String >() { { put ("interpolate" , "<%=([\\ s\\ S]+?)%>" );
271- put ("evaluate" , "<%([\\ s\\ S]+?)%>" ); } });
272- }
273-
274233/*
275234var template = _.template("<b><%- value %></b>");
276235template({value: '<script>'});
@@ -290,20 +249,6 @@ public void templateValue2() {
290249 template .apply (new LinkedHashMap <String , Object >() { {
291250 put ("name" , "moe" ); put ("value" , "<script>" ); } }));
292251 }
293- /*
294- var compiled = _.template("<% print('Hello ' + epithet); %>");
295- compiled({epithet: "stooge"});
296- => "Hello stooge"
297- */
298- @ Test
299- public void templatePrint () {
300- Template <Map <String , Object >> compiled = $ .template ("<% print('Hello ' + epithet); %>" );
301- assertEquals ("Hello stooge" ,
302- compiled .apply (new LinkedHashMap <String , Object >() { { put ("epithet" , "stooge" ); } }));
303- Template <Map <String , Object >> compiled2 = $ .template ("<% print('Hello ' + epithet2); %>" );
304- assertEquals ("<% print('Hello ' + epithet2); %>" ,
305- compiled2 .apply (new LinkedHashMap <String , Object >() { { put ("epithet" , "stooge" ); } }));
306- }
307252
308253/*
309254var object = {cheese: 'crumpets', stuff: function(){ return 'nonsense'; }};
0 commit comments