OSDN Git Service

fix peta spec
[pettanr/pettanr.git] / app / assets / javascripts / pettanr.js.coffee
1 class Pettanr\r
2   class Pettanr.AppHelper\r
3     \r
4     @icon_tag: (name, opt = {}) ->\r
5       title = if opt['object']\r
6         name + ' ID:' + opt['object'].get(id).toString()\r
7       else\r
8         name\r
9       size = if opt['size']\r
10         parseInt(opt['size'])\r
11       else\r
12         35\r
13       "<img src=\"" + '/images/' + Pettanr.underscore(name) + '.gif' + "\" width=" + size.toString() + " height=" + size.toString() + " alt=\"" + name + ' Icon' + "title=\"" + title + ">"\r
14 \r
15   class Pettanr.AppController\r
16 \r
17   #>> https://gist.github.com/davidjbeveridge/3813724\r
18   @xeach: (arr, func, index=0) ->\r
19     if index < arr.length then [ func(arr[index], index), @xeach(arr, func, index + 1)... ] else []\r
20   \r
21   @camelize: (input) ->\r
22     pieces = input.split(/[\W_-]/)\r
23     @xeach(pieces, @capitalize).join("")\r
24   \r
25   @capitalize: (input) ->\r
26     input.charAt(0).toUpperCase() + input.slice(1)\r
27   \r
28   @lowercase: (input) ->\r
29     input.toLowerCase()\r
30    \r
31   @underscore: (input) ->\r
32     pieces = input.replace(/([A-Z])/g, '_$1').split(/[\W_-]/).filter (n) -> !!n\r
33     @xeach(pieces, @lowercase ).join("_")\r
34   # <<\r
35   @is_a_string: (str) ->\r
36     if (str instanceof String) or (typeof str == "string")\r
37       true\r
38     else\r
39       false\r
40   \r
41 @Pettanr = Pettanr\r