5 class Pettanr.AppHelper
\r
9 @full_url: (filename) ->
\r
10 request.protocol + request.host_with_port + filename
\r
13 l = label.split('.')
\r
18 I18n.t('activerecord.models.' + Pettanr[label].item_name())
\r
20 I18n.t('activerecord.models.attribtes.' + Pettanr[l.first].item_name() + '.' + l.last)
\r
22 @t_select_items: (items) ->
\r
26 @t_selected_item: (name, index) ->
\r
27 I18n.t(Manifest.manifest().system_resources.select_items[name][index][0])
\r
29 @image_tag: (src, opt = {}) ->
\r
30 size = if opt['size']
\r
31 parseInt(opt['size'])
\r
34 "<img src=\"" + src + "\" width=" + size.toString() + " height=" + size.toString() + ">"
\r
36 @icon_tag: (name, opt = {}) ->
\r
37 title = if opt['object']
\r
38 name + ' ID:' + opt['object'].get(id).toString()
\r
41 size = if opt['size']
\r
42 parseInt(opt['size'])
\r
45 "<img src=\"" + '/images/' + Pettanr.underscore(name) + '.gif' + "\" width=" + size.toString() + " height=" + size.toString() + " alt=\"" + name + ' Icon' + "title=\"" + title + ">"
\r
47 @distance_of_time_in_words_to_now: (datetime) ->
\r
50 class Pettanr.AppController
\r
52 #>> https://gist.github.com/davidjbeveridge/3813724
\r
53 @xeach: (arr, func, index=0) ->
\r
54 if index < arr.length then [ func(arr[index], index), @xeach(arr, func, index + 1)... ] else []
\r
56 @camelize: (input) ->
\r
57 pieces = input.split(/[\W_-]/)
\r
58 @xeach(pieces, @capitalize).join("")
\r
60 @capitalize: (input) ->
\r
61 input.charAt(0).toUpperCase() + input.slice(1)
\r
63 @lowercase: (input) ->
\r
66 @underscore: (input) ->
\r
67 pieces = input.replace(/([A-Z])/g, '_$1').split(/[\W_-]/).filter (n) -> !!n
\r
68 @xeach(pieces, @lowercase ).join("_")
\r
70 @is_a_string: (str) ->
\r
71 if (str instanceof String) or (typeof str == "string")
\r