yellow-brick-road 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rst +10 -5
- data/lib/yellow-brick-road/directive_processor.rb +10 -3
- data/lib/yellow-brick-road/version.rb +1 -1
- data/test/dummy/app/assets/javascripts/closure-deps.js +3 -3
- data/test/dummy/log/development.log +159 -0
- data/test/dummy/tmp/cache/assets/C1E/0C0/sprockets%2F9c2f7430126aff8d8514326208712832 +165 -0
- data/test/dummy/tmp/cache/assets/C29/5D0/sprockets%2F1498f4451d0836a53c7c302c49920996 +0 -0
- data/test/dummy/tmp/cache/assets/C7E/9F0/sprockets%2F89862076204c62c4593ac20de32da909 +6 -6
- data/test/dummy/tmp/cache/assets/CB4/5B0/sprockets%2Ff17618b71eca9a4621f68626572a75b2 +103 -0
- data/test/dummy/tmp/cache/assets/CC2/240/sprockets%2F9f41da672330830c3366594f7ff5e7f6 +590 -0
- data/test/dummy/tmp/cache/assets/CC4/2C0/sprockets%2F715db78c7d974ea64406ed9711793f42 +494 -0
- data/test/dummy/tmp/cache/assets/CE1/610/sprockets%2F50c01109ecf86153176ccf577595fab4 +53 -0
- data/test/dummy/tmp/cache/assets/CE1/C20/sprockets%2F58a7b0499656c97a2204b5821eadab84 +207 -0
- data/test/dummy/tmp/cache/assets/CE4/DE0/sprockets%2Fb3aab0604ee02598f339965ec583a746 +204 -0
- data/test/dummy/tmp/cache/assets/CE9/B00/sprockets%2F80b139f66661444d6a781bfe56aee076 +0 -0
- data/test/dummy/tmp/cache/assets/CEB/840/sprockets%2F38fe57c2a5963f36a49404f672cc707b +0 -0
- data/test/dummy/tmp/cache/assets/CEC/6C0/sprockets%2F01b982295748dbd09683557aebd358bd +0 -0
- data/test/dummy/tmp/cache/assets/CF0/140/sprockets%2F3974b046fe949e86ef851a0271eb9d50 +1545 -0
- data/test/dummy/tmp/cache/assets/D01/DF0/sprockets%2F2ce268622b41a173bb209465a2ced6b9 +806 -0
- data/test/dummy/tmp/cache/assets/D05/920/sprockets%2F909507434dcc270db4853e4c147f0aac +4 -5
- data/test/dummy/tmp/cache/assets/D0A/C10/sprockets%2Fd050d5ee6a2073aa708a26c589a4c974 +283 -0
- data/test/dummy/tmp/cache/assets/D0F/360/sprockets%2Fa18927874a5e02c58c14c5b5df19ec04 +300 -0
- data/test/dummy/tmp/cache/assets/D15/700/sprockets%2F2987192f402d2bdc72792b5ae17f9a2f +142 -0
- data/test/dummy/tmp/cache/assets/D15/F60/sprockets%2Fa28394e3f80365b5bc86794dd46daa22 +0 -0
- data/test/dummy/tmp/cache/assets/D1F/E60/sprockets%2Fe65796b72231e36f5573ce71e2c8bbf8 +511 -0
- data/test/dummy/tmp/cache/assets/D22/200/sprockets%2F874bd1079c304ae88fbec8434d6d7794 +187 -0
- data/test/dummy/tmp/cache/assets/D3B/6A0/sprockets%2Ff8a978a3672b4f7ba513303b91ad15fc +127 -0
- data/test/dummy/tmp/cache/assets/D3C/530/sprockets%2Fe6730ff143273d9a7471b4afc3e1c19d +0 -0
- data/test/dummy/tmp/cache/assets/D41/B30/sprockets%2Fba1b93913dd01d83ac9a96df334456f8 +0 -0
- data/test/dummy/tmp/cache/assets/D49/570/sprockets%2Fd76be81d59871518ea06d3668f2c4bbb +239 -0
- data/test/dummy/tmp/cache/assets/D49/DA0/sprockets%2Fa84f85a305cde80a4d53785d7be0892f +457 -0
- data/test/dummy/tmp/cache/assets/D5C/760/sprockets%2F5cd491e0f9106cfd4ec4938896c97de7 +256 -0
- data/test/dummy/tmp/cache/assets/D5C/A00/sprockets%2Fefe291b3012745251e2641defbe4cad0 +1529 -0
- data/test/dummy/tmp/cache/assets/D68/2B0/sprockets%2Fe51ab0aca893e08c40f9672edef71106 +0 -0
- data/test/dummy/tmp/cache/assets/D6E/EA0/sprockets%2Fb52cbc47414c9e60ad4c46824928fbbe +115 -0
- data/test/dummy/tmp/cache/assets/D70/0B0/sprockets%2F1ae574bacfb86b4d51281b5e47fe1892 +505 -0
- data/test/dummy/tmp/cache/assets/D75/A60/sprockets%2Fab64285176f11f975fb6bb40af8bce76 +0 -0
- data/test/dummy/tmp/cache/assets/D76/0A0/sprockets%2F3ad3bd078c47096b34d5bcce886d7b47 +794 -0
- data/test/dummy/tmp/cache/assets/D79/C00/sprockets%2F94449fa386c370a1ebd7628eba9afe72 +72 -0
- data/test/dummy/tmp/cache/assets/D7B/310/sprockets%2Ff56e44be18b2d65efda80e588e5229a4 +0 -0
- data/test/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +7 -8
- data/test/dummy/tmp/cache/assets/D95/D20/sprockets%2F05b19351f203fb1eadf8ef1f0e6f9a60 +173 -0
- data/test/dummy/tmp/cache/assets/D9F/250/sprockets%2F40dcbb8f852f0e6360c4afb1f39964eb +0 -0
- data/test/dummy/tmp/cache/assets/DA8/0E0/sprockets%2F1351359f5bbdb94ef7d247df9af38bd1 +2556 -0
- data/test/dummy/tmp/cache/assets/DB3/070/sprockets%2Fd98f91680433cec456e6eb7485dcfdbc +522 -0
- data/test/dummy/tmp/cache/assets/DC4/6E0/sprockets%2F72117f09fccb98e6aac4cd1124edae42 +2539 -0
- data/test/dummy/tmp/cache/assets/DCC/D50/sprockets%2F9b2b027991c15af6f8afeacdd183c14e +1260 -0
- data/test/dummy/tmp/cache/assets/DD9/FF0/sprockets%2Fdf5dcfe86e199b272742a52a4b7e5fbd +823 -0
- data/test/dummy/tmp/cache/assets/DE7/0D0/sprockets%2Fe4d9fe29b6d96cdeb070d9b595af83d7 +1354 -0
- data/test/dummy/tmp/cache/assets/E00/3A0/sprockets%2Fc1db8cbfbc94bd2736f9f067a4c06cc7 +811 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E0C/C80/sprockets%2F55805edb5f27aaef88eef6632fd08ade +1277 -0
- data/test/dummy/tmp/cache/assets/E1B/CF0/sprockets%2Feb58b29b94f29d7da8d9fbe666e4a8dd +474 -0
- data/test/dummy/tmp/cache/assets/E1E/E00/sprockets%2Fb005d4fa3dc6cfc1c5098e0fdb3f6b2b +1371 -0
- data/test/dummy/tmp/cache/assets/E30/8E0/sprockets%2Fef4fdb83b3eefb027cbc8e19b274ec80 +607 -0
- metadata +96 -8
@@ -0,0 +1,494 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1325729947.977189:@value{ I"length:EFi�LI"digest;
|
2
|
+
F"%4f0a8e9b1528c6b0e7296c9651b2e0c3I"source;
|
3
|
+
FI"�L// Copyright 2009 The Closure Library Authors. All Rights Reserved.
|
4
|
+
//
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
// you may not use this file except in compliance with the License.
|
7
|
+
// You may obtain a copy of the License at
|
8
|
+
//
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
//
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
12
|
+
// distributed under the License is distributed on an "AS-IS" BASIS,
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
// See the License for the specific language governing permissions and
|
15
|
+
// limitations under the License.
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @fileoverview Utility for formatting text for display in a potentially
|
19
|
+
* opposite-directionality context without garbling.
|
20
|
+
* Mostly a port of http://go/formatter.cc.
|
21
|
+
*/
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
goog.provide('goog.i18n.BidiFormatter');
|
26
|
+
|
27
|
+
goog.require('goog.i18n.bidi');
|
28
|
+
goog.require('goog.string');
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Utility class for formatting text for display in a potentially
|
34
|
+
* opposite-directionality context without garbling. Provides the following
|
35
|
+
* functionality:
|
36
|
+
*
|
37
|
+
* 1. BiDi Wrapping
|
38
|
+
* When text in one language is mixed into a document in another, opposite-
|
39
|
+
* directionality language, e.g. when an English business name is embedded in a
|
40
|
+
* Hebrew web page, both the inserted string and the text following it may be
|
41
|
+
* displayed incorrectly unless the inserted string is explicitly separated
|
42
|
+
* from the surrounding text in a "wrapper" that declares its directionality at
|
43
|
+
* the start and then resets it back at the end. This wrapping can be done in
|
44
|
+
* HTML mark-up (e.g. a 'span dir=rtl' tag) or - only in contexts where mark-up
|
45
|
+
* can not be used - in Unicode BiDi formatting codes (LRE|RLE and PDF).
|
46
|
+
* Providing such wrapping services is the basic purpose of the BiDi formatter.
|
47
|
+
*
|
48
|
+
* 2. Directionality estimation
|
49
|
+
* How does one know whether a string about to be inserted into surrounding
|
50
|
+
* text has the same directionality? Well, in many cases, one knows that this
|
51
|
+
* must be the case when writing the code doing the insertion, e.g. when a
|
52
|
+
* localized message is inserted into a localized page. In such cases there is
|
53
|
+
* no need to involve the BiDi formatter at all. In the remaining cases, e.g.
|
54
|
+
* when the string is user-entered or comes from a database, the language of
|
55
|
+
* the string (and thus its directionality) is not known a priori, and must be
|
56
|
+
* estimated at run-time. The BiDi formatter does this automatically.
|
57
|
+
*
|
58
|
+
* 3. Escaping
|
59
|
+
* When wrapping plain text - i.e. text that is not already HTML or HTML-
|
60
|
+
* escaped - in HTML mark-up, the text must first be HTML-escaped to prevent XSS
|
61
|
+
* attacks and other nasty business. This of course is always true, but the
|
62
|
+
* escaping can not be done after the string has already been wrapped in
|
63
|
+
* mark-up, so the BiDi formatter also serves as a last chance and includes
|
64
|
+
* escaping services.
|
65
|
+
*
|
66
|
+
* Thus, in a single call, the formatter will escape the input string as
|
67
|
+
* specified, determine its directionality, and wrap it as necessary. It is
|
68
|
+
* then up to the caller to insert the return value in the output.
|
69
|
+
*
|
70
|
+
* See http://wiki/Main/TemplatesAndBiDi for more information.
|
71
|
+
*
|
72
|
+
* @param {goog.i18n.bidi.Dir|number|boolean} contextDir The context
|
73
|
+
* directionality. May be supplied either as a goog.i18n.bidi.Dir constant,
|
74
|
+
* as a number (positive = LRT, negative = RTL, 0 = unknown) or as a boolean
|
75
|
+
* (true = RTL, false = LTR).
|
76
|
+
* @param {boolean=} opt_alwaysSpan Whether {@link #spanWrap} should always
|
77
|
+
* use a 'span' tag, even when the input directionality is neutral or
|
78
|
+
* matches the context, so that the DOM structure of the output does not
|
79
|
+
* depend on the combination of directionalities. Default: false.
|
80
|
+
* @constructor
|
81
|
+
*/
|
82
|
+
goog.i18n.BidiFormatter = function(contextDir, opt_alwaysSpan) {
|
83
|
+
/**
|
84
|
+
* The overall directionality of the context in which the formatter is being
|
85
|
+
* used.
|
86
|
+
* @type {goog.i18n.bidi.Dir}
|
87
|
+
* @private
|
88
|
+
*/
|
89
|
+
this.contextDir_ = goog.i18n.bidi.toDir(contextDir);
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Whether {@link #spanWrap} and similar methods should always use the same
|
93
|
+
* span structure, regardless of the combination of directionalities, for a
|
94
|
+
* stable DOM structure.
|
95
|
+
* @type {boolean}
|
96
|
+
* @private
|
97
|
+
*/
|
98
|
+
this.alwaysSpan_ = !!opt_alwaysSpan;
|
99
|
+
};
|
100
|
+
|
101
|
+
|
102
|
+
/**
|
103
|
+
* @return {goog.i18n.bidi.Dir} The context directionality.
|
104
|
+
*/
|
105
|
+
goog.i18n.BidiFormatter.prototype.getContextDir = function() {
|
106
|
+
return this.contextDir_;
|
107
|
+
};
|
108
|
+
|
109
|
+
|
110
|
+
/**
|
111
|
+
* @return {boolean} Whether alwaysSpan is set.
|
112
|
+
*/
|
113
|
+
goog.i18n.BidiFormatter.prototype.getAlwaysSpan = function() {
|
114
|
+
return this.alwaysSpan_;
|
115
|
+
};
|
116
|
+
|
117
|
+
|
118
|
+
/**
|
119
|
+
* @param {goog.i18n.bidi.Dir|number|boolean} contextDir The context
|
120
|
+
* directionality. May be supplied either as a goog.i18n.bidi.Dir constant,
|
121
|
+
* as a number (positive = LRT, negative = RTL, 0 = unknown) or as a boolean
|
122
|
+
* (true = RTL, false = LTR).
|
123
|
+
*/
|
124
|
+
goog.i18n.BidiFormatter.prototype.setContextDir = function(contextDir) {
|
125
|
+
this.contextDir_ = goog.i18n.bidi.toDir(contextDir);
|
126
|
+
};
|
127
|
+
|
128
|
+
|
129
|
+
/**
|
130
|
+
* @param {boolean} alwaysSpan Whether {@link #spanWrap} should always use a
|
131
|
+
* 'span' tag, even when the input directionality is neutral or matches the
|
132
|
+
* context, so that the DOM structure of the output does not depend on the
|
133
|
+
* combination of directionalities.
|
134
|
+
*/
|
135
|
+
goog.i18n.BidiFormatter.prototype.setAlwaysSpan = function(alwaysSpan) {
|
136
|
+
this.alwaysSpan_ = alwaysSpan;
|
137
|
+
};
|
138
|
+
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Returns the directionality of input argument {@code str}.
|
142
|
+
* Identical to {@link goog.i18n.bidi.estimateDirection}.
|
143
|
+
*
|
144
|
+
* @param {string} str The input text.
|
145
|
+
* @param {boolean=} opt_isHtml Whether {@code str} is HTML / HTML-escaped.
|
146
|
+
* Default: false.
|
147
|
+
* @return {goog.i18n.bidi.Dir} Estimated overall directionality of {@code str}.
|
148
|
+
*/
|
149
|
+
goog.i18n.BidiFormatter.prototype.estimateDirection =
|
150
|
+
goog.i18n.bidi.estimateDirection;
|
151
|
+
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Returns true if two given directionalities are opposite.
|
155
|
+
* Note: the implementation is based on the numeric values of the Dir enum.
|
156
|
+
*
|
157
|
+
* @param {goog.i18n.bidi.Dir} dir1 1st directionality.
|
158
|
+
* @param {goog.i18n.bidi.Dir} dir2 2nd directionality.
|
159
|
+
* @return {boolean} Whether the directionalities are opposite.
|
160
|
+
* @private
|
161
|
+
*/
|
162
|
+
goog.i18n.BidiFormatter.prototype.areDirectionalitiesOpposite_ = function(dir1,
|
163
|
+
dir2) {
|
164
|
+
return dir1 * dir2 < 0;
|
165
|
+
};
|
166
|
+
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Returns a unicode BiDi mark matching the context directionality (LRM or
|
170
|
+
* RLM) if {@code opt_dirReset}, and if either the directionality or the exit
|
171
|
+
* directionality of {@code str} is opposite to the context directionality.
|
172
|
+
* Otherwise returns the empty string.
|
173
|
+
*
|
174
|
+
* @param {string} str The input text.
|
175
|
+
* @param {goog.i18n.bidi.Dir} dir {@code str}'s overall directionality.
|
176
|
+
* @param {boolean=} opt_isHtml Whether {@code str} is HTML / HTML-escaped.
|
177
|
+
* Default: false.
|
178
|
+
* @param {boolean=} opt_dirReset Whether to perform the reset. Default: false.
|
179
|
+
* @return {string} A unicode BiDi mark or the empty string.
|
180
|
+
* @private
|
181
|
+
*/
|
182
|
+
goog.i18n.BidiFormatter.prototype.dirResetIfNeeded_ = function(str, dir,
|
183
|
+
opt_isHtml, opt_dirReset) {
|
184
|
+
// endsWithRtl and endsWithLtr are called only if needed (short-circuit).
|
185
|
+
if (opt_dirReset &&
|
186
|
+
(this.areDirectionalitiesOpposite_(dir, this.contextDir_) ||
|
187
|
+
(this.contextDir_ == goog.i18n.bidi.Dir.LTR &&
|
188
|
+
goog.i18n.bidi.endsWithRtl(str, opt_isHtml)) ||
|
189
|
+
(this.contextDir_ == goog.i18n.bidi.Dir.RTL &&
|
190
|
+
goog.i18n.bidi.endsWithLtr(str, opt_isHtml)))) {
|
191
|
+
return this.contextDir_ == goog.i18n.bidi.Dir.LTR ?
|
192
|
+
goog.i18n.bidi.Format.LRM : goog.i18n.bidi.Format.RLM;
|
193
|
+
} else {
|
194
|
+
return '';
|
195
|
+
}
|
196
|
+
};
|
197
|
+
|
198
|
+
|
199
|
+
/**
|
200
|
+
* Returns "rtl" if {@code str}'s estimated directionality is RTL, and "ltr" if
|
201
|
+
* it is LTR. In case it's UNKNOWN, returns "rtl" if the context directionality
|
202
|
+
* is RTL, and "ltr" otherwise.
|
203
|
+
* Needed for GXP, which can't handle dirAttr.
|
204
|
+
* Example use case:
|
205
|
+
* <td expr:dir='bidiFormatter.dirAttrValue(foo)'><gxp:eval expr='foo'></td>
|
206
|
+
*
|
207
|
+
* @param {string} str Text whose directionality is to be estimated.
|
208
|
+
* @param {boolean=} opt_isHtml Whether {@code str} is HTML / HTML-escaped.
|
209
|
+
* Default: false.
|
210
|
+
* @return {string} "rtl" or "ltr", according to the logic described above.
|
211
|
+
*/
|
212
|
+
goog.i18n.BidiFormatter.prototype.dirAttrValue = function(str, opt_isHtml) {
|
213
|
+
return this.knownDirAttrValue(this.estimateDirection(str, opt_isHtml));
|
214
|
+
};
|
215
|
+
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Returns "rtl" if the given directionality is RTL, and "ltr" if it is LTR. In
|
219
|
+
* case it's UNKNOWN, returns "rtl" if the context directionality is RTL, and
|
220
|
+
* "ltr" otherwise.
|
221
|
+
*
|
222
|
+
* @param {goog.i18n.bidi.Dir} dir A directionality.
|
223
|
+
* @return {string} "rtl" or "ltr", according to the logic described above.
|
224
|
+
*/
|
225
|
+
goog.i18n.BidiFormatter.prototype.knownDirAttrValue = function(dir) {
|
226
|
+
if (dir == goog.i18n.bidi.Dir.UNKNOWN) {
|
227
|
+
dir = this.contextDir_;
|
228
|
+
}
|
229
|
+
|
230
|
+
return dir == goog.i18n.bidi.Dir.RTL ? 'rtl' : 'ltr';
|
231
|
+
};
|
232
|
+
|
233
|
+
|
234
|
+
/**
|
235
|
+
* Returns "dir=ltr" or "dir=rtl", depending on {@code str}'s estimated
|
236
|
+
* directionality, if it is not the same as the context directionality.
|
237
|
+
* Otherwise, returns the empty string.
|
238
|
+
*
|
239
|
+
* @param {string} str Text whose directionality is to be estimated.
|
240
|
+
* @param {boolean=} opt_isHtml Whether {@code str} is HTML / HTML-escaped.
|
241
|
+
* Default: false.
|
242
|
+
* @return {string} "dir=rtl" for RTL text in non-RTL context; "dir=ltr" for LTR
|
243
|
+
* text in non-LTR context; else, the empty string.
|
244
|
+
*/
|
245
|
+
goog.i18n.BidiFormatter.prototype.dirAttr = function(str, opt_isHtml) {
|
246
|
+
return this.knownDirAttr(this.estimateDirection(str, opt_isHtml));
|
247
|
+
};
|
248
|
+
|
249
|
+
|
250
|
+
/**
|
251
|
+
* Returns "dir=ltr" or "dir=rtl", depending on the given directionality, if it
|
252
|
+
* is not the same as the context directionality. Otherwise, returns the empty
|
253
|
+
* string.
|
254
|
+
*
|
255
|
+
* @param {goog.i18n.bidi.Dir} dir A directionality.
|
256
|
+
* @return {string} "dir=rtl" for RTL text in non-RTL context; "dir=ltr" for LTR
|
257
|
+
* text in non-LTR context; else, the empty string.
|
258
|
+
*/
|
259
|
+
goog.i18n.BidiFormatter.prototype.knownDirAttr = function(dir) {
|
260
|
+
if (dir != this.contextDir_) {
|
261
|
+
return dir == goog.i18n.bidi.Dir.RTL ? 'dir=rtl' :
|
262
|
+
dir == goog.i18n.bidi.Dir.LTR ? 'dir=ltr' : '';
|
263
|
+
}
|
264
|
+
return '';
|
265
|
+
};
|
266
|
+
|
267
|
+
|
268
|
+
/**
|
269
|
+
* Formats a string of unknown directionality for use in HTML output of the
|
270
|
+
* context directionality, so an opposite-directionality string is neither
|
271
|
+
* garbled nor garbles what follows it.
|
272
|
+
* The algorithm: estimates the directionality of input argument {@code str}. In
|
273
|
+
* case its directionality doesn't match the context directionality, wraps it
|
274
|
+
* with a 'span' tag and adds a "dir" attribute (either 'dir=rtl' or 'dir=ltr').
|
275
|
+
* If setAlwaysSpan(true) was used, the input is always wrapped with 'span',
|
276
|
+
* skipping just the dir attribute when it's not needed.
|
277
|
+
*
|
278
|
+
* If {@code opt_dirReset}, and if the overall directionality or the exit
|
279
|
+
* directionality of {@code str} are opposite to the context directionality, a
|
280
|
+
* trailing unicode BiDi mark matching the context directionality is appened
|
281
|
+
* (LRM or RLM).
|
282
|
+
*
|
283
|
+
* If !{@code opt_isHtml}, HTML-escapes {@code str} regardless of wrapping.
|
284
|
+
*
|
285
|
+
* @param {string} str The input text.
|
286
|
+
* @param {boolean=} opt_isHtml Whether {@code str} is HTML / HTML-escaped.
|
287
|
+
* Default: false.
|
288
|
+
* @param {boolean=} opt_dirReset Whether to append a trailing unicode bidi mark
|
289
|
+
* matching the context directionality, when needed, to prevent the possible
|
290
|
+
* garbling of whatever may follow {@code str}. Default: true.
|
291
|
+
* @return {string} Input text after applying the above processing.
|
292
|
+
*/
|
293
|
+
goog.i18n.BidiFormatter.prototype.spanWrap = function(str, opt_isHtml,
|
294
|
+
opt_dirReset) {
|
295
|
+
var dir = this.estimateDirection(str, opt_isHtml);
|
296
|
+
return this.spanWrapWithKnownDir(dir, str, opt_isHtml, opt_dirReset);
|
297
|
+
};
|
298
|
+
|
299
|
+
|
300
|
+
/**
|
301
|
+
* Formats a string of given directionality for use in HTML output of the
|
302
|
+
* context directionality, so an opposite-directionality string is neither
|
303
|
+
* garbled nor garbles what follows it.
|
304
|
+
* The algorithm: If {@code dir} doesn't match the context directionality, wraps
|
305
|
+
* {@code str} with a 'span' tag and adds a "dir" attribute (either 'dir=rtl' or
|
306
|
+
* 'dir=ltr'). If setAlwaysSpan(true) was used, the input is always wrapped with
|
307
|
+
* 'span', skipping just the dir attribute when it's not needed.
|
308
|
+
*
|
309
|
+
* If {@code opt_dirReset}, and if {@code dir} or the exit directionality of
|
310
|
+
* {@code str} are opposite to the context directionality, a trailing unicode
|
311
|
+
* BiDi mark matching the context directionality is appened (LRM or RLM).
|
312
|
+
*
|
313
|
+
* If !{@code opt_isHtml}, HTML-escapes {@code str} regardless of wrapping.
|
314
|
+
*
|
315
|
+
* @param {goog.i18n.bidi.Dir} dir {@code str}'s overall directionality.
|
316
|
+
* @param {string} str The input text.
|
317
|
+
* @param {boolean=} opt_isHtml Whether {@code str} is HTML / HTML-escaped.
|
318
|
+
* Default: false.
|
319
|
+
* @param {boolean=} opt_dirReset Whether to append a trailing unicode bidi mark
|
320
|
+
* matching the context directionality, when needed, to prevent the possible
|
321
|
+
* garbling of whatever may follow {@code str}. Default: true.
|
322
|
+
* @return {string} Input text after applying the above processing.
|
323
|
+
*/
|
324
|
+
goog.i18n.BidiFormatter.prototype.spanWrapWithKnownDir = function(dir, str,
|
325
|
+
opt_isHtml, opt_dirReset) {
|
326
|
+
opt_dirReset = opt_dirReset || (opt_dirReset == undefined);
|
327
|
+
// Whether to add the "dir" attribute.
|
328
|
+
var dirCondition = dir != goog.i18n.bidi.Dir.UNKNOWN && dir !=
|
329
|
+
this.contextDir_;
|
330
|
+
if (!opt_isHtml) {
|
331
|
+
str = goog.string.htmlEscape(str);
|
332
|
+
}
|
333
|
+
|
334
|
+
var result = [];
|
335
|
+
if (this.alwaysSpan_ || dirCondition) { // Wrap is needed
|
336
|
+
result.push('<span');
|
337
|
+
if (dirCondition) {
|
338
|
+
result.push(dir == goog.i18n.bidi.Dir.RTL ? ' dir=rtl' : ' dir=ltr');
|
339
|
+
}
|
340
|
+
result.push('>' + str + '</span>');
|
341
|
+
} else {
|
342
|
+
result.push(str);
|
343
|
+
}
|
344
|
+
|
345
|
+
result.push(this.dirResetIfNeeded_(str, dir, true, opt_dirReset));
|
346
|
+
return result.join('');
|
347
|
+
};
|
348
|
+
|
349
|
+
|
350
|
+
/**
|
351
|
+
* Formats a string of unknown directionality for use in plain-text output of
|
352
|
+
* the context directionality, so an opposite-directionality string is neither
|
353
|
+
* garbled nor garbles what follows it.
|
354
|
+
* As opposed to {@link #spanWrap}, this makes use of unicode BiDi formatting
|
355
|
+
* characters. In HTML, its *only* valid use is inside of elements that do not
|
356
|
+
* allow mark-up, e.g. an 'option' tag.
|
357
|
+
* The algorithm: estimates the directionality of input argument {@code str}.
|
358
|
+
* In case it doesn't match the context directionality, wraps it with Unicode
|
359
|
+
* BiDi formatting characters: RLE{@code str}PDF for RTL text, and
|
360
|
+
* LRE{@code str}PDF for LTR text.
|
361
|
+
*
|
362
|
+
* If {@code opt_dirReset}, and if the overall directionality or the exit
|
363
|
+
* directionality of {@code str} are opposite to the context directionality, a
|
364
|
+
* trailing unicode BiDi mark matching the context directionality is appended
|
365
|
+
* (LRM or RLM).
|
366
|
+
*
|
367
|
+
* Does *not* do HTML-escaping regardless of the value of {@code opt_isHtml}.
|
368
|
+
* The return value can be HTML-escaped as necessary.
|
369
|
+
*
|
370
|
+
* @param {string} str The input text.
|
371
|
+
* @param {boolean=} opt_isHtml Whether {@code str} is HTML / HTML-escaped.
|
372
|
+
* Default: false.
|
373
|
+
* @param {boolean=} opt_dirReset Whether to append a trailing unicode bidi mark
|
374
|
+
* matching the context directionality, when needed, to prevent the possible
|
375
|
+
* garbling of whatever may follow {@code str}. Default: true.
|
376
|
+
* @return {string} Input text after applying the above processing.
|
377
|
+
*/
|
378
|
+
goog.i18n.BidiFormatter.prototype.unicodeWrap = function(str, opt_isHtml,
|
379
|
+
opt_dirReset) {
|
380
|
+
var dir = this.estimateDirection(str, opt_isHtml);
|
381
|
+
return this.unicodeWrapWithKnownDir(dir, str, opt_isHtml, opt_dirReset);
|
382
|
+
};
|
383
|
+
|
384
|
+
|
385
|
+
/**
|
386
|
+
* Formats a string of given directionality for use in plain-text output of the
|
387
|
+
* context directionality, so an opposite-directionality string is neither
|
388
|
+
* garbled nor garbles what follows it.
|
389
|
+
* As opposed to {@link #spanWrapWithKnownDir}, makes use of unicode BiDi
|
390
|
+
* formatting characters. In HTML, its *only* valid use is inside of elements
|
391
|
+
* that do not allow mark-up, e.g. an 'option' tag.
|
392
|
+
* The algorithm: If {@code dir} doesn't match the context directionality, wraps
|
393
|
+
* {@code str} with Unicode BiDi formatting characters: RLE{@code str}PDF for
|
394
|
+
* RTL text, and LRE{@code str}PDF for LTR text.
|
395
|
+
*
|
396
|
+
* If {@code opt_dirReset}, and if the overall directionality or the exit
|
397
|
+
* directionality of {@code str} are opposite to the context directionality, a
|
398
|
+
* trailing unicode BiDi mark matching the context directionality is appended
|
399
|
+
* (LRM or RLM).
|
400
|
+
*
|
401
|
+
* Does *not* do HTML-escaping regardless of the value of {@code opt_isHtml}.
|
402
|
+
* The return value can be HTML-escaped as necessary.
|
403
|
+
*
|
404
|
+
* @param {goog.i18n.bidi.Dir} dir {@code str}'s overall directionality.
|
405
|
+
* @param {string} str The input text.
|
406
|
+
* @param {boolean=} opt_isHtml Whether {@code str} is HTML / HTML-escaped.
|
407
|
+
* Default: false.
|
408
|
+
* @param {boolean=} opt_dirReset Whether to append a trailing unicode bidi mark
|
409
|
+
* matching the context directionality, when needed, to prevent the possible
|
410
|
+
* garbling of whatever may follow {@code str}. Default: true.
|
411
|
+
* @return {string} Input text after applying the above processing.
|
412
|
+
*/
|
413
|
+
goog.i18n.BidiFormatter.prototype.unicodeWrapWithKnownDir = function(dir, str,
|
414
|
+
opt_isHtml, opt_dirReset) {
|
415
|
+
opt_dirReset = opt_dirReset || (opt_dirReset == undefined);
|
416
|
+
var result = [];
|
417
|
+
if (dir != goog.i18n.bidi.Dir.UNKNOWN && dir != this.contextDir_) {
|
418
|
+
result.push(dir == goog.i18n.bidi.Dir.RTL ? goog.i18n.bidi.Format.RLE :
|
419
|
+
goog.i18n.bidi.Format.LRE);
|
420
|
+
result.push(str);
|
421
|
+
result.push(goog.i18n.bidi.Format.PDF);
|
422
|
+
} else {
|
423
|
+
result.push(str);
|
424
|
+
}
|
425
|
+
|
426
|
+
result.push(this.dirResetIfNeeded_(str, dir, opt_isHtml, opt_dirReset));
|
427
|
+
return result.join('');
|
428
|
+
};
|
429
|
+
|
430
|
+
|
431
|
+
/**
|
432
|
+
* Returns a Unicode BiDi mark matching the context directionality (LRM or RLM)
|
433
|
+
* if the directionality or the exit directionality of {@code str} are opposite
|
434
|
+
* to the context directionality. Otherwise returns the empty string.
|
435
|
+
*
|
436
|
+
* @param {string} str The input text.
|
437
|
+
* @param {boolean=} opt_isHtml Whether {@code str} is HTML / HTML-escaped.
|
438
|
+
* Default: false.
|
439
|
+
* @return {string} A Unicode bidi mark matching the global directionality or
|
440
|
+
* the empty string.
|
441
|
+
*/
|
442
|
+
goog.i18n.BidiFormatter.prototype.markAfter = function(str, opt_isHtml) {
|
443
|
+
return this.dirResetIfNeeded_(str,
|
444
|
+
this.estimateDirection(str, opt_isHtml), opt_isHtml, true);
|
445
|
+
};
|
446
|
+
|
447
|
+
|
448
|
+
/**
|
449
|
+
* Returns the Unicode BiDi mark matching the context directionality (LRM for
|
450
|
+
* LTR context directionality, RLM for RTL context directionality), or the
|
451
|
+
* empty string for neutral / unknown context directionality.
|
452
|
+
*
|
453
|
+
* @return {string} LRM for LTR context directionality and RLM for RTL context
|
454
|
+
* directionality.
|
455
|
+
*/
|
456
|
+
goog.i18n.BidiFormatter.prototype.mark = function() {
|
457
|
+
switch (this.contextDir_) {
|
458
|
+
case (goog.i18n.bidi.Dir.LTR):
|
459
|
+
return goog.i18n.bidi.Format.LRM;
|
460
|
+
case (goog.i18n.bidi.Dir.RTL):
|
461
|
+
return goog.i18n.bidi.Format.RLM;
|
462
|
+
default:
|
463
|
+
return '';
|
464
|
+
}
|
465
|
+
};
|
466
|
+
|
467
|
+
|
468
|
+
/**
|
469
|
+
* Returns 'right' for RTL context directionality. Otherwise (LTR or neutral /
|
470
|
+
* unknown context directionality) returns 'left'.
|
471
|
+
*
|
472
|
+
* @return {string} 'right' for RTL context directionality and 'left' for other
|
473
|
+
* context directionality.
|
474
|
+
*/
|
475
|
+
goog.i18n.BidiFormatter.prototype.startEdge = function() {
|
476
|
+
return this.contextDir_ == goog.i18n.bidi.Dir.RTL ?
|
477
|
+
goog.i18n.bidi.RIGHT : goog.i18n.bidi.LEFT;
|
478
|
+
};
|
479
|
+
|
480
|
+
|
481
|
+
/**
|
482
|
+
* Returns 'left' for RTL context directionality. Otherwise (LTR or neutral /
|
483
|
+
* unknown context directionality) returns 'right'.
|
484
|
+
*
|
485
|
+
* @return {string} 'left' for RTL context directionality and 'right' for other
|
486
|
+
* context directionality.
|
487
|
+
*/
|
488
|
+
goog.i18n.BidiFormatter.prototype.endEdge = function() {
|
489
|
+
return this.contextDir_ == goog.i18n.bidi.Dir.RTL ?
|
490
|
+
goog.i18n.bidi.LEFT : goog.i18n.bidi.RIGHT;
|
491
|
+
};
|
492
|
+
;
|
493
|
+
FI"
|
494
|
+
F"%1b104aa2ee5bbf7451ef8006d26bb516
|