diff options
Diffstat (limited to 'node_modules/montage/core/converter/new-line-to-br-converter.js')
-rwxr-xr-x | node_modules/montage/core/converter/new-line-to-br-converter.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/node_modules/montage/core/converter/new-line-to-br-converter.js b/node_modules/montage/core/converter/new-line-to-br-converter.js new file mode 100755 index 00000000..d64531e6 --- /dev/null +++ b/node_modules/montage/core/converter/new-line-to-br-converter.js | |||
@@ -0,0 +1,60 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | @module montage/core/converter/new-line-to-br-converter | ||
8 | @requires montage/core/core | ||
9 | @requires montage/core/converter/converter | ||
10 | */ | ||
11 | |||
12 | var Montage = require("montage").Montage; | ||
13 | var Converter = require('core/converter/converter').Converter; | ||
14 | |||
15 | /** | ||
16 | Replaces all new line characters with a HTML <br> | ||
17 | @memberof module:montage/core/converter# | ||
18 | @function | ||
19 | @param {String} str The string to format. | ||
20 | @returns {String} The formatted string. | ||
21 | */ | ||
22 | var newLineToBr = function(str) { | ||
23 | return str.replace(/(\r\n|\r|\n)/g, '<br />'); | ||
24 | }; | ||
25 | |||
26 | /** | ||
27 | @class module:montage/core/converter/new-line-to-br-converter.NewLineToBrConverter | ||
28 | @classdesc Converts a newline to a <br> tag. | ||
29 | */ | ||
30 | exports.NewLineToBrConverter = Montage.create(Converter, /** @lends module:montage/core/converter/new-line-to-br-converter.NewLineToBrConverter# */{ | ||
31 | |||
32 | /** | ||
33 | @private | ||
34 | */ | ||
35 | _convert: { | ||
36 | value: function(v) { | ||
37 | if (v && typeof v === 'string') { | ||
38 | return newLineToBr(v); | ||
39 | } | ||
40 | return v; | ||
41 | } | ||
42 | }, | ||
43 | /** | ||
44 | @function | ||
45 | @param {String} v Case format | ||
46 | @returns this._convert(v) | ||
47 | */ | ||
48 | convert: {value: function(v) { | ||
49 | return this._convert(v); | ||
50 | }}, | ||
51 | |||
52 | /** | ||
53 | @function | ||
54 | @param {String} v Case format | ||
55 | @returns this._convert(v) | ||
56 | */ | ||
57 | revert: {value: function(v) { | ||
58 | return this._convert(v); | ||
59 | }} | ||
60 | }); | ||