OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview This is a simple template engine inspired by JsTemplates | 6 * @fileoverview This is a simple template engine inspired by JsTemplates |
7 * optimized for i18n. | 7 * optimized for i18n. |
8 * | 8 * |
9 * It currently supports two handlers: | 9 * It currently supports two handlers: |
10 * | 10 * |
(...skipping 21 matching lines...) Expand all Loading... |
32 */ | 32 */ |
33 var handlers = { | 33 var handlers = { |
34 /** | 34 /** |
35 * This handler sets the textContent of the element. | 35 * This handler sets the textContent of the element. |
36 */ | 36 */ |
37 'i18n-content': function(element, attributeValue, obj) { | 37 'i18n-content': function(element, attributeValue, obj) { |
38 element.textContent = obj[attributeValue]; | 38 element.textContent = obj[attributeValue]; |
39 }, | 39 }, |
40 | 40 |
41 /** | 41 /** |
| 42 * This handler adds options to a select element. |
| 43 */ |
| 44 'i18n-options': function(element, attributeValue, obj) { |
| 45 var options = obj[attributeValue]; |
| 46 options.forEach(function(values) { |
| 47 var option = typeof values == 'string' ? new Option(values) : |
| 48 new Option(values[1], values[0]); |
| 49 element.appendChild(option); |
| 50 }); |
| 51 }, |
| 52 |
| 53 /** |
42 * This is used to set HTML attributes and DOM properties,. The syntax is: | 54 * This is used to set HTML attributes and DOM properties,. The syntax is: |
43 * attributename:key; | 55 * attributename:key; |
44 * .domProperty:key; | 56 * .domProperty:key; |
45 * .nested.dom.property:key | 57 * .nested.dom.property:key |
46 */ | 58 */ |
47 'i18n-values': function(element, attributeValue, obj) { | 59 'i18n-values': function(element, attributeValue, obj) { |
48 var parts = attributeValue.replace(/\s/g, '').split(/;/); | 60 var parts = attributeValue.replace(/\s/g, '').split(/;/); |
49 for (var j = 0; j < parts.length; j++) { | 61 for (var j = 0; j < parts.length; j++) { |
50 var a = parts[j].match(/^([^:]+):(.+)$/); | 62 var a = parts[j].match(/^([^:]+):(.+)$/); |
51 if (a) { | 63 if (a) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 handlers[name](element, att, obj); | 111 handlers[name](element, att, obj); |
100 } | 112 } |
101 } | 113 } |
102 } | 114 } |
103 } | 115 } |
104 | 116 |
105 return { | 117 return { |
106 process: process | 118 process: process |
107 }; | 119 }; |
108 })(); | 120 })(); |
OLD | NEW |