cshaml-sprockets 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,331 @@
1
+ // Underscore.string
2
+ // (c) 2010 Esa-Matti Suuronen <esa-matti aet suuronen dot org>
3
+ // Underscore.strings is freely distributable under the terms of the MIT license.
4
+ // Documentation: https://github.com/edtsech/underscore.string
5
+ // Some code is borrowed from MooTools and Alexandru Marasteanu.
6
+
7
+ // Version 1.1.4
8
+
9
+ (function(){
10
+ // ------------------------- Baseline setup ---------------------------------
11
+
12
+ // Establish the root object, "window" in the browser, or "global" on the server.
13
+ var root = this;
14
+
15
+ var nativeTrim = String.prototype.trim;
16
+
17
+ var parseNumber = function(source) { return source * 1 || 0; };
18
+
19
+ function str_repeat(i, m) {
20
+ for (var o = []; m > 0; o[--m] = i);
21
+ return o.join('');
22
+ }
23
+
24
+ function defaultToWhiteSpace(characters){
25
+ if (characters) {
26
+ return _s.escapeRegExp(characters);
27
+ }
28
+ return '\\s';
29
+ }
30
+
31
+ var _s = {
32
+
33
+ isBlank: function(str){
34
+ return !!str.match(/^\s*$/);
35
+ },
36
+
37
+ capitalize : function(str) {
38
+ return str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();
39
+ },
40
+
41
+ chop: function(str, step){
42
+ step = step || str.length;
43
+ var arr = [];
44
+ for (var i = 0; i < str.length;) {
45
+ arr.push(str.slice(i,i + step));
46
+ i = i + step;
47
+ }
48
+ return arr;
49
+ },
50
+
51
+ clean: function(str){
52
+ return _s.strip(str.replace(/\s+/g, ' '));
53
+ },
54
+
55
+ count: function(str, substr){
56
+ var count = 0, index;
57
+ for (var i=0; i < str.length;) {
58
+ index = str.indexOf(substr, i);
59
+ index >= 0 && count++;
60
+ i = i + (index >= 0 ? index : 0) + substr.length;
61
+ }
62
+ return count;
63
+ },
64
+
65
+ chars: function(str) {
66
+ return str.split('');
67
+ },
68
+
69
+ escapeHTML: function(str) {
70
+ return String(str||'').replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;')
71
+ .replace(/"/g, '&quot;').replace(/'/g, "&apos;");
72
+ },
73
+
74
+ unescapeHTML: function(str) {
75
+ return String(str||'').replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>')
76
+ .replace(/&quot;/g, '"').replace(/&apos;/g, "'");
77
+ },
78
+
79
+ escapeRegExp: function(str){
80
+ // From MooTools core 1.2.4
81
+ return String(str||'').replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
82
+ },
83
+
84
+ insert: function(str, i, substr){
85
+ var arr = str.split('');
86
+ arr.splice(i, 0, substr);
87
+ return arr.join('');
88
+ },
89
+
90
+ includes: function(str, needle){
91
+ return str.indexOf(needle) !== -1;
92
+ },
93
+
94
+ join: function(sep) {
95
+ // TODO: Could this be faster by converting
96
+ // arguments to Array and using array.join(sep)?
97
+ sep = String(sep);
98
+ var str = "";
99
+ for (var i=1; i < arguments.length; i += 1) {
100
+ str += String(arguments[i]);
101
+ if ( i !== arguments.length-1 ) {
102
+ str += sep;
103
+ }
104
+ }
105
+ return str;
106
+ },
107
+
108
+ lines: function(str) {
109
+ return str.split("\n");
110
+ },
111
+
112
+ // reverse: function(str){
113
+ // return Array.prototype.reverse.apply(str.split('')).join('');
114
+ // },
115
+
116
+ splice: function(str, i, howmany, substr){
117
+ var arr = str.split('');
118
+ arr.splice(i, howmany, substr);
119
+ return arr.join('');
120
+ },
121
+
122
+ startsWith: function(str, starts){
123
+ return str.length >= starts.length && str.substring(0, starts.length) === starts;
124
+ },
125
+
126
+ endsWith: function(str, ends){
127
+ return str.length >= ends.length && str.substring(str.length - ends.length) === ends;
128
+ },
129
+
130
+ succ: function(str){
131
+ var arr = str.split('');
132
+ arr.splice(str.length-1, 1, String.fromCharCode(str.charCodeAt(str.length-1) + 1));
133
+ return arr.join('');
134
+ },
135
+
136
+ titleize: function(str){
137
+ var arr = str.split(' '),
138
+ word;
139
+ for (var i=0; i < arr.length; i++) {
140
+ word = arr[i].split('');
141
+ if(typeof word[0] !== 'undefined') word[0] = word[0].toUpperCase();
142
+ i+1 === arr.length ? arr[i] = word.join('') : arr[i] = word.join('') + ' ';
143
+ }
144
+ return arr.join('');
145
+ },
146
+
147
+ camelize: function(str){
148
+ return _s.trim(str).replace(/(\-|_|\s)+(.)?/g, function(match, separator, chr) {
149
+ return chr ? chr.toUpperCase() : '';
150
+ });
151
+ },
152
+
153
+ underscored: function(str){
154
+ return _s.trim(str).replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/\-|\s+/g, '_').toLowerCase();
155
+ },
156
+
157
+ dasherize: function(str){
158
+ return _s.trim(str).replace(/([a-z\d])([A-Z]+)/g, '$1-$2').replace(/^([A-Z]+)/, '-$1').replace(/\_|\s+/g, '-').toLowerCase();
159
+ },
160
+
161
+ trim: function(str, characters){
162
+ if (!characters && nativeTrim) {
163
+ return nativeTrim.call(str);
164
+ }
165
+ characters = defaultToWhiteSpace(characters);
166
+ return str.replace(new RegExp('\^[' + characters + ']+|[' + characters + ']+$', 'g'), '');
167
+ },
168
+
169
+ ltrim: function(str, characters){
170
+ characters = defaultToWhiteSpace(characters);
171
+ return str.replace(new RegExp('\^[' + characters + ']+', 'g'), '');
172
+ },
173
+
174
+ rtrim: function(str, characters){
175
+ characters = defaultToWhiteSpace(characters);
176
+ return str.replace(new RegExp('[' + characters + ']+$', 'g'), '');
177
+ },
178
+
179
+ truncate: function(str, length, truncateStr){
180
+ truncateStr = truncateStr || '...';
181
+ return str.slice(0,length) + truncateStr;
182
+ },
183
+
184
+ words: function(str, delimiter) {
185
+ delimiter = delimiter || " ";
186
+ return str.split(delimiter);
187
+ },
188
+
189
+
190
+ pad: function(str, length, padStr, type) {
191
+
192
+ var padding = '';
193
+ var padlen = 0;
194
+
195
+ if (!padStr) { padStr = ' '; }
196
+ else if (padStr.length > 1) { padStr = padStr[0]; }
197
+ switch(type) {
198
+ case "right":
199
+ padlen = (length - str.length);
200
+ padding = str_repeat(padStr, padlen);
201
+ str = str+padding;
202
+ break;
203
+ case "both":
204
+ padlen = (length - str.length);
205
+ padding = {
206
+ 'left' : str_repeat(padStr, Math.ceil(padlen/2)),
207
+ 'right': str_repeat(padStr, Math.floor(padlen/2))
208
+ };
209
+ str = padding.left+str+padding.right;
210
+ break;
211
+ default: // "left"
212
+ padlen = (length - str.length);
213
+ padding = str_repeat(padStr, padlen);;
214
+ str = padding+str;
215
+ }
216
+ return str;
217
+ },
218
+
219
+ lpad: function(str, length, padStr) {
220
+ return _s.pad(str, length, padStr);
221
+ },
222
+
223
+ rpad: function(str, length, padStr) {
224
+ return _s.pad(str, length, padStr, 'right');
225
+ },
226
+
227
+ lrpad: function(str, length, padStr) {
228
+ return _s.pad(str, length, padStr, 'both');
229
+ },
230
+
231
+
232
+ /**
233
+ * Credits for this function goes to
234
+ * http://www.diveintojavascript.com/projects/sprintf-for-javascript
235
+ *
236
+ * Copyright (c) Alexandru Marasteanu <alexaholic [at) gmail (dot] com>
237
+ * All rights reserved.
238
+ * */
239
+ sprintf: function(){
240
+
241
+ var i = 0, a, f = arguments[i++], o = [], m, p, c, x, s = '';
242
+ while (f) {
243
+ if (m = /^[^\x25]+/.exec(f)) {
244
+ o.push(m[0]);
245
+ }
246
+ else if (m = /^\x25{2}/.exec(f)) {
247
+ o.push('%');
248
+ }
249
+ else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
250
+ if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) {
251
+ throw('Too few arguments.');
252
+ }
253
+ if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) {
254
+ throw('Expecting number but found ' + typeof(a));
255
+ }
256
+ switch (m[7]) {
257
+ case 'b': a = a.toString(2); break;
258
+ case 'c': a = String.fromCharCode(a); break;
259
+ case 'd': a = parseInt(a); break;
260
+ case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
261
+ case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
262
+ case 'o': a = a.toString(8); break;
263
+ case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
264
+ case 'u': a = Math.abs(a); break;
265
+ case 'x': a = a.toString(16); break;
266
+ case 'X': a = a.toString(16).toUpperCase(); break;
267
+ }
268
+ a = (/[def]/.test(m[7]) && m[2] && a >= 0 ? '+'+ a : a);
269
+ c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
270
+ x = m[5] - String(a).length - s.length;
271
+ p = m[5] ? str_repeat(c, x) : '';
272
+ o.push(s + (m[4] ? a + p : p + a));
273
+ }
274
+ else {
275
+ throw('Huh ?!');
276
+ }
277
+ f = f.substring(m[0].length);
278
+ }
279
+ return o.join('');
280
+ },
281
+
282
+ toNumber: function(str, decimals) {
283
+ return parseNumber(parseNumber(str).toFixed(parseNumber(decimals)));
284
+ },
285
+
286
+ strRight: function(sourceStr, sep){
287
+ var pos = (!sep) ? -1 : sourceStr.indexOf(sep);
288
+ return (pos != -1) ? sourceStr.slice(pos+sep.length, sourceStr.length) : sourceStr;
289
+ },
290
+
291
+ strRightBack: function(sourceStr, sep){
292
+ var pos = (!sep) ? -1 : sourceStr.lastIndexOf(sep);
293
+ return (pos != -1) ? sourceStr.slice(pos+sep.length, sourceStr.length) : sourceStr;
294
+ },
295
+
296
+ strLeft: function(sourceStr, sep){
297
+ var pos = (!sep) ? -1 : sourceStr.indexOf(sep);
298
+ return (pos != -1) ? sourceStr.slice(0, pos) : sourceStr;
299
+ },
300
+
301
+ strLeftBack: function(sourceStr, sep){
302
+ var pos = sourceStr.lastIndexOf(sep);
303
+ return (pos != -1) ? sourceStr.slice(0, pos) : sourceStr;
304
+ }
305
+
306
+ };
307
+
308
+ // Aliases
309
+
310
+ _s.strip = _s.trim;
311
+ _s.lstrip = _s.ltrim;
312
+ _s.rstrip = _s.rtrim;
313
+ _s.center = _s.lrpad;
314
+ _s.ljust = _s.lpad;
315
+ _s.rjust = _s.rpad;
316
+
317
+ // CommonJS module is defined
318
+ if (typeof window === 'undefined' && typeof module !== 'undefined') {
319
+ // Export module
320
+ module.exports = _s;
321
+
322
+ // Integrate with Underscore.js
323
+ } else if (typeof root._ !== 'undefined') {
324
+ root._.mixin(_s);
325
+
326
+ // Or define it
327
+ } else {
328
+ root._ = _s;
329
+ }
330
+
331
+ }());
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cshaml-sprockets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Boris Nadion
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: tilt
16
+ requirement: &70125240826400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70125240826400
25
+ - !ruby/object:Gem::Dependency
26
+ name: sprockets
27
+ requirement: &70125240825860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.1.2
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70125240825860
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70125240825480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70125240825480
47
+ description: Use the JST processor and have haml code read in and appended to application.js
48
+ email:
49
+ - boris@astrails.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - cs-haml-sprockets.gemspec
60
+ - lib/cshaml-sprockets.rb
61
+ - lib/cshaml-sprockets/engine.rb
62
+ - lib/cshaml-sprockets/version.rb
63
+ - spec/lib/cshaml-sprockets_spec.rb
64
+ - spec/spec_helper.rb
65
+ - vendor/assets/javascripts/haml.js
66
+ - vendor/assets/javascripts/json2.js
67
+ - vendor/assets/javascripts/underscore.js
68
+ - vendor/assets/javascripts/underscore.string.js
69
+ homepage: https://github.com/astrails/cshaml-sprockets
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project: cshaml-sprockets
89
+ rubygems_version: 1.8.15
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Use the awesome https://github.com/uglyog/clientside-haml-js javascript templating
93
+ lib in Ruby
94
+ test_files:
95
+ - spec/lib/cshaml-sprockets_spec.rb
96
+ - spec/spec_helper.rb