ultimate-base 0.2.4 → 0.3.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/.gitignore +4 -1
  2. data/.rvmrc +0 -1
  3. data/.rvmrc.example +0 -1
  4. data/Gemfile +6 -0
  5. data/Gemfile.lock +113 -1
  6. data/app/assets/javascripts/ultimate/backbone/base.js.coffee +14 -2
  7. data/app/assets/javascripts/ultimate/backbone/extra/jquery-plugin-adapter.js.coffee +1 -1
  8. data/app/assets/javascripts/ultimate/backbone/model.js.coffee +6 -0
  9. data/app/assets/javascripts/ultimate/backbone/view.js.coffee +5 -4
  10. data/app/assets/javascripts/ultimate/backbone/views/slider.js.coffee +4 -1
  11. data/app/assets/javascripts/ultimate/helpers/asset_tag.js.coffee +71 -54
  12. data/app/assets/javascripts/ultimate/helpers/base.js.coffee +3 -0
  13. data/app/assets/javascripts/ultimate/helpers/decor.js.coffee +19 -14
  14. data/app/assets/javascripts/ultimate/helpers/number.js.coffee +600 -0
  15. data/app/assets/javascripts/ultimate/helpers/record_tag.js.coffee +66 -0
  16. data/app/assets/javascripts/ultimate/helpers/tag.js.coffee +77 -0
  17. data/app/assets/javascripts/ultimate/helpers/url.js.coffee +49 -0
  18. data/app/assets/javascripts/ultimate/helpers.js.coffee +39 -66
  19. data/app/assets/javascripts/ultimate/{devise.js.coffee → improves/devise.js.coffee} +0 -0
  20. data/app/assets/javascripts/ultimate/improves/i18n-lite.js.coffee +18 -12
  21. data/app/assets/javascripts/ultimate/improves/magic-radios.js.coffee +2 -0
  22. data/app/assets/javascripts/ultimate/improves/typed-fields.js.coffee +13 -14
  23. data/app/assets/javascripts/ultimate/{base.js.coffee → jquery.base.js.coffee} +24 -37
  24. data/app/assets/javascripts/ultimate/{experimental/_inflections → underscore}/underscore.inflection.js +19 -18
  25. data/app/assets/javascripts/ultimate/underscore/underscore.outcasts.js.coffee +123 -0
  26. data/app/assets/javascripts/ultimate/underscore/underscore.string.js +16 -6
  27. data/config/routes.rb +2 -0
  28. data/lib/{ultimate-base → ultimate/base}/engine.rb +1 -0
  29. data/lib/{ultimate-base → ultimate/base}/version.rb +1 -1
  30. data/lib/ultimate/base.rb +10 -0
  31. data/lib/{ultimate-base → ultimate}/extensions/directive_processor.rb +0 -0
  32. data/lib/{ultimate-base → ultimate}/extensions/sass_script_functions.rb +0 -0
  33. data/scripts/rails +8 -0
  34. data/test/dummy/Rakefile +7 -0
  35. data/test/dummy/_emfile +18 -0
  36. data/{app/assets/javascripts/ultimate/helpers/forms.js.coffee → test/dummy/app/assets/images/.gitkeep} +0 -0
  37. data/test/dummy/app/assets/javascripts/application.js +3 -0
  38. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  39. data/test/dummy/app/assets/stylesheets/global/forms.css.scss +65 -0
  40. data/test/dummy/app/assets/stylesheets/global/layout/footer.scss +18 -0
  41. data/test/dummy/app/assets/stylesheets/global/layout/header.scss +13 -0
  42. data/test/dummy/app/assets/stylesheets/global/layout/main-menu.scss +68 -0
  43. data/test/dummy/app/assets/stylesheets/global/layout.css.scss +46 -0
  44. data/test/dummy/app/assets/stylesheets/global/reserved.css.scss +79 -0
  45. data/test/dummy/app/assets/stylesheets/global/reset.css.scss +85 -0
  46. data/test/dummy/app/assets/stylesheets/global/structures.css.scss +9 -0
  47. data/test/dummy/app/assets/stylesheets/import/base.scss +34 -0
  48. data/test/dummy/app/assets/stylesheets/plugins/qunit.css.scss +3 -0
  49. data/test/dummy/app/controllers/application_controller.rb +4 -0
  50. data/test/dummy/app/controllers/main_controller.rb +8 -0
  51. data/test/dummy/app/helpers/application_helper.rb +2 -0
  52. data/test/dummy/app/mailers/.gitkeep +0 -0
  53. data/test/dummy/app/models/.gitkeep +0 -0
  54. data/test/dummy/app/views/application/_footer.html.haml +3 -0
  55. data/test/dummy/app/views/application/_header.html.haml +4 -0
  56. data/test/dummy/app/views/application/_main_menu.html.haml +11 -0
  57. data/test/dummy/app/views/layouts/application.html.haml +24 -0
  58. data/test/dummy/app/views/main/index.html.haml +13 -0
  59. data/test/dummy/app/views/main/qunit.html.haml +7 -0
  60. data/test/dummy/config/application.rb +59 -0
  61. data/test/dummy/config/boot.rb +10 -0
  62. data/test/dummy/config/database.yml +25 -0
  63. data/test/dummy/config/environment.rb +5 -0
  64. data/test/dummy/config/environments/development.rb +40 -0
  65. data/test/dummy/config/environments/production.rb +67 -0
  66. data/test/dummy/config/environments/test.rb +37 -0
  67. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/test/dummy/config/initializers/inflections.rb +15 -0
  69. data/test/dummy/config/initializers/mime_types.rb +5 -0
  70. data/test/dummy/config/initializers/qunit-rails.rb +1 -0
  71. data/test/dummy/config/initializers/secret_token.rb +7 -0
  72. data/test/dummy/config/initializers/session_store.rb +8 -0
  73. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  74. data/test/dummy/config/locales/en.yml +5 -0
  75. data/test/dummy/config/routes.rb +63 -0
  76. data/test/dummy/config.ru +4 -0
  77. data/test/dummy/log/.gitkeep +0 -0
  78. data/test/dummy/public/404.html +26 -0
  79. data/test/dummy/public/422.html +26 -0
  80. data/test/dummy/public/500.html +25 -0
  81. data/test/dummy/public/favicon.ico +0 -0
  82. data/test/dummy/script/rails +6 -0
  83. data/test/javascripts/all_tests.js.coffee +13 -0
  84. data/test/javascripts/test_helper.js.coffee +3 -0
  85. data/test/javascripts/tests/base_test.js.coffee +42 -0
  86. data/test/javascripts/tests/helpers/asset_tag_test.js.coffee +51 -0
  87. data/test/javascripts/tests/helpers/number_test.js.coffee +250 -0
  88. data/test/javascripts/tests/helpers/record_tag_test.js.coffee +56 -0
  89. data/test/javascripts/tests/helpers/tag_test.js.coffee +33 -0
  90. data/test/javascripts/tests/helpers/url_test.js.coffee +28 -0
  91. data/test/javascripts/tests/helpers_test.js.coffee +47 -0
  92. data/test/javascripts/tests/improves/i18n-lite_test.js.coffee +25 -0
  93. data/test/javascripts/tests/underscore/underscore.outcasts.test.js.coffee +38 -0
  94. data/test/stylesheets/test_helper.css +4 -0
  95. data/ultimate-base.gemspec +4 -4
  96. metadata +116 -24
  97. data/app/assets/javascripts/ultimate/bus.js.coffee +0 -57
  98. data/app/assets/javascripts/ultimate/experimental/_inflections/dzone.inflections.js +0 -154
  99. data/app/assets/javascripts/ultimate/helpers/array.js.coffee +0 -63
  100. data/app/assets/javascripts/ultimate/helpers/tags.js.coffee +0 -73
  101. data/app/assets/javascripts/ultimate/widgets/dock.js.coffee +0 -70
  102. data/app/assets/javascripts/ultimate/widgets/gear.js.coffee +0 -84
  103. data/app/assets/javascripts/ultimate/widgets/jquery-ext.js.coffee +0 -104
  104. data/app/assets/javascripts/ultimate/widgets/jquery.adapter.js.coffee +0 -62
  105. data/app/assets/javascripts/ultimate/widgets/widget.js.coffee +0 -115
  106. data/lib/ultimate-base.rb +0 -10
@@ -0,0 +1,77 @@
1
+ #= require ./base
2
+
3
+ @Ultimate.Helpers.Tag =
4
+
5
+ BOOLEAN_ATTRIBUTES: "disabled readonly multiple checked autobuffer
6
+ autoplay controls loop selected hidden scoped async
7
+ defer reversed ismap seemless muted required
8
+ autofocus novalidate formnovalidate open pubdate itemscope".split(/\s+/)
9
+
10
+ PRE_CONTENT_STRINGS:
11
+ textarea: "\n"
12
+
13
+ tag: (tag_name, options = {}, open = false, escape = true) ->
14
+ "<#{tag_name}#{@tag_options(options)}#{if open then '>' else ' />'}"
15
+
16
+ content_tag: (name, content_or_options_with_block = null, options = null, escape = true, block = null) ->
17
+ if block = _.outcasts.blockGiven(arguments)
18
+ options = content_or_options_with_block
19
+ @content_tag_string(name, block(), options, escape)
20
+ else
21
+ @content_tag_string(name, content_or_options_with_block, options, escape)
22
+
23
+ content_tag_string: (name, content = '', options = {}, escape = true) ->
24
+ content = _.escape(content) if escape
25
+ "<#{name}#{@tag_options(options, escape)}>#{@PRE_CONTENT_STRINGS[name] ? ''}#{content}</#{name}>"
26
+
27
+ html_options_to_s: (html_options, escape = false, prefix = "") ->
28
+ deprecate 'html_options_to_s()', "tag_options()"
29
+ @tag_options.apply(@, arguments)
30
+
31
+ tag_options: (options, escape = true) ->
32
+ return "" if _.isEmpty(options)
33
+ attrs = []
34
+ for key, value of options
35
+ if key is "data" and _.isObject(value)
36
+ for k, v of value
37
+ attrs.push @data_tag_option(k, v, escape)
38
+ else if _.include(@BOOLEAN_ATTRIBUTES, key)
39
+ attrs.push @boolean_tag_option(key) if value
40
+ else if value?
41
+ attrs.push @tag_option(key, value, escape)
42
+ if _.isEmpty(attrs) then "" else " #{attrs.sort().join(' ')}"
43
+
44
+ data_tag_option: (key, value, escape) ->
45
+ key = "data-#{_.string.dasherize(key)}"
46
+ value = JSON.stringify(value) if JSON? and _.isObject(value)
47
+ @tag_option(key, value, escape)
48
+
49
+ boolean_tag_option: (key) ->
50
+ "#{key}=\"#{key}\""
51
+
52
+ tag_option: (key, value, escape) ->
53
+ value = value.join(" ") if _.isArray(value)
54
+ value = _.string.escapeHTML(value) if escape
55
+ "#{key}=\"#{value}\""
56
+
57
+
58
+
59
+ # # TODO more zen features: +, *x, {content}
60
+ # # TODO cache
61
+ # selectorToHtml: (selector) ->
62
+ # if matches = selector.match(/^[\s>]*([\w\.]+)(.*)$/)
63
+ # selector = matches[1]
64
+ # continuation = matches[2]#{(if open then ">" else " />")}
65
+ # classes = selector.split(".")
66
+ # tag_name = classes.shift() or "div"
67
+ # html_options = {}
68
+ # html_options["class"] = classes.join(" ") if classes.length
69
+ # if continuation
70
+ # @content_tag(tag_name, @selectorToHtml(continuation), html_options)
71
+ # else
72
+ # @tag(tag_name, html_options)
73
+ # else
74
+ # ""
75
+ #
76
+ concat_class: ->
77
+ _.uniq(_.compact(arguments).join(' ').split(/\s+/)).join(' ')
@@ -0,0 +1,49 @@
1
+ #= require ./base
2
+ #= require ./tag
3
+
4
+ @Ultimate.Helpers.Url =
5
+
6
+ url_for: (options = null) ->
7
+ if _.isString(options)
8
+ if options is "back"
9
+ 'javascript:history.back();'
10
+ else
11
+ options
12
+ else unless _.isEmpty(options)
13
+ url = _.result(options, 'url') ? ''
14
+ if _.isObject(options)
15
+ options = _.clone(options)
16
+ delete options['url']
17
+ anchor = _.outcasts.delete(options, 'anchor')
18
+ url += "?#{_.map(options, (value, key) -> "#{key}=#{value}").sort().join('&')}" unless _.isEmpty(options)
19
+ url += "##{anchor}" if anchor
20
+ url
21
+ else
22
+ 'javascript:;'
23
+
24
+ link_to: (name = null, options = null, html_options = null, block = null) ->
25
+ [html_options, options] = [options, name] if block = _.outcasts.blockGiven(arguments)
26
+ options ||= {}
27
+ url = @url_for(options)
28
+ html_options = @_convert_options_to_data_attributes(options, html_options)
29
+ html_options["href"] ||= url
30
+ Ultimate.Helpers.Tag.content_tag("a", name or url, html_options, false, block)
31
+
32
+
33
+
34
+ _convert_options_to_data_attributes: (options, html_options) ->
35
+ if html_options
36
+ html_options['data-remote'] = 'true' if @_link_to_remote_options(options) or @_link_to_remote_options(html_options)
37
+ method = _.outcasts.delete(html_options, 'method')
38
+ @_add_method_to_attributes(html_options, method) if method
39
+ html_options
40
+ else
41
+ if @_link_to_remote_options(options) then {'data-remote': 'true'} else {}
42
+
43
+ _link_to_remote_options: (options) ->
44
+ _.isObject(options) and _.outcasts.delete(options, 'remote')
45
+
46
+ _add_method_to_attributes: (html_options, method) ->
47
+ if _.isString(method) and method.toLowerCase() isnt "get" and not /nofollow/.test(html_options["rel"])
48
+ html_options["rel"] = _.string.lstrip("#{html_options["rel"]} nofollow")
49
+ html_options["data-method"] = method
@@ -7,10 +7,10 @@
7
7
 
8
8
  @DEBUG_MODE ?= false
9
9
  @TEST_MODE ?= false
10
- @WARNINGS ?= true
10
+ @LOG_TODO ?= true
11
11
 
12
12
  @cout = =>
13
- args = @args(arguments)
13
+ args = _.toArray(arguments)
14
14
  method = if args[0] in ['log', 'info', 'warn', 'error', 'assert', 'clear'] then args.shift() else 'log'
15
15
  if @DEBUG_MODE and console?
16
16
  method = console[method]
@@ -25,34 +25,53 @@
25
25
  arguments[0]
26
26
 
27
27
  @deprecate = (subject, instead = null) =>
28
- @cout 'warn', "\"#{subject}\" DEPRECATED!#{if instead then " Use instead: \"#{instead}\"" else ''}"
29
- return
28
+ @cout 'error', "`#{subject}` DEPRECATED!#{if instead then " Use instead `#{instead}`" else ''}"
30
29
 
31
- @warning = (subject, instead = null) =>
32
- if @WARNINGS
33
- @cout 'warn', "\"#{subject}\" WARNING!#{if instead then " Use instead: \"#{instead}\"" else ''}"
34
- return
30
+ @todo = (subject, location = null, numberOrString = null) =>
31
+ if @LOG_TODO
32
+ @cout 'warn', "TODO: #{subject}#{if location then " ### #{location}" else ''}#{if numberOrString then (if _.isNumber(numberOrString) then ":#{numberOrString}" else " > #{numberOrString}") else ''}"
35
33
 
36
34
  @args = (a) ->
35
+ @deprecate 'arg()', '_.toArray()'
37
36
  r = []
38
37
  Array::push.apply(r, a) if a.length > 0
39
38
  r
40
39
 
41
- @blockGiven = (args) =>
42
- l = args.length
43
- if l
44
- l = args[l - 1]
45
- if _.isFunction(l) then l else false
46
- else
47
- false
40
+ @logicalXOR = (a, b) ->
41
+ ( a and not b ) or ( not a and b )
42
+
43
+ @bound = (number, min, max) ->
44
+ Math.max(min, Math.min(max, number))
45
+
48
46
 
49
- @_delete = (object, key) ->
50
- value = object[key]
51
- delete object[key]
52
- value
47
+
48
+ @getParams = ->
49
+ q = location.search.substring(1).split('&')
50
+ r = {}
51
+ for e in q
52
+ t = e.split('=')
53
+ r[t[0]] = t[1]
54
+ r
55
+
56
+ @respondFormat = (url, format = null) ->
57
+ aq = url.split('?')
58
+ ah = aq[0].split('#')
59
+ ad = ah[0].split('.')
60
+ currentFormat = if ad.length > 1 and not /\//.test(ad[ad.length - 1]) then ad.pop() else ''
61
+ return currentFormat unless format?
62
+ return url if format is currentFormat
63
+ ad.push format if format
64
+ ah[0] = ad.join('.')
65
+ aq[0] = ah.join('#')
66
+ aq.join('?')
67
+
68
+
69
+
70
+ ########### Deprecated ###########
53
71
 
54
72
  # Helper function to get a value from a object as a property or as a function.
55
73
  @getValue = (object, prop) ->
74
+ @deprecate "getValue()", "_.result()"
56
75
  return null unless object and object[prop]
57
76
  return if _.isFunction(object[prop]) then object[prop]() else object[prop]
58
77
 
@@ -80,16 +99,6 @@
80
99
  r.push(e) for e in arrOrString when not _.include(r, e)
81
100
  if isStr then r.join('') else r
82
101
 
83
- @logicalXOR = (a, b) ->
84
- ( a and not b ) or ( not a and b )
85
-
86
- @bound = (number, min, max) ->
87
- Math.max(min, Math.min(max, number))
88
-
89
- @roundWithPrecision = (number, precision = 2) ->
90
- precision = Math.pow(10, precision)
91
- Math.round(number * precision) / precision
92
-
93
102
  @regexpSpace = /^\s*$/
94
103
  @regexpTrim = /^\s*(.*?)\s*$/
95
104
 
@@ -97,53 +106,17 @@
97
106
  @deprecate "strTrim(s)", "_.trim(s)"
98
107
  s.match(@regexpTrim)[1]
99
108
 
100
- # !!!!!!!!!!! tags !!!!!!!!!!!!
101
-
102
- @number_to_currency = (number, units) ->
103
- precision = 2
104
- s = parseFloat(number).toFixed(precision)
105
- b = s.length - 1 - precision
106
- r = s.substring(b)
107
- while b > 0
108
- a = b - 3
109
- r = ' ' + s.substring(a, b) + r
110
- b = a
111
- "#{r.substring(1)} #{units}"
112
-
113
-
114
-
115
- @getParams = ->
116
- q = location.search.substring(1).split('&')
117
- r = {}
118
- for e in q
119
- t = e.split('=')
120
- r[t[0]] = t[1]
121
- r
122
-
123
- @respondFormat = (url, format = null) ->
124
- aq = url.split('?')
125
- ah = aq[0].split('#')
126
- ad = ah[0].split('.')
127
- currentFormat = if ad.length > 1 and not /\//.test(ad[ad.length - 1]) then ad.pop() else ''
128
- return currentFormat unless format?
129
- return url if format is currentFormat
130
- ad.push format if format
131
- ah[0] = ad.join('.')
132
- aq[0] = ah.join('#')
133
- aq.join('?')
134
-
135
109
 
136
110
 
137
111
  @rails_data = {}
138
112
 
139
113
  @rails_scope = (controller_name, action_name, scopedCloasure = null, scopedCloasureArguments...) =>
114
+ @deprecate 'rails_scope'
140
115
  return false if _.isString(controller_name) and controller_name isnt @rails_data['controller_name']
141
116
  return false if _.isString(action_name) and action_name isnt @rails_data['action_name']
142
117
  if _.isFunction(scopedCloasure)
143
118
  arguments[2] scopedCloasureArguments...
144
119
  true
145
120
 
146
-
147
-
148
121
  $ =>
149
122
  @rails_data = $('body').data()
@@ -1,14 +1,20 @@
1
- # TODO list
1
+ # TODO list:
2
2
  # * load all locales
3
+ # * pluralize
3
4
 
4
- @I18n ||=
5
- locale: "en"
6
- translations: {}
7
-
8
- t: (path) ->
9
- path = path.split('.') if _.isString(path)
10
- scope = @translations
11
- for step in path
12
- scope = scope[step]
13
- return path.join('.') unless scope
14
- scope
5
+ @I18n = $.extend true,
6
+ {
7
+ locale: "en"
8
+ translations: {}
9
+
10
+ translate: (path, options = {}) ->
11
+ path = path.split('.') if _.isString(path)
12
+ scope = @translations
13
+ for step in path
14
+ scope = scope[step]
15
+ return options['default'] ? path.join('.') unless scope?
16
+ scope
17
+
18
+ t: -> @translate arguments...
19
+
20
+ }, @I18n
@@ -1,5 +1,7 @@
1
1
  #
2
2
  # Magic Radios
3
+ # TODO refactoring
4
+ # TODO checkboxes
3
5
  #
4
6
  # @example
5
7
  # = f.radio_button :main_addr_same_as_jur, true, data: {disable: ".main-addr"}
@@ -1,15 +1,16 @@
1
- ( ( $ ) ->
1
+ do ($ = jQuery) ->
2
2
 
3
3
  # ========= max & min =========
4
4
  $('input:text[data-gte], input:text[data-lte]').live 'change focusout blur', ->
5
- jField = $ @
5
+ jField = $(@)
6
6
  realValue = jField.val()
7
7
  if realValue isnt ''
8
- min = parseFloat jField.data('gte')
9
- max = parseFloat jField.data('lte')
10
- oldValue = parseFloat realValue
8
+ # TODO refactor this
9
+ min = parseFloat(jField.data('gte'))
10
+ max = parseFloat(jField.data('lte'))
11
+ oldValue = parseFloat(realValue)
11
12
  v = oldValue
12
- v = 0 if isNaN v
13
+ v = 0 if isNaN(v)
13
14
  v = min if not isNaN(min) and v < min
14
15
  v = max if not isNaN(max) and v > max
15
16
  jField.val(v).change() unless v is oldValue
@@ -33,15 +34,15 @@
33
34
  'text' : /^.*$/
34
35
 
35
36
  $.fn.getRegExpMask = ->
36
- mask = @data 'regexpMask'
37
+ mask = @data('regexpMask')
37
38
  if _.isString(mask)
38
39
  try
39
- mask = new RegExp mask
40
+ mask = new RegExp(mask)
40
41
  @data 'regexpMask', mask
41
42
  catch e
42
43
  # nop
43
44
  else
44
- dataType = @data 'dataType'
45
+ dataType = @data('dataType')
45
46
  mask = $.regexp.typedField[dataType] if dataType
46
47
  unless mask
47
48
  @val 'unknown dataType'
@@ -56,18 +57,16 @@
56
57
 
57
58
  $.fn.setRegExpMask = (mask) ->
58
59
  stringMask = 'true'
59
- if _.isString mask
60
+ if _.isString(mask)
60
61
  stringMask = mask
61
62
  try
62
- mask = new RegExp mask
63
+ mask = new RegExp(mask)
63
64
  catch e
64
65
  # nop
65
- if _.isRegExp mask
66
+ if _.isRegExp(mask)
66
67
  @
67
68
  .dropRegExpMask()
68
69
  .attr('data-regexp-mask', stringMask)
69
70
  .data('regexpMask', mask)
70
71
  .change()
71
72
  @
72
-
73
- )( jQuery )
@@ -1,14 +1,4 @@
1
- ###
2
- * front-end ui-components routines
3
- *
4
- * @version 0.5.5.alpha / 2010-2012
5
- * @author Karpunin Dmitry / Evrone.com
6
- * @email koderfunk_at_gmail_dot_com
7
- *
8
- * TODO register components
9
- * TODO using underscore.js
10
- *
11
- ###
1
+ # TODO: register components
12
2
 
13
3
  do ($ = jQuery) =>
14
4
 
@@ -18,43 +8,39 @@ do ($ = jQuery) =>
18
8
 
19
9
  @ror_id = (jObjOrString) ->
20
10
  if jObjOrString instanceof jQuery
21
- id = jObjOrString.data('rorId') # Maybe use "id"
22
- unless id
23
- id = jObjOrString.attr('id')
24
- if id
25
- matchResult = id.match($.regexp.rorId)
26
- id = if matchResult then matchResult[2] else null
27
- jObjOrString.data 'rorId', id
28
- id
29
- else
30
- null
31
- else
11
+ id = jObjOrString.data("rorId") # Maybe use "id"
12
+ unless id?
13
+ id = ror_id(jObjOrString.attr("id"))
14
+ jObjOrString.data("rorId", id) if id?
15
+ id
16
+ else if _.isString(jObjOrString)
32
17
  matchResult = jObjOrString.match($.regexp.rorId)
33
18
  if matchResult then matchResult[2] else null
19
+ else
20
+ null
34
21
 
35
- $.fn.rorId = ->
22
+ $.fn.rorId = (id = null, prefix = null) ->
36
23
  if arguments.length
37
- id = arguments[0]
38
- word = 'ror_id'
39
- thisId = @attr('id')
40
- if thisId
41
- word = matchResult[1] if matchResult = thisId.match($.regexp.rorId)
42
- @data('rorId', id).attr 'id', "${word}_#{id}"
43
- @
24
+ jThis = @first()
25
+ thisId = @attr("id")
26
+ if not prefix? and _.isString(thisId)
27
+ prefix = matchResult[1] if matchResult = thisId.match($.regexp.rorId)
28
+ @data("rorId", id)
29
+ if prefix?
30
+ jThis.attr "id", "#{prefix}_#{id}"
31
+ jThis
44
32
  else
45
33
  ror_id @
46
34
 
47
35
  $.fn.getClasses = ->
48
- _.words @attr("class")
36
+ _.string.words @attr("class")
49
37
 
50
38
  # Get hash of html-dom attributes from first matched element or false, if no elements
51
39
  $.fn.getAttributes = ->
40
+ attrs = {}
52
41
  if @length
53
- attrs = {}
54
- attrs[attr.nodeName] = attr.nodeValue for attr in this[0].attributes
55
- attrs
56
- else
57
- false
42
+ attrs[attr.nodeName] = attr.nodeValue for attr in this[0].attributes
43
+ attrs
58
44
 
59
45
  # [showOrHide[, duration[, callback]]]
60
46
  $.fn.slideToggleByState = ->
@@ -74,7 +60,8 @@ do ($ = jQuery) =>
74
60
  $.isHTML = (content, strong = false) ->
75
61
  return false unless _.isString(content)
76
62
  matches = content.match($.regexp.HTML)
77
- matches and not strong or matches[1] is matches[2]
63
+ return false unless matches?
64
+ not strong or matches[1] is matches[2]
78
65
 
79
66
  # TODO replace usages to underscore methods and using distribution
80
67
  unless $.isRegExp
@@ -6,16 +6,17 @@
6
6
 
7
7
  ( function( _, undefined )
8
8
  {
9
+ var
10
+ plurals = [ ],
11
+
12
+ singulars = [ ],
13
+
14
+ uncountables = [ ];
15
+
9
16
  /**
10
17
  * Inflector
11
18
  */
12
19
  var inflector = {
13
-
14
- plurals : [ ],
15
-
16
- singulars : [ ],
17
-
18
- uncountables : [ ],
19
20
 
20
21
  gsub : function( word, rule, replacement )
21
22
  {
@@ -26,7 +27,7 @@
26
27
 
27
28
  plural : function( rule, replacement )
28
29
  {
29
- this.plurals.unshift( [ rule, replacement ] );
30
+ plurals.unshift( [ rule, replacement ] );
30
31
  },
31
32
 
32
33
  pluralize : function( word, count, includeNumber )
@@ -40,14 +41,14 @@
40
41
  }
41
42
  else
42
43
  {
43
- if( _( this.uncountables ).include( word ) )
44
+ if( _( uncountables ).include( word ) )
44
45
  {
45
46
  return word;
46
47
  }
47
48
 
48
49
  result = word;
49
50
 
50
- _( this.plurals ).detect( function( rule )
51
+ _( plurals ).detect( function( rule )
51
52
  {
52
53
  var gsub = this.gsub( word, rule[ 0 ], rule[ 1 ] );
53
54
 
@@ -61,19 +62,19 @@
61
62
 
62
63
  singular : function( rule, replacement )
63
64
  {
64
- this.singulars.unshift( [ rule, replacement ] );
65
+ singulars.unshift( [ rule, replacement ] );
65
66
  },
66
67
 
67
68
  singularize : function( word )
68
69
  {
69
- if( _( this.uncountables ).include( word ) )
70
+ if( _( uncountables ).include( word ) )
70
71
  {
71
72
  return word;
72
73
  }
73
74
 
74
75
  var result = word;
75
76
 
76
- _( this.singulars ).detect( function( rule )
77
+ _( singulars ).detect( function( rule )
77
78
  {
78
79
  var gsub = this.gsub( word, rule[ 0 ], rule[ 1 ] );
79
80
 
@@ -86,20 +87,20 @@
86
87
 
87
88
  irregular : function( singular, plural )
88
89
  {
89
- this.plural( singular, plural );
90
- this.singular( plural, singular );
90
+ this.plural( '\\b' + singular + '\\b', plural );
91
+ this.singular( '\\b' + plural + '\\b', singular );
91
92
  },
92
93
 
93
94
  uncountable : function( word )
94
95
  {
95
- this.uncountables.unshift( word );
96
+ uncountables.unshift( word );
96
97
  },
97
98
 
98
99
  resetInflections : function( )
99
100
  {
100
- this.plurals = [ ];
101
- this.singulars = [ ];
102
- this.uncountables = [ ];
101
+ plurals = [ ];
102
+ singulars = [ ];
103
+ uncountables = [ ];
103
104
 
104
105
  this.plural( /$/, 's' );
105
106
  this.plural( /s$/, 's' );