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 element.appendChild(new Option(values[1], values[0])); | |
arv (Not doing code reviews)
2011/01/07 22:24:16
I think we should support an array of strings as w
James Hawkins
2011/01/07 22:41:15
Done.
| |
48 }); | |
49 }, | |
50 | |
51 /** | |
42 * This is used to set HTML attributes and DOM properties,. The syntax is: | 52 * This is used to set HTML attributes and DOM properties,. The syntax is: |
43 * attributename:key; | 53 * attributename:key; |
44 * .domProperty:key; | 54 * .domProperty:key; |
45 * .nested.dom.property:key | 55 * .nested.dom.property:key |
46 */ | 56 */ |
47 'i18n-values': function(element, attributeValue, obj) { | 57 'i18n-values': function(element, attributeValue, obj) { |
48 var parts = attributeValue.replace(/\s/g, '').split(/;/); | 58 var parts = attributeValue.replace(/\s/g, '').split(/;/); |
49 for (var j = 0; j < parts.length; j++) { | 59 for (var j = 0; j < parts.length; j++) { |
50 var a = parts[j].match(/^([^:]+):(.+)$/); | 60 var a = parts[j].match(/^([^:]+):(.+)$/); |
51 if (a) { | 61 if (a) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 handlers[name](element, att, obj); | 109 handlers[name](element, att, obj); |
100 } | 110 } |
101 } | 111 } |
102 } | 112 } |
103 } | 113 } |
104 | 114 |
105 return { | 115 return { |
106 process: process | 116 process: process |
107 }; | 117 }; |
108 })(); | 118 })(); |
OLD | NEW |