polyblock 0.8.4 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 298a38958f28c29444340f358aee6ed9a42bf767
4
- data.tar.gz: c6502c06cbaadaab66a4e579a35e1dc8dd75f65a
3
+ metadata.gz: 0735618eca2f20bb1830d51da32632d3bd844c2b
4
+ data.tar.gz: 7213fc179a35c4c4766820679efaf1180c1394cd
5
5
  SHA512:
6
- metadata.gz: 192dfc9c14197b7133fe5c9d74af68412ae8be14b82bbf768996f772f422b547f0aa565c2d8ccc69daee61f0954dff1267b09cc9d85af2cf8d7e6285b2b57651
7
- data.tar.gz: 3a45d6dc912efcc770128e2314fb083a9ddb3bb75d44a586d516ec5e92b32c9cc1f184aa254a2693424423cde53f279b33b24bdab8db90054033e2e25a3cd20e
6
+ metadata.gz: 2cf28466ac12876a76d4b001d4d99d86780307bf63fd9406ae47c5f144e7c348bf9736e61682abf58b7176e733e012b821dbfe013ed9b53a50cff9db2cdaaa5e
7
+ data.tar.gz: 1fabe9680ca66fcb9586b995bfb79a39e29497a04603c19da46f3ceab066635ae5bc816db32d32e0e211dbff8c7cc3586b6819431b688baff1784b7c4cbb73f1
@@ -13,8 +13,6 @@
13
13
  //= require jquery
14
14
  //= require jquery_ujs
15
15
  //= require jquery-ui
16
- //= require underscore
17
- //= require underscore.string
18
16
  //= require beautify
19
17
  //= require beautify-css
20
18
  //= require beautify-html
@@ -38,7 +38,7 @@ jQuery ($)->
38
38
  blocks.each ->
39
39
  id = $(@).attr('id')
40
40
  blockclones[id] = $(@).clone()
41
- instanciateCKEditor(id) unless _.contains(_.keys(CKEDITOR.instances), id)
41
+ instanciateCKEditor(id) unless $.map(CKEDITOR.instances, (inst, key)-> key).indexOf(id) > -1
42
42
 
43
43
  # Wait for changes
44
44
  verbose = false
@@ -89,7 +89,7 @@ jQuery ($)->
89
89
  saveChanges = (cb)->
90
90
  stopListening()
91
91
  showSavingChanges()
92
- pbs = _.map blocks, (b)->
92
+ pbs = $.map blocks, (b, i)->
93
93
  {
94
94
  id: $(b).attr("data-pbid"),
95
95
  name: $(b).attr("data-pbname"),
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  module Polyblock
4
4
  class Block < ActiveRecord::Base
5
- attr_accessor :settings
5
+ attr_accessor :settings_cache
6
6
  DEFAULTS = {
7
7
  :association => {
8
8
  :class_name => "Polyblock::Block",
@@ -36,6 +36,11 @@ module Polyblock
36
36
  puts ""
37
37
  end
38
38
 
39
+ def settings
40
+ return settings_cache unless settings_cache.nil?
41
+ settings_cache = self.contentable.present? ? self.contentable.send(self.name).settings : DEFAULTS
42
+ end
43
+
39
44
  def to_s
40
45
  content
41
46
  end
@@ -87,7 +92,6 @@ module Polyblock
87
92
 
88
93
  private
89
94
  def strip_html_if_necessary
90
- self.settings ||= self.contentable.send(self.name).settings
91
95
  self.content = Block.strip_html(self.content) unless self.settings[:html] || self.content.nil?
92
96
  end
93
97
 
@@ -1,3 +1,3 @@
1
1
  module Polyblock
2
- VERSION = "0.8.4"
2
+ VERSION = "0.8.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyblock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - MacKinley Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2014-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: underscore-rails
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
139
  description: Polymorphic content blocks made simple.
154
140
  email:
155
141
  - smit1625@msu.edu
@@ -178,7 +164,6 @@ files:
178
164
  - app/assets/javascripts/polyblock/init.js
179
165
  - app/assets/javascripts/polyblock/polyblock.js.coffee
180
166
  - app/assets/javascripts/transit.js
181
- - app/assets/javascripts/underscore.string.js
182
167
  - app/assets/stylesheets/polyblock/application.css
183
168
  - app/assets/stylesheets/polyblock/polyblocks.css
184
169
  - app/controllers/polyblock/application_controller.rb
@@ -1,600 +0,0 @@
1
- // Underscore.string
2
- // (c) 2010 Esa-Matti Suuronen <esa-matti aet suuronen dot org>
3
- // Underscore.string is freely distributable under the terms of the MIT license.
4
- // Documentation: https://github.com/epeli/underscore.string
5
- // Some code is borrowed from MooTools and Alexandru Marasteanu.
6
- // Version '2.3.0'
7
-
8
- !function(root, String){
9
- 'use strict';
10
-
11
- // Defining helper functions.
12
-
13
- var nativeTrim = String.prototype.trim;
14
- var nativeTrimRight = String.prototype.trimRight;
15
- var nativeTrimLeft = String.prototype.trimLeft;
16
-
17
- var parseNumber = function(source) { return source * 1 || 0; };
18
-
19
- var strRepeat = function(str, qty){
20
- if (qty < 1) return '';
21
- var result = '';
22
- while (qty > 0) {
23
- if (qty & 1) result += str;
24
- qty >>= 1, str += str;
25
- }
26
- return result;
27
- };
28
-
29
- var slice = [].slice;
30
-
31
- var defaultToWhiteSpace = function(characters) {
32
- if (characters == null)
33
- return '\\s';
34
- else if (characters.source)
35
- return characters.source;
36
- else
37
- return '[' + _s.escapeRegExp(characters) + ']';
38
- };
39
-
40
- var escapeChars = {
41
- lt: '<',
42
- gt: '>',
43
- quot: '"',
44
- apos: "'",
45
- amp: '&'
46
- };
47
-
48
- var reversedEscapeChars = {};
49
- for(var key in escapeChars){ reversedEscapeChars[escapeChars[key]] = key; }
50
-
51
- // sprintf() for JavaScript 0.7-beta1
52
- // http://www.diveintojavascript.com/projects/javascript-sprintf
53
- //
54
- // Copyright (c) Alexandru Marasteanu <alexaholic [at) gmail (dot] com>
55
- // All rights reserved.
56
-
57
- var sprintf = (function() {
58
- function get_type(variable) {
59
- return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase();
60
- }
61
-
62
- var str_repeat = strRepeat;
63
-
64
- var str_format = function() {
65
- if (!str_format.cache.hasOwnProperty(arguments[0])) {
66
- str_format.cache[arguments[0]] = str_format.parse(arguments[0]);
67
- }
68
- return str_format.format.call(null, str_format.cache[arguments[0]], arguments);
69
- };
70
-
71
- str_format.format = function(parse_tree, argv) {
72
- var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length;
73
- for (i = 0; i < tree_length; i++) {
74
- node_type = get_type(parse_tree[i]);
75
- if (node_type === 'string') {
76
- output.push(parse_tree[i]);
77
- }
78
- else if (node_type === 'array') {
79
- match = parse_tree[i]; // convenience purposes only
80
- if (match[2]) { // keyword argument
81
- arg = argv[cursor];
82
- for (k = 0; k < match[2].length; k++) {
83
- if (!arg.hasOwnProperty(match[2][k])) {
84
- throw new Error(sprintf('[_.sprintf] property "%s" does not exist', match[2][k]));
85
- }
86
- arg = arg[match[2][k]];
87
- }
88
- } else if (match[1]) { // positional argument (explicit)
89
- arg = argv[match[1]];
90
- }
91
- else { // positional argument (implicit)
92
- arg = argv[cursor++];
93
- }
94
-
95
- if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) {
96
- throw new Error(sprintf('[_.sprintf] expecting number but found %s', get_type(arg)));
97
- }
98
- switch (match[8]) {
99
- case 'b': arg = arg.toString(2); break;
100
- case 'c': arg = String.fromCharCode(arg); break;
101
- case 'd': arg = parseInt(arg, 10); break;
102
- case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break;
103
- case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break;
104
- case 'o': arg = arg.toString(8); break;
105
- case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break;
106
- case 'u': arg = Math.abs(arg); break;
107
- case 'x': arg = arg.toString(16); break;
108
- case 'X': arg = arg.toString(16).toUpperCase(); break;
109
- }
110
- arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg);
111
- pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' ';
112
- pad_length = match[6] - String(arg).length;
113
- pad = match[6] ? str_repeat(pad_character, pad_length) : '';
114
- output.push(match[5] ? arg + pad : pad + arg);
115
- }
116
- }
117
- return output.join('');
118
- };
119
-
120
- str_format.cache = {};
121
-
122
- str_format.parse = function(fmt) {
123
- var _fmt = fmt, match = [], parse_tree = [], arg_names = 0;
124
- while (_fmt) {
125
- if ((match = /^[^\x25]+/.exec(_fmt)) !== null) {
126
- parse_tree.push(match[0]);
127
- }
128
- else if ((match = /^\x25{2}/.exec(_fmt)) !== null) {
129
- parse_tree.push('%');
130
- }
131
- else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) {
132
- if (match[2]) {
133
- arg_names |= 1;
134
- var field_list = [], replacement_field = match[2], field_match = [];
135
- if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) {
136
- field_list.push(field_match[1]);
137
- while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
138
- if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) {
139
- field_list.push(field_match[1]);
140
- }
141
- else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) {
142
- field_list.push(field_match[1]);
143
- }
144
- else {
145
- throw new Error('[_.sprintf] huh?');
146
- }
147
- }
148
- }
149
- else {
150
- throw new Error('[_.sprintf] huh?');
151
- }
152
- match[2] = field_list;
153
- }
154
- else {
155
- arg_names |= 2;
156
- }
157
- if (arg_names === 3) {
158
- throw new Error('[_.sprintf] mixing positional and named placeholders is not (yet) supported');
159
- }
160
- parse_tree.push(match);
161
- }
162
- else {
163
- throw new Error('[_.sprintf] huh?');
164
- }
165
- _fmt = _fmt.substring(match[0].length);
166
- }
167
- return parse_tree;
168
- };
169
-
170
- return str_format;
171
- })();
172
-
173
-
174
-
175
- // Defining underscore.string
176
-
177
- var _s = {
178
-
179
- VERSION: '2.3.0',
180
-
181
- isBlank: function(str){
182
- if (str == null) str = '';
183
- return (/^\s*$/).test(str);
184
- },
185
-
186
- stripTags: function(str){
187
- if (str == null) return '';
188
- return String(str).replace(/<\/?[^>]+>/g, '');
189
- },
190
-
191
- capitalize : function(str){
192
- str = str == null ? '' : String(str);
193
- return str.charAt(0).toUpperCase() + str.slice(1);
194
- },
195
-
196
- chop: function(str, step){
197
- if (str == null) return [];
198
- str = String(str);
199
- step = ~~step;
200
- return step > 0 ? str.match(new RegExp('.{1,' + step + '}', 'g')) : [str];
201
- },
202
-
203
- clean: function(str){
204
- return _s.strip(str).replace(/\s+/g, ' ');
205
- },
206
-
207
- count: function(str, substr){
208
- if (str == null || substr == null) return 0;
209
- return String(str).split(substr).length - 1;
210
- },
211
-
212
- chars: function(str) {
213
- if (str == null) return [];
214
- return String(str).split('');
215
- },
216
-
217
- swapCase: function(str) {
218
- if (str == null) return '';
219
- return String(str).replace(/\S/g, function(c){
220
- return c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase();
221
- });
222
- },
223
-
224
- escapeHTML: function(str) {
225
- if (str == null) return '';
226
- return String(str).replace(/[&<>"']/g, function(m){ return '&' + reversedEscapeChars[m] + ';'; });
227
- },
228
-
229
- unescapeHTML: function(str) {
230
- if (str == null) return '';
231
- return String(str).replace(/\&([^;]+);/g, function(entity, entityCode){
232
- var match;
233
-
234
- if (entityCode in escapeChars) {
235
- return escapeChars[entityCode];
236
- } else if (match = entityCode.match(/^#x([\da-fA-F]+)$/)) {
237
- return String.fromCharCode(parseInt(match[1], 16));
238
- } else if (match = entityCode.match(/^#(\d+)$/)) {
239
- return String.fromCharCode(~~match[1]);
240
- } else {
241
- return entity;
242
- }
243
- });
244
- },
245
-
246
- escapeRegExp: function(str){
247
- if (str == null) return '';
248
- return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
249
- },
250
-
251
- splice: function(str, i, howmany, substr){
252
- var arr = _s.chars(str);
253
- arr.splice(~~i, ~~howmany, substr);
254
- return arr.join('');
255
- },
256
-
257
- insert: function(str, i, substr){
258
- return _s.splice(str, i, 0, substr);
259
- },
260
-
261
- include: function(str, needle){
262
- if (needle === '') return true;
263
- if (str == null) return false;
264
- return String(str).indexOf(needle) !== -1;
265
- },
266
-
267
- join: function() {
268
- var args = slice.call(arguments),
269
- separator = args.shift();
270
-
271
- if (separator == null) separator = '';
272
-
273
- return args.join(separator);
274
- },
275
-
276
- lines: function(str) {
277
- if (str == null) return [];
278
- return String(str).split("\n");
279
- },
280
-
281
- reverse: function(str){
282
- return _s.chars(str).reverse().join('');
283
- },
284
-
285
- startsWith: function(str, starts){
286
- if (starts === '') return true;
287
- if (str == null || starts == null) return false;
288
- str = String(str); starts = String(starts);
289
- return str.length >= starts.length && str.slice(0, starts.length) === starts;
290
- },
291
-
292
- endsWith: function(str, ends){
293
- if (ends === '') return true;
294
- if (str == null || ends == null) return false;
295
- str = String(str); ends = String(ends);
296
- return str.length >= ends.length && str.slice(str.length - ends.length) === ends;
297
- },
298
-
299
- succ: function(str){
300
- if (str == null) return '';
301
- str = String(str);
302
- return str.slice(0, -1) + String.fromCharCode(str.charCodeAt(str.length-1) + 1);
303
- },
304
-
305
- titleize: function(str){
306
- if (str == null) return '';
307
- return String(str).replace(/(?:^|\s)\S/g, function(c){ return c.toUpperCase(); });
308
- },
309
-
310
- camelize: function(str){
311
- return _s.trim(str).replace(/[-_\s]+(.)?/g, function(match, c){ return c.toUpperCase(); });
312
- },
313
-
314
- underscored: function(str){
315
- return _s.trim(str).replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
316
- },
317
-
318
- dasherize: function(str){
319
- return _s.trim(str).replace(/([A-Z])/g, '-$1').replace(/[-_\s]+/g, '-').toLowerCase();
320
- },
321
-
322
- classify: function(str){
323
- return _s.titleize(String(str).replace(/_/g, ' ')).replace(/\s/g, '');
324
- },
325
-
326
- humanize: function(str){
327
- return _s.capitalize(_s.underscored(str).replace(/_id$/,'').replace(/_/g, ' '));
328
- },
329
-
330
- trim: function(str, characters){
331
- if (str == null) return '';
332
- if (!characters && nativeTrim) return nativeTrim.call(str);
333
- characters = defaultToWhiteSpace(characters);
334
- return String(str).replace(new RegExp('\^' + characters + '+|' + characters + '+$', 'g'), '');
335
- },
336
-
337
- ltrim: function(str, characters){
338
- if (str == null) return '';
339
- if (!characters && nativeTrimLeft) return nativeTrimLeft.call(str);
340
- characters = defaultToWhiteSpace(characters);
341
- return String(str).replace(new RegExp('^' + characters + '+'), '');
342
- },
343
-
344
- rtrim: function(str, characters){
345
- if (str == null) return '';
346
- if (!characters && nativeTrimRight) return nativeTrimRight.call(str);
347
- characters = defaultToWhiteSpace(characters);
348
- return String(str).replace(new RegExp(characters + '+$'), '');
349
- },
350
-
351
- truncate: function(str, length, truncateStr){
352
- if (str == null) return '';
353
- str = String(str); truncateStr = truncateStr || '...';
354
- length = ~~length;
355
- return str.length > length ? str.slice(0, length) + truncateStr : str;
356
- },
357
-
358
- /**
359
- * _s.prune: a more elegant version of truncate
360
- * prune extra chars, never leaving a half-chopped word.
361
- * @author github.com/rwz
362
- */
363
- prune: function(str, length, pruneStr){
364
- if (str == null) return '';
365
-
366
- str = String(str); length = ~~length;
367
- pruneStr = pruneStr != null ? String(pruneStr) : '...';
368
-
369
- if (str.length <= length) return str;
370
-
371
- var tmpl = function(c){ return c.toUpperCase() !== c.toLowerCase() ? 'A' : ' '; },
372
- template = str.slice(0, length+1).replace(/.(?=\W*\w*$)/g, tmpl); // 'Hello, world' -> 'HellAA AAAAA'
373
-
374
- if (template.slice(template.length-2).match(/\w\w/))
375
- template = template.replace(/\s*\S+$/, '');
376
- else
377
- template = _s.rtrim(template.slice(0, template.length-1));
378
-
379
- return (template+pruneStr).length > str.length ? str : str.slice(0, template.length)+pruneStr;
380
- },
381
-
382
- words: function(str, delimiter) {
383
- if (_s.isBlank(str)) return [];
384
- return _s.trim(str, delimiter).split(delimiter || /\s+/);
385
- },
386
-
387
- pad: function(str, length, padStr, type) {
388
- str = str == null ? '' : String(str);
389
- length = ~~length;
390
-
391
- var padlen = 0;
392
-
393
- if (!padStr)
394
- padStr = ' ';
395
- else if (padStr.length > 1)
396
- padStr = padStr.charAt(0);
397
-
398
- switch(type) {
399
- case 'right':
400
- padlen = length - str.length;
401
- return str + strRepeat(padStr, padlen);
402
- case 'both':
403
- padlen = length - str.length;
404
- return strRepeat(padStr, Math.ceil(padlen/2)) + str
405
- + strRepeat(padStr, Math.floor(padlen/2));
406
- default: // 'left'
407
- padlen = length - str.length;
408
- return strRepeat(padStr, padlen) + str;
409
- }
410
- },
411
-
412
- lpad: function(str, length, padStr) {
413
- return _s.pad(str, length, padStr);
414
- },
415
-
416
- rpad: function(str, length, padStr) {
417
- return _s.pad(str, length, padStr, 'right');
418
- },
419
-
420
- lrpad: function(str, length, padStr) {
421
- return _s.pad(str, length, padStr, 'both');
422
- },
423
-
424
- sprintf: sprintf,
425
-
426
- vsprintf: function(fmt, argv){
427
- argv.unshift(fmt);
428
- return sprintf.apply(null, argv);
429
- },
430
-
431
- toNumber: function(str, decimals) {
432
- if (str == null || str == '') return 0;
433
- str = String(str);
434
- var num = parseNumber(parseNumber(str).toFixed(~~decimals));
435
- return num === 0 && !str.match(/^0+$/) ? Number.NaN : num;
436
- },
437
-
438
- numberFormat : function(number, dec, dsep, tsep) {
439
- if (isNaN(number) || number == null) return '';
440
-
441
- number = number.toFixed(~~dec);
442
- tsep = tsep || ',';
443
-
444
- var parts = number.split('.'), fnums = parts[0],
445
- decimals = parts[1] ? (dsep || '.') + parts[1] : '';
446
-
447
- return fnums.replace(/(\d)(?=(?:\d{3})+$)/g, '$1' + tsep) + decimals;
448
- },
449
-
450
- strRight: function(str, sep){
451
- if (str == null) return '';
452
- str = String(str); sep = sep != null ? String(sep) : sep;
453
- var pos = !sep ? -1 : str.indexOf(sep);
454
- return ~pos ? str.slice(pos+sep.length, str.length) : str;
455
- },
456
-
457
- strRightBack: function(str, sep){
458
- if (str == null) return '';
459
- str = String(str); sep = sep != null ? String(sep) : sep;
460
- var pos = !sep ? -1 : str.lastIndexOf(sep);
461
- return ~pos ? str.slice(pos+sep.length, str.length) : str;
462
- },
463
-
464
- strLeft: function(str, sep){
465
- if (str == null) return '';
466
- str = String(str); sep = sep != null ? String(sep) : sep;
467
- var pos = !sep ? -1 : str.indexOf(sep);
468
- return ~pos ? str.slice(0, pos) : str;
469
- },
470
-
471
- strLeftBack: function(str, sep){
472
- if (str == null) return '';
473
- str += ''; sep = sep != null ? ''+sep : sep;
474
- var pos = str.lastIndexOf(sep);
475
- return ~pos ? str.slice(0, pos) : str;
476
- },
477
-
478
- toSentence: function(array, separator, lastSeparator, serial) {
479
- separator = separator || ', '
480
- lastSeparator = lastSeparator || ' and '
481
- var a = array.slice(), lastMember = a.pop();
482
-
483
- if (array.length > 2 && serial) lastSeparator = _s.rtrim(separator) + lastSeparator;
484
-
485
- return a.length ? a.join(separator) + lastSeparator + lastMember : lastMember;
486
- },
487
-
488
- toSentenceSerial: function() {
489
- var args = slice.call(arguments);
490
- args[3] = true;
491
- return _s.toSentence.apply(_s, args);
492
- },
493
-
494
- slugify: function(str) {
495
- if (str == null) return '';
496
-
497
- var from = "ąàáäâãåæćęèéëêìíïîłńòóöôõøùúüûñçżź",
498
- to = "aaaaaaaaceeeeeiiiilnoooooouuuunczz",
499
- regex = new RegExp(defaultToWhiteSpace(from), 'g');
500
-
501
- str = String(str).toLowerCase().replace(regex, function(c){
502
- var index = from.indexOf(c);
503
- return to.charAt(index) || '-';
504
- });
505
-
506
- return _s.dasherize(str.replace(/[^\w\s-]/g, ''));
507
- },
508
-
509
- surround: function(str, wrapper) {
510
- return [wrapper, str, wrapper].join('');
511
- },
512
-
513
- quote: function(str) {
514
- return _s.surround(str, '"');
515
- },
516
-
517
- exports: function() {
518
- var result = {};
519
-
520
- for (var prop in this) {
521
- if (!this.hasOwnProperty(prop) || prop.match(/^(?:include|contains|reverse)$/)) continue;
522
- result[prop] = this[prop];
523
- }
524
-
525
- return result;
526
- },
527
-
528
- repeat: function(str, qty, separator){
529
- if (str == null) return '';
530
-
531
- qty = ~~qty;
532
-
533
- // using faster implementation if separator is not needed;
534
- if (separator == null) return strRepeat(String(str), qty);
535
-
536
- // this one is about 300x slower in Google Chrome
537
- for (var repeat = []; qty > 0; repeat[--qty] = str) {}
538
- return repeat.join(separator);
539
- },
540
-
541
- levenshtein: function(str1, str2) {
542
- if (str1 == null && str2 == null) return 0;
543
- if (str1 == null) return String(str2).length;
544
- if (str2 == null) return String(str1).length;
545
-
546
- str1 = String(str1); str2 = String(str2);
547
-
548
- var current = [], prev, value;
549
-
550
- for (var i = 0; i <= str2.length; i++)
551
- for (var j = 0; j <= str1.length; j++) {
552
- if (i && j)
553
- if (str1.charAt(j - 1) === str2.charAt(i - 1))
554
- value = prev;
555
- else
556
- value = Math.min(current[j], current[j - 1], prev) + 1;
557
- else
558
- value = i + j;
559
-
560
- prev = current[j];
561
- current[j] = value;
562
- }
563
-
564
- return current.pop();
565
- }
566
- };
567
-
568
- // Aliases
569
-
570
- _s.strip = _s.trim;
571
- _s.lstrip = _s.ltrim;
572
- _s.rstrip = _s.rtrim;
573
- _s.center = _s.lrpad;
574
- _s.rjust = _s.lpad;
575
- _s.ljust = _s.rpad;
576
- _s.contains = _s.include;
577
- _s.q = _s.quote;
578
-
579
- // CommonJS module is defined
580
- if (typeof exports !== 'undefined') {
581
- if (typeof module !== 'undefined' && module.exports) {
582
- // Export module
583
- module.exports = _s;
584
- }
585
- exports._s = _s;
586
-
587
- } else if (typeof define === 'function' && define.amd) {
588
- // Register as a named module with AMD.
589
- define('underscore.string', [], function() {
590
- return _s;
591
- });
592
-
593
- } else {
594
- // Integrate with Underscore.js if defined
595
- // or create our own underscore object.
596
- root._ = root._ || {};
597
- root._.string = root._.str = _s;
598
- }
599
-
600
- }(this, String);