material_raingular 0.2.3.1 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets/javascripts/directives/ngcallback.coffee +1 -0
- data/lib/assets/javascripts/directives/ngdestroy.js.coffee +1 -0
- data/lib/assets/javascripts/material_raingular.js.coffee +7 -1
- data/lib/assets/javascripts/material_raingular/directives/callback/controller.coffee +16 -0
- data/lib/assets/javascripts/material_raingular/directives/callback/directive.coffee +5 -0
- data/lib/assets/javascripts/material_raingular/directives/destroy/directive.coffee +4 -0
- data/lib/assets/javascripts/material_raingular/directives/destroy/linkmodel.coffee +40 -0
- data/lib/assets/javascripts/material_raingular/directives/update/directive.coffee +4 -0
- data/lib/assets/javascripts/material_raingular/directives/update/linkmodel.coffee +56 -0
- data/lib/assets/javascripts/super_classes/angular_compile_model.coffee +20 -0
- data/lib/assets/javascripts/super_classes/angular_directive.coffee +42 -0
- data/lib/assets/javascripts/super_classes/angular_directive_model.coffee +13 -0
- data/lib/assets/javascripts/super_classes/angular_link_model.coffee +14 -0
- data/lib/assets/javascripts/super_classes/angular_model.coffee +17 -0
- data/lib/assets/javascripts/super_classes/angular_route_model.coffee +30 -0
- data/lib/assets/javascripts/super_classes/angular_scoped_model.coffee +18 -0
- data/lib/assets/javascripts/super_classes/angular_service_model.coffee +7 -0
- data/lib/assets/javascripts/super_classes/angular_view_model.coffee +7 -0
- data/lib/assets/javascripts/super_classes/material_modal_model.coffee +27 -0
- data/lib/assets/javascripts/super_classes/module.coffee +19 -0
- data/lib/assets/javascripts/super_classes/panel_config.coffee +15 -0
- data/lib/material_raingular/version.rb +1 -1
- data/vendor/assets/angular/inflections.js +637 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f214ce783246db52946da67e8381c835d0b4da0
|
4
|
+
data.tar.gz: 0967d56bcdb0a1b08ad7110c42ea16411a624b8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80b0323f2fc9b445653a58412df33f75b225235bdcc101bf9aed9ea0be1c78fb28ea474080b681783995cdb8994cdb4b0d3df1ef224208934c539393fd68872e
|
7
|
+
data.tar.gz: db786aa0dfdcc5b068424ab5a5f932625859707433df7214f56c1412d0cdb8a8d87af1dc739b62ab87bf801e331f016622434318d76de8f80aacffc6b28f9a28
|
@@ -3,6 +3,7 @@ angular.module 'NgCallback', ['Factories', 'FactoryName']
|
|
3
3
|
.directive 'ngCallback', ->
|
4
4
|
restrict: 'A'
|
5
5
|
controller: ($scope,$element) ->
|
6
|
+
console.warn 'ngCallback is deprecated. Please consider using mrCallback in its stead.'
|
6
7
|
@evaluate = (returnData)->
|
7
8
|
for callback in $element[0].attributes['ng-callback'].value.split(';')
|
8
9
|
[match,func,args] = callback.match(/(.*)\((.*)\)/)
|
@@ -4,6 +4,7 @@ angular.module 'NgDestroy', ['Factories']
|
|
4
4
|
restrict: 'A'
|
5
5
|
require: '?ngCallback'
|
6
6
|
link: (scope, element, attributes, ngCallbackCtrl) ->
|
7
|
+
console.warn "ngDestroy is deprecated. Please consider using mrDestroy in its stead."
|
7
8
|
element.bind 'click', (event) ->
|
8
9
|
form = element[0]
|
9
10
|
until form.nodeName == 'FORM' || !form
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# //= require_tree ./super_classes
|
2
|
+
# //= require inflections
|
1
3
|
# //= require extensions
|
2
4
|
# //= require angular
|
3
5
|
# //= require angular-route
|
@@ -15,10 +17,14 @@
|
|
15
17
|
# //= require ajax_errors
|
16
18
|
# //= require identifier_interceptor
|
17
19
|
# //= require rails_updater
|
20
|
+
# //= require_self
|
21
|
+
# //= require_tree ./material_raingular
|
18
22
|
|
19
|
-
|
23
|
+
@MaterialRaingular = {
|
24
|
+
app: angular.module('materialRaingular', ['AutoComplete', 'NgDownload', 'NgChangeOnBlur', 'NgDrag', 'NgAuthorize', 'AComplete'
|
20
25
|
'NgRepeatList', 'NgUpdate', 'NgPopup', 'NgBoolean', 'Table', 'NgWatchShow', 'NgTrackBy'
|
21
26
|
'NgUpload', 'NgDestroy', 'NgCreate', 'Video','NgAuthorize', 'TextArea', 'MdUpdate'
|
22
27
|
'NgSlide', 'NgMatches','NgFade','NgSwipe', 'NgLoad', 'NgWatchContent', 'RailsUpdater'
|
23
28
|
'ngRoute', 'ngMaterial', 'ngMessages', 'ngResource', 'materialFilters', 'NgCallback'
|
24
29
|
'NgSortable', 'FilteredSelect'])
|
30
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class DirectiveModels.MrCallbackModel extends AngularDirectiveModel
|
2
|
+
@inject(
|
3
|
+
'$attrs'
|
4
|
+
'$parse'
|
5
|
+
'$scope'
|
6
|
+
)
|
7
|
+
evaluate: (returnData)->
|
8
|
+
for callback in @$attrs.mrCallback.split(';')
|
9
|
+
[match,func,args] = callback.match(/(.*)\((.*)\)/)
|
10
|
+
data = []
|
11
|
+
if !!args
|
12
|
+
for arg in args.split(',')
|
13
|
+
data.push @$scope.$eval(arg)
|
14
|
+
data.push returnData
|
15
|
+
callbackFunc = @$parse(func)(@$scope) || @$parse(func)(window)
|
16
|
+
callbackFunc(data...)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# //= require material_raingular/directives/destroy/directive
|
2
|
+
class MrDestroyModel extends AngularLinkModel
|
3
|
+
REGEXP: /^\s*(.*?)\s+in\s+(.*?)(?:\s+track\s+by\s+([\s\S]+?))?$/
|
4
|
+
# 1: model name
|
5
|
+
# 2: collection name
|
6
|
+
# 3: track by value
|
7
|
+
@inject(
|
8
|
+
'$parse'
|
9
|
+
'factoryName'
|
10
|
+
'$timeout'
|
11
|
+
)
|
12
|
+
initialize: ->
|
13
|
+
@_setForm()
|
14
|
+
@$element.bind 'click', @destroy
|
15
|
+
@register(Directives.MrDestroy)
|
16
|
+
|
17
|
+
destroy: =>
|
18
|
+
return if @$attrs.disabled || @form.disabled
|
19
|
+
@$timeout =>
|
20
|
+
@_list().drop(@_model())
|
21
|
+
factory = @$injector.get(@_options().factory || @factoryName(@_matchedExpression()[1]))
|
22
|
+
factory.destroy {id: @_model().id}, @_callBack
|
23
|
+
|
24
|
+
_callBack: (data) => @$controller[1]?.evaluate(data)
|
25
|
+
_model: -> @$controller[0].$viewValue
|
26
|
+
_list: -> @_options().list || @$scope.$eval(@_matchedExpression()[2].split('|')[0])
|
27
|
+
_options: -> @$scope.$eval(@$attrs.mrOptions || '{}')
|
28
|
+
_matchedExpression: -> @_repeatElement().getAttribute('ng-repeat').match(@REGEXP)
|
29
|
+
_repeatElement: ->
|
30
|
+
repeatElement = @$element[0]
|
31
|
+
until repeatElement.hasAttribute 'ng-repeat'
|
32
|
+
repeatElement = repeatElement.parentNode
|
33
|
+
break if !repeatElement
|
34
|
+
repeatElement
|
35
|
+
_setForm: ->
|
36
|
+
@form = @$element[0]
|
37
|
+
until @form.nodeName == 'FORM' || !@form
|
38
|
+
@form = @form.parentNode
|
39
|
+
break if !@form
|
40
|
+
@form ||= @$element[0]
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class DirectiveModels.MrUpdateModel extends AngularLinkModel
|
2
|
+
@inject(
|
3
|
+
'$parse'
|
4
|
+
'$timeout'
|
5
|
+
'RailsUpdater'
|
6
|
+
)
|
7
|
+
initialize: ->
|
8
|
+
[@ngModelCtrl,@mrCallbackCtrl,@ngTrackByCtrl] = @$controller
|
9
|
+
@updater = @RailsUpdater.new(@$scope,@$controller,@$attrs.ngModel,@$attrs.ngOverride,@$attrs.ngFactory)
|
10
|
+
@_bind()
|
11
|
+
|
12
|
+
@register(Directives.MrUpdate)
|
13
|
+
|
14
|
+
_bind: -> @$timeout => @_bindInput()[@_funcName()]()
|
15
|
+
_bindInput: =>
|
16
|
+
radio: => @_boundUpdate('input',true)
|
17
|
+
date: => @_boundUpdate('input',true)
|
18
|
+
checkbox: => @_boundUpdate('click')
|
19
|
+
hidden: => @_watcher()
|
20
|
+
text: => @_bindText()
|
21
|
+
textarea: => @_bindDebounce(750,'keyup')
|
22
|
+
other: => @_watcher()
|
23
|
+
|
24
|
+
_boundUpdate: (binding,checkValid) ->
|
25
|
+
@$element.bind binding, (event) =>
|
26
|
+
return if !@ngModelCtrl.$valid && checkValid
|
27
|
+
@updater.update(@$element.val())
|
28
|
+
|
29
|
+
_bindText: ->
|
30
|
+
@$element.bind 'focus', =>
|
31
|
+
@$scope.$apply =>
|
32
|
+
@oldValue = @$element.val()
|
33
|
+
delay = if @$element.hasClass('autocomplete') then 300 else 0
|
34
|
+
@_bindDebounce(delay,'blur')
|
35
|
+
|
36
|
+
_bindDebounce: (delay,binding) ->
|
37
|
+
@$element.bind binding, (event) =>
|
38
|
+
return if @$element.val() == @oldValue
|
39
|
+
@$timeout.cancel(@debounce)
|
40
|
+
@debounce = @$timeout =>
|
41
|
+
@updater.update(@$element.val())
|
42
|
+
,delay
|
43
|
+
|
44
|
+
_watcher: ->
|
45
|
+
@$scope.$watch @_modelVal(), (updated,old) =>
|
46
|
+
@updater.update(updated) unless updated == old
|
47
|
+
_specificTypes: ['radio','date','checkbox','hidden']
|
48
|
+
_type: -> @$attrs.type
|
49
|
+
_tagName: -> @$element[0].tagName
|
50
|
+
_modelName: -> @$attrs.ngModel
|
51
|
+
_modelVal: -> @$parse(@$attrs.ngModel)
|
52
|
+
_isInput: -> @_tagName() == 'INPUT'
|
53
|
+
_funcName: ->
|
54
|
+
return 'textarea' if @_tagName() == 'TEXTAREA'
|
55
|
+
return (@_specificTypes.intersection([@_tagName()])[0] || 'text') if @_isInput()
|
56
|
+
'other'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# //= require super_classes/angular_model
|
2
|
+
class @AngularCompileModel extends AngularModel
|
3
|
+
@register: (model,type) -> model::[type || 'compile'] = (args...) => new @(args...)
|
4
|
+
@$default_arguments: ['element','attrs','transcludeFn']
|
5
|
+
constructor: (args...) ->
|
6
|
+
for key,index in @constructor.$default_arguments
|
7
|
+
@['$' + key] = args[index]
|
8
|
+
@$injector = angular.element(document.body).injector()
|
9
|
+
for key in @constructor.$inject || []
|
10
|
+
@[key] = @$injector.get(key)
|
11
|
+
@initialize?()
|
12
|
+
###
|
13
|
+
class CompileModel extends AngularLinkModel
|
14
|
+
@inject('Project')
|
15
|
+
initialize: ->
|
16
|
+
console.dir 'howdy'
|
17
|
+
console.dir @$scope
|
18
|
+
console.dir @Project
|
19
|
+
@register(testDirective) #NOTE: Must be called last in directive since it instantiates a new model instance
|
20
|
+
### #NOTE: argument should be directive model
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#//= require super_classes/angular_model
|
2
|
+
|
3
|
+
### Example Usage
|
4
|
+
class testDirective extends AngularDirectiveModel
|
5
|
+
@inject('Project') #NOTE: Inject any dependencies
|
6
|
+
initialize: -> #NOTE: This method is called immediately upon creation of the directive
|
7
|
+
console.dir @Project #NOTE: The Project factory has been injected and is available on this
|
8
|
+
restrict: 'E' #NOTE: Declare typical angular directive statements
|
9
|
+
replace: true
|
10
|
+
template: '<div> Hello</div>'
|
11
|
+
controller: DirectiveModel #NOTE: Use a class defined extending AngularDirectiveModel
|
12
|
+
link: LinkModel #NOTE: Can't be set here if using AngularLinkModel
|
13
|
+
compile: CompileModel #NOTE: Same as above, if set link is unset
|
14
|
+
|
15
|
+
|
16
|
+
# Other Options
|
17
|
+
priority: 0,
|
18
|
+
template: '<div></div>', or function(tElement, tAttrs) { ... },
|
19
|
+
or
|
20
|
+
templateUrl: 'directive.html', or function(tElement, tAttrs) { ... },
|
21
|
+
transclude: false,
|
22
|
+
templateNamespace: 'html',
|
23
|
+
scope: false,
|
24
|
+
controllerAs: 'stringIdentifier',
|
25
|
+
bindToController: false,
|
26
|
+
require: 'siblingDirectiveName', or ['^parentDirectiveName', '?optionalDirectiveName', '?^optionalParent'],
|
27
|
+
multiElement: false,
|
28
|
+
|
29
|
+
@register(angular.app) #NOTE: Must be called last in directive since it instantiates a new model instance
|
30
|
+
###
|
31
|
+
@Directives ||= {}
|
32
|
+
class @AngularDirective extends AngularModel
|
33
|
+
# Automatically registers the controller to the module
|
34
|
+
@register: (app, name,type) ->
|
35
|
+
name ?= (@name || @toString().match(/function\s*(.*?)\(/)?[1]).tableize().camelize('lower').singularize()
|
36
|
+
app?[type || 'directive'] name, ['$injector', ($injector) => new @($injector)]
|
37
|
+
constructor: ($injector) ->
|
38
|
+
# Bind injected dependencies on scope ie @$scope
|
39
|
+
for key in @constructor.$inject || []
|
40
|
+
@[key] = $injector.get(key)
|
41
|
+
# Run initialize function if exists
|
42
|
+
@initialize?()
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# //= require super_classes/angular_view_model
|
2
|
+
@DirectiveModels ||= {}
|
3
|
+
class @AngularDirectiveModel extends @AngularViewModel
|
4
|
+
@register: -> console.warn "Directive models can not be registered. Perhaps you were trying to use a view model?"
|
5
|
+
|
6
|
+
###
|
7
|
+
class TestDirectiveModel extends AngularDirectiveModel
|
8
|
+
@register(angular.app) #NOTE: Raises Warning. Do not register
|
9
|
+
@inject('Person') #NOTE: Inject Dependencies
|
10
|
+
initialize: -> #NOTE: Runs on initialization
|
11
|
+
console.dir @Person
|
12
|
+
console.dir 'controller'
|
13
|
+
###
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# //= require super_classes/angular_compile_model
|
2
|
+
class @AngularLinkModel extends AngularCompileModel
|
3
|
+
@register: (model) -> super(model,'link')
|
4
|
+
@$default_arguments: ['scope','element','attrs','controller','transcludeFn'] #NOTE: Order matters
|
5
|
+
|
6
|
+
###
|
7
|
+
class LinkModel extends AngularLinkModel
|
8
|
+
@inject('Project')
|
9
|
+
initialize: ->
|
10
|
+
console.dir 'howdy'
|
11
|
+
console.dir @$scope
|
12
|
+
console.dir @Project
|
13
|
+
@register(testDirective) #NOTE: Must be called last in directive since it instantiates a new model instance
|
14
|
+
### #NOTE: argument should be directive model
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# //= require ./module
|
2
|
+
class @AngularModel extends Module
|
3
|
+
# Automatically registers the controller to the module
|
4
|
+
@register: (app, name,type) ->
|
5
|
+
name ?= @name || @toString().match(/function\s*(.*?)\(/)?[1]
|
6
|
+
app?[type] name, @
|
7
|
+
# Injects dependencies included in args
|
8
|
+
@inject: (args...) ->
|
9
|
+
@$inject = args
|
10
|
+
|
11
|
+
constructor: (args...) ->
|
12
|
+
# Bind injected dependencies on scope ie @$scope
|
13
|
+
for key, index in @constructor.$inject || []
|
14
|
+
@[key] = args[index]
|
15
|
+
|
16
|
+
# Run initialize function if exists
|
17
|
+
@initialize?()
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# //= require super_classes/angular_model
|
2
|
+
###
|
3
|
+
class @AdminRouteModel extends AngularRouteModel
|
4
|
+
default: -> #'/'
|
5
|
+
controller: 'Admin'
|
6
|
+
_id: -> #'/:id'
|
7
|
+
controller: 'Admin'
|
8
|
+
person_id: -> #'/person/:id'
|
9
|
+
controller: 'Admin'
|
10
|
+
personName: -> #'/person/name'
|
11
|
+
controller: 'Admin'
|
12
|
+
otherwise: ->
|
13
|
+
redirectTo: '/'
|
14
|
+
@register(angular.app)
|
15
|
+
###
|
16
|
+
class @AngularRouteModel extends AngularModel
|
17
|
+
@register: (app) ->
|
18
|
+
app.config(($routeProvider,$locationProvider) => new @($routeProvider,$locationProvider))
|
19
|
+
constructor: ($routeProvider,$locationProvider)->
|
20
|
+
for key, val of @constructor.prototype
|
21
|
+
continue if key in ['constructor', 'initialize']
|
22
|
+
unless key in ['default','otherwise']
|
23
|
+
route = key.replace('_','/:').tableize().singularize().replace('_','/')
|
24
|
+
route = '/' + route unless route[0] is '/'
|
25
|
+
$routeProvider.when(route,val())
|
26
|
+
else if key == 'default'
|
27
|
+
$routeProvider.when('/',val())
|
28
|
+
else
|
29
|
+
$routeProvider.otherwise(val())
|
30
|
+
return $routeProvider
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# //= require ./angular_model
|
2
|
+
class @AngularScopedModel extends AngularModel
|
3
|
+
@inject: (args...) ->
|
4
|
+
args.push('$scope','$rootScope','$routeParams')
|
5
|
+
@$inject = args
|
6
|
+
|
7
|
+
constructor: (args...) ->
|
8
|
+
# Bind injected dependencies on scope ie @$scope
|
9
|
+
for key, index in @constructor.$inject || []
|
10
|
+
@[key] = args[index]
|
11
|
+
|
12
|
+
# Bind all functions not begining with _ to scope
|
13
|
+
for key, val of @constructor.prototype
|
14
|
+
continue if key in ['constructor', 'initialize'] or key[0] is '_'
|
15
|
+
@$scope[key] = if (typeof val is 'function') then val.bind?(@) || _.bind(val, @) else val
|
16
|
+
|
17
|
+
# Run initialize function if exists
|
18
|
+
@initialize?()
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# //= require ./angular_model
|
2
|
+
@ServiceModels ||= {}
|
3
|
+
class @AngularServiceModel extends AngularModel
|
4
|
+
# Automatically registers the service to the module
|
5
|
+
@register: (app, name) ->
|
6
|
+
name ?= @name || @toString().match(/function\s*(.*?)\(/)?[1]
|
7
|
+
app?.service name, @
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# //= require ./angular_scoped_model
|
2
|
+
@ViewModels ||= {}
|
3
|
+
class @AngularViewModel extends AngularScopedModel
|
4
|
+
# Automatically registers the controller to the module
|
5
|
+
@register: (app, name) ->
|
6
|
+
name ?= @name || @toString().match(/function\s*(.*?)\(/)?[1]
|
7
|
+
app.controller? name, @
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# //= require ./angular_scoped_model
|
2
|
+
@ModalModels ||= {}
|
3
|
+
class @MaterialModalModel extends AngularScopedModel
|
4
|
+
@locals: (args...) ->
|
5
|
+
@$inject ||= []
|
6
|
+
@$inject.merge(args)
|
7
|
+
@$locals = args
|
8
|
+
@inject: (args...) ->
|
9
|
+
args.push('$scope','$rootScope','$mdDialog')
|
10
|
+
@$inject ||= []
|
11
|
+
@$inject.merge(args)
|
12
|
+
constructor: (args...) ->
|
13
|
+
# Bind injected dependencies on scope ie @$scope
|
14
|
+
for key, index in @constructor.$inject || []
|
15
|
+
@[key] = args[index]
|
16
|
+
for key in @constructor.$locals || []
|
17
|
+
@$scope[key] = @[key]
|
18
|
+
@$scope.hide = @$mdDialog.hide
|
19
|
+
@$scope.cancel = @$mdDialog.hide
|
20
|
+
|
21
|
+
# Bind all functions not begining with _ to scope
|
22
|
+
for key, val of @constructor.prototype
|
23
|
+
continue if key in ['constructor', 'initialize'] or key[0] is '_'
|
24
|
+
@$scope[key] = if (typeof val is 'function') then val.bind?(@) || _.bind(val, @) else val
|
25
|
+
|
26
|
+
# Run initialize function if exists
|
27
|
+
@initialize?()
|
@@ -0,0 +1,19 @@
|
|
1
|
+
moduleKeywords = ['extended', 'included']
|
2
|
+
@Modules = {}
|
3
|
+
class @Module
|
4
|
+
@extend: (obj) ->
|
5
|
+
obj = obj.prototype || obj
|
6
|
+
for key, value of obj when key not in moduleKeywords
|
7
|
+
@[key] = value
|
8
|
+
|
9
|
+
obj.extended?.apply(@)
|
10
|
+
this
|
11
|
+
|
12
|
+
@include: (obj) ->
|
13
|
+
obj = obj.prototype || obj
|
14
|
+
for key, value of obj when key not in moduleKeywords
|
15
|
+
# Assign properties to the prototype
|
16
|
+
@::[key] = value
|
17
|
+
|
18
|
+
obj.included?.apply(@)
|
19
|
+
this
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class @PanelConfig
|
2
|
+
constructor: (config) ->
|
3
|
+
for key,value of config || {}
|
4
|
+
@[key] = value
|
5
|
+
@attachTo ||= angular.element(document.body)
|
6
|
+
@clickOutsideToClose ||= true
|
7
|
+
@escapeToClose ||= true
|
8
|
+
@focusOnOpen ||= false
|
9
|
+
@zIndex ||= 2
|
10
|
+
@openFrom ||= @event
|
11
|
+
@target ||= @event.target
|
12
|
+
@panelClass ||= 'md-select-menu'
|
13
|
+
setPosition: (target,$mdPanel) ->
|
14
|
+
@position = $mdPanel.newPanelPosition().relativeTo(target).addPanelPosition($mdPanel.xPosition.ALIGN_START, $mdPanel.yPosition.BELOW)
|
15
|
+
return @
|
@@ -0,0 +1,637 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2007-2015 Ryan Schuft (ryan.schuft@gmail.com)
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
The above copyright notice and this permission notice shall be included in
|
10
|
+
all copies or substantial portions of the Software.
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
12
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
13
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
14
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
15
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
17
|
+
THE SOFTWARE.
|
18
|
+
*/
|
19
|
+
|
20
|
+
/*
|
21
|
+
This code is based in part on the work done in Ruby to support
|
22
|
+
infection as part of Ruby on Rails in the ActiveSupport's Inflector
|
23
|
+
and Inflections classes. It was initally ported to Javascript by
|
24
|
+
Ryan Schuft (ryan.schuft@gmail.com) in 2007.
|
25
|
+
The code is available at http://code.google.com/p/inflection-js/
|
26
|
+
The basic usage is:
|
27
|
+
1. Include this script on your web page.
|
28
|
+
2. Call functions on any String object in Javascript
|
29
|
+
Currently implemented functions:
|
30
|
+
String.pluralize(plural) == String
|
31
|
+
renders a singular English language noun into its plural form
|
32
|
+
normal results can be overridden by passing in an alternative
|
33
|
+
String.singularize(singular) == String
|
34
|
+
renders a plural English language noun into its singular form
|
35
|
+
normal results can be overridden by passing in an alterative
|
36
|
+
String.camelize(lowFirstLetter) == String
|
37
|
+
renders a lower case underscored word into camel case
|
38
|
+
the first letter of the result will be upper case unless you pass true
|
39
|
+
also translates "/" into "::" (underscore does the opposite)
|
40
|
+
String.underscore() == String
|
41
|
+
renders a camel cased word into words seperated by underscores
|
42
|
+
also translates "::" back into "/" (camelize does the opposite)
|
43
|
+
String.humanize(lowFirstLetter) == String
|
44
|
+
renders a lower case and underscored word into human readable form
|
45
|
+
defaults to making the first letter capitalized unless you pass true
|
46
|
+
String.capitalize() == String
|
47
|
+
renders all characters to lower case and then makes the first upper
|
48
|
+
String.dasherize() == String
|
49
|
+
renders all underbars and spaces as dashes
|
50
|
+
String.titleize() == String
|
51
|
+
renders words into title casing (as for book titles)
|
52
|
+
String.demodulize() == String
|
53
|
+
renders class names that are prepended by modules into just the class
|
54
|
+
String.tableize() == String
|
55
|
+
renders camel cased singular words into their underscored plural form
|
56
|
+
String.classify() == String
|
57
|
+
renders an underscored plural word into its camel cased singular form
|
58
|
+
String.foreign_key(dropIdUbar) == String
|
59
|
+
renders a class name (camel cased singular noun) into a foreign key
|
60
|
+
defaults to seperating the class from the id with an underbar unless
|
61
|
+
you pass true
|
62
|
+
String.ordinalize() == String
|
63
|
+
renders all numbers found in the string into their sequence like "22nd"
|
64
|
+
*/
|
65
|
+
|
66
|
+
/*
|
67
|
+
This sets up a container for some constants in its own namespace
|
68
|
+
We use the window (if available) to enable dynamic loading of this script
|
69
|
+
Window won't necessarily exist for non-browsers.
|
70
|
+
*/
|
71
|
+
if (typeof window !== "undefined" && !window.InflectionJS)
|
72
|
+
{
|
73
|
+
window.InflectionJS = null;
|
74
|
+
}
|
75
|
+
|
76
|
+
/*
|
77
|
+
This sets up some constants for later use
|
78
|
+
This should use the window namespace variable if available
|
79
|
+
*/
|
80
|
+
InflectionJS =
|
81
|
+
{
|
82
|
+
/*
|
83
|
+
This is a list of nouns that use the same form for both singular and plural.
|
84
|
+
This list should remain entirely in lower case to correctly match Strings.
|
85
|
+
*/
|
86
|
+
uncountable_words: [
|
87
|
+
'equipment', 'information', 'rice', 'money', 'species', 'series',
|
88
|
+
'fish', 'sheep', 'moose', 'deer', 'news'
|
89
|
+
],
|
90
|
+
|
91
|
+
/*
|
92
|
+
These rules translate from the singular form of a noun to its plural form.
|
93
|
+
*/
|
94
|
+
plural_rules: [
|
95
|
+
[new RegExp('(m)an$', 'gi'), '$1en'],
|
96
|
+
[new RegExp('(pe)rson$', 'gi'), '$1ople'],
|
97
|
+
[new RegExp('(child)$', 'gi'), '$1ren'],
|
98
|
+
[new RegExp('^(ox)$', 'gi'), '$1en'],
|
99
|
+
[new RegExp('(ax|test)is$', 'gi'), '$1es'],
|
100
|
+
[new RegExp('(octop|vir)us$', 'gi'), '$1i'],
|
101
|
+
[new RegExp('(alias|status)$', 'gi'), '$1es'],
|
102
|
+
[new RegExp('(bu)s$', 'gi'), '$1ses'],
|
103
|
+
[new RegExp('(buffal|tomat|potat)o$', 'gi'), '$1oes'],
|
104
|
+
[new RegExp('([ti])um$', 'gi'), '$1a'],
|
105
|
+
[new RegExp('sis$', 'gi'), 'ses'],
|
106
|
+
[new RegExp('(?:([^f])fe|([lr])f)$', 'gi'), '$1$2ves'],
|
107
|
+
[new RegExp('(hive)$', 'gi'), '$1s'],
|
108
|
+
[new RegExp('([^aeiouy]|qu)y$', 'gi'), '$1ies'],
|
109
|
+
[new RegExp('(x|ch|ss|sh)$', 'gi'), '$1es'],
|
110
|
+
[new RegExp('(matr|vert|ind)ix|ex$', 'gi'), '$1ices'],
|
111
|
+
[new RegExp('([m|l])ouse$', 'gi'), '$1ice'],
|
112
|
+
[new RegExp('(quiz)$', 'gi'), '$1zes'],
|
113
|
+
[new RegExp('s$', 'gi'), 's'],
|
114
|
+
[new RegExp('$', 'gi'), 's']
|
115
|
+
],
|
116
|
+
|
117
|
+
/*
|
118
|
+
These rules translate from the plural form of a noun to its singular form.
|
119
|
+
*/
|
120
|
+
singular_rules: [
|
121
|
+
[new RegExp('(m)en$', 'gi'), '$1an'],
|
122
|
+
[new RegExp('(pe)ople$', 'gi'), '$1rson'],
|
123
|
+
[new RegExp('(child)ren$', 'gi'), '$1'],
|
124
|
+
[new RegExp('([ti])a$', 'gi'), '$1um'],
|
125
|
+
[new RegExp('((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$','gi'), '$1$2sis'],
|
126
|
+
[new RegExp('(hive)s$', 'gi'), '$1'],
|
127
|
+
[new RegExp('(tive)s$', 'gi'), '$1'],
|
128
|
+
[new RegExp('(curve)s$', 'gi'), '$1'],
|
129
|
+
[new RegExp('([lr])ves$', 'gi'), '$1f'],
|
130
|
+
[new RegExp('([^fo])ves$', 'gi'), '$1fe'],
|
131
|
+
[new RegExp('([^aeiouy]|qu)ies$', 'gi'), '$1y'],
|
132
|
+
[new RegExp('(s)eries$', 'gi'), '$1eries'],
|
133
|
+
[new RegExp('(m)ovies$', 'gi'), '$1ovie'],
|
134
|
+
[new RegExp('(x|ch|ss|sh)es$', 'gi'), '$1'],
|
135
|
+
[new RegExp('([m|l])ice$', 'gi'), '$1ouse'],
|
136
|
+
[new RegExp('(bus)es$', 'gi'), '$1'],
|
137
|
+
[new RegExp('(o)es$', 'gi'), '$1'],
|
138
|
+
[new RegExp('(shoe)s$', 'gi'), '$1'],
|
139
|
+
[new RegExp('(cris|ax|test)es$', 'gi'), '$1is'],
|
140
|
+
[new RegExp('(octop|vir)i$', 'gi'), '$1us'],
|
141
|
+
[new RegExp('(alias|status)es$', 'gi'), '$1'],
|
142
|
+
[new RegExp('^(ox)en', 'gi'), '$1'],
|
143
|
+
[new RegExp('(vert|ind)ices$', 'gi'), '$1ex'],
|
144
|
+
[new RegExp('(matr)ices$', 'gi'), '$1ix'],
|
145
|
+
[new RegExp('(quiz)zes$', 'gi'), '$1'],
|
146
|
+
[new RegExp('s$', 'gi'), '']
|
147
|
+
],
|
148
|
+
|
149
|
+
/*
|
150
|
+
This is a list of words that should not be capitalized for title case
|
151
|
+
*/
|
152
|
+
non_titlecased_words: [
|
153
|
+
'and', 'or', 'nor', 'a', 'an', 'the', 'so', 'but', 'to', 'of', 'at',
|
154
|
+
'by', 'from', 'into', 'on', 'onto', 'off', 'out', 'in', 'over',
|
155
|
+
'with', 'for'
|
156
|
+
],
|
157
|
+
|
158
|
+
/*
|
159
|
+
These are regular expressions used for converting between String formats
|
160
|
+
*/
|
161
|
+
id_suffix: new RegExp('(_ids|_id)$', 'g'),
|
162
|
+
underbar: new RegExp('_', 'g'),
|
163
|
+
space_or_underbar: new RegExp('[\ _]', 'g'),
|
164
|
+
uppercase: new RegExp('([A-Z])', 'g'),
|
165
|
+
underbar_prefix: new RegExp('^_'),
|
166
|
+
|
167
|
+
/*
|
168
|
+
This is a helper method that applies rules based replacement to a String
|
169
|
+
Signature:
|
170
|
+
InflectionJS.apply_rules(str, rules, skip, override) == String
|
171
|
+
Arguments:
|
172
|
+
str - String - String to modify and return based on the passed rules
|
173
|
+
rules - Array: [RegExp, String] - Regexp to match paired with String to use for replacement
|
174
|
+
skip - Array: [String] - Strings to skip if they match
|
175
|
+
override - String (optional) - String to return as though this method succeeded (used to conform to APIs)
|
176
|
+
Returns:
|
177
|
+
String - passed String modified by passed rules
|
178
|
+
Examples:
|
179
|
+
InflectionJS.apply_rules("cows", InflectionJs.singular_rules) === 'cow'
|
180
|
+
*/
|
181
|
+
apply_rules: function(str, rules, skip, override)
|
182
|
+
{
|
183
|
+
if (override)
|
184
|
+
{
|
185
|
+
str = override;
|
186
|
+
}
|
187
|
+
else
|
188
|
+
{
|
189
|
+
var ignore = (skip.indexOf(str.toLowerCase()) > -1);
|
190
|
+
if (!ignore)
|
191
|
+
{
|
192
|
+
for (var x = 0; x < rules.length; x++)
|
193
|
+
{
|
194
|
+
if (str.match(rules[x][0]))
|
195
|
+
{
|
196
|
+
str = str.replace(rules[x][0], rules[x][1]);
|
197
|
+
break;
|
198
|
+
}
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|
202
|
+
return '' + str;
|
203
|
+
}
|
204
|
+
};
|
205
|
+
|
206
|
+
/*
|
207
|
+
This lets us detect if an Array contains a given element
|
208
|
+
Signature:
|
209
|
+
Array.indexOf(item, fromIndex, compareFunc) == Integer
|
210
|
+
Arguments:
|
211
|
+
item - Object - object to locate in the Array
|
212
|
+
fromIndex - Integer (optional) - starts checking from this position in the Array
|
213
|
+
compareFunc - Function (optional) - function used to compare Array item vs passed item
|
214
|
+
Returns:
|
215
|
+
Integer - index position in the Array of the passed item
|
216
|
+
Examples:
|
217
|
+
['hi','there'].indexOf("guys") === -1
|
218
|
+
['hi','there'].indexOf("hi") === 0
|
219
|
+
*/
|
220
|
+
if (!Array.prototype.indexOf)
|
221
|
+
{
|
222
|
+
Array.prototype.indexOf = function(item, fromIndex, compareFunc)
|
223
|
+
{
|
224
|
+
if (!fromIndex)
|
225
|
+
{
|
226
|
+
fromIndex = -1;
|
227
|
+
}
|
228
|
+
var index = -1;
|
229
|
+
for (var i = fromIndex; i < this.length; i++)
|
230
|
+
{
|
231
|
+
if (this[i] === item || compareFunc && compareFunc(this[i], item))
|
232
|
+
{
|
233
|
+
index = i;
|
234
|
+
break;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
return index;
|
238
|
+
};
|
239
|
+
}
|
240
|
+
|
241
|
+
/*
|
242
|
+
You can override this list for all Strings or just one depending on if you
|
243
|
+
set the new values on prototype or on a given String instance.
|
244
|
+
*/
|
245
|
+
if (!String.prototype._uncountable_words)
|
246
|
+
{
|
247
|
+
String.prototype._uncountable_words = InflectionJS.uncountable_words;
|
248
|
+
}
|
249
|
+
|
250
|
+
/*
|
251
|
+
You can override this list for all Strings or just one depending on if you
|
252
|
+
set the new values on prototype or on a given String instance.
|
253
|
+
*/
|
254
|
+
if (!String.prototype._plural_rules)
|
255
|
+
{
|
256
|
+
String.prototype._plural_rules = InflectionJS.plural_rules;
|
257
|
+
}
|
258
|
+
|
259
|
+
/*
|
260
|
+
You can override this list for all Strings or just one depending on if you
|
261
|
+
set the new values on prototype or on a given String instance.
|
262
|
+
*/
|
263
|
+
if (!String.prototype._singular_rules)
|
264
|
+
{
|
265
|
+
String.prototype._singular_rules = InflectionJS.singular_rules;
|
266
|
+
}
|
267
|
+
|
268
|
+
/*
|
269
|
+
You can override this list for all Strings or just one depending on if you
|
270
|
+
set the new values on prototype or on a given String instance.
|
271
|
+
*/
|
272
|
+
if (!String.prototype._non_titlecased_words)
|
273
|
+
{
|
274
|
+
String.prototype._non_titlecased_words = InflectionJS.non_titlecased_words;
|
275
|
+
}
|
276
|
+
|
277
|
+
/*
|
278
|
+
This function adds plurilization support to every String object
|
279
|
+
Signature:
|
280
|
+
String.pluralize(plural) == String
|
281
|
+
Arguments:
|
282
|
+
plural - String (optional) - overrides normal output with said String
|
283
|
+
Returns:
|
284
|
+
String - singular English language nouns are returned in plural form
|
285
|
+
Examples:
|
286
|
+
"person".pluralize() == "people"
|
287
|
+
"octopus".pluralize() == "octopi"
|
288
|
+
"Hat".pluralize() == "Hats"
|
289
|
+
"person".pluralize("guys") == "guys"
|
290
|
+
*/
|
291
|
+
if (!String.prototype.pluralize)
|
292
|
+
{
|
293
|
+
String.prototype.pluralize = function(plural)
|
294
|
+
{
|
295
|
+
return InflectionJS.apply_rules(
|
296
|
+
this,
|
297
|
+
this._plural_rules,
|
298
|
+
this._uncountable_words,
|
299
|
+
plural
|
300
|
+
);
|
301
|
+
};
|
302
|
+
}
|
303
|
+
|
304
|
+
/*
|
305
|
+
This function adds singularization support to every String object
|
306
|
+
Signature:
|
307
|
+
String.singularize(singular) == String
|
308
|
+
Arguments:
|
309
|
+
singular - String (optional) - overrides normal output with said String
|
310
|
+
Returns:
|
311
|
+
String - plural English language nouns are returned in singular form
|
312
|
+
Examples:
|
313
|
+
"people".singularize() == "person"
|
314
|
+
"octopi".singularize() == "octopus"
|
315
|
+
"Hats".singularize() == "Hat"
|
316
|
+
"guys".singularize("person") == "person"
|
317
|
+
*/
|
318
|
+
if (!String.prototype.singularize)
|
319
|
+
{
|
320
|
+
String.prototype.singularize = function(singular)
|
321
|
+
{
|
322
|
+
return InflectionJS.apply_rules(
|
323
|
+
this,
|
324
|
+
this._singular_rules,
|
325
|
+
this._uncountable_words,
|
326
|
+
singular
|
327
|
+
);
|
328
|
+
};
|
329
|
+
}
|
330
|
+
|
331
|
+
/*
|
332
|
+
This function adds camelization support to every String object
|
333
|
+
Signature:
|
334
|
+
String.camelize(lowFirstLetter) == String
|
335
|
+
Arguments:
|
336
|
+
lowFirstLetter - boolean (optional) - default is to capitalize the first
|
337
|
+
letter of the results... passing true will lowercase it
|
338
|
+
Returns:
|
339
|
+
String - lower case underscored words will be returned in camel case
|
340
|
+
additionally '/' is translated to '::'
|
341
|
+
Examples:
|
342
|
+
"message_properties".camelize() == "MessageProperties"
|
343
|
+
"message_properties".camelize(true) == "messageProperties"
|
344
|
+
*/
|
345
|
+
if (!String.prototype.camelize)
|
346
|
+
{
|
347
|
+
String.prototype.camelize = function(lowFirstLetter)
|
348
|
+
{
|
349
|
+
var str = this.toLowerCase();
|
350
|
+
var str_path = str.split('/');
|
351
|
+
for (var i = 0; i < str_path.length; i++)
|
352
|
+
{
|
353
|
+
var str_arr = str_path[i].split('_');
|
354
|
+
var initX = ((lowFirstLetter && i + 1 === str_path.length) ? (1) : (0));
|
355
|
+
for (var x = initX; x < str_arr.length; x++)
|
356
|
+
{
|
357
|
+
str_arr[x] = str_arr[x].charAt(0).toUpperCase() + str_arr[x].substring(1);
|
358
|
+
}
|
359
|
+
str_path[i] = str_arr.join('');
|
360
|
+
}
|
361
|
+
str = str_path.join('::');
|
362
|
+
return '' + str;
|
363
|
+
};
|
364
|
+
}
|
365
|
+
|
366
|
+
/*
|
367
|
+
This function adds underscore support to every String object
|
368
|
+
Signature:
|
369
|
+
String.underscore() == String
|
370
|
+
Arguments:
|
371
|
+
N/A
|
372
|
+
Returns:
|
373
|
+
String - camel cased words are returned as lower cased and underscored
|
374
|
+
additionally '::' is translated to '/'
|
375
|
+
Examples:
|
376
|
+
"MessageProperties".camelize() == "message_properties"
|
377
|
+
"messageProperties".underscore() == "message_properties"
|
378
|
+
*/
|
379
|
+
if (!String.prototype.underscore)
|
380
|
+
{
|
381
|
+
String.prototype.underscore = function()
|
382
|
+
{
|
383
|
+
var str = this;
|
384
|
+
var str_path = str.split('::');
|
385
|
+
for (var i = 0; i < str_path.length; i++)
|
386
|
+
{
|
387
|
+
str_path[i] = str_path[i].replace(InflectionJS.uppercase, '_$1');
|
388
|
+
str_path[i] = str_path[i].replace(InflectionJS.underbar_prefix, '');
|
389
|
+
}
|
390
|
+
str = str_path.join('/').toLowerCase();
|
391
|
+
return '' + str;
|
392
|
+
};
|
393
|
+
}
|
394
|
+
|
395
|
+
/*
|
396
|
+
This function adds humanize support to every String object
|
397
|
+
Signature:
|
398
|
+
String.humanize(lowFirstLetter) == String
|
399
|
+
Arguments:
|
400
|
+
lowFirstLetter - boolean (optional) - default is to capitalize the first
|
401
|
+
letter of the results... passing true will lowercase it
|
402
|
+
Returns:
|
403
|
+
String - lower case underscored words will be returned in humanized form
|
404
|
+
Examples:
|
405
|
+
"message_properties".humanize() == "Message properties"
|
406
|
+
"message_properties".humanize(true) == "message properties"
|
407
|
+
*/
|
408
|
+
if (!String.prototype.humanize)
|
409
|
+
{
|
410
|
+
String.prototype.humanize = function(lowFirstLetter)
|
411
|
+
{
|
412
|
+
var str = this.toLowerCase();
|
413
|
+
str = str.replace(InflectionJS.id_suffix, '');
|
414
|
+
str = str.replace(InflectionJS.underbar, ' ');
|
415
|
+
if (!lowFirstLetter)
|
416
|
+
{
|
417
|
+
str = str.capitalize();
|
418
|
+
}
|
419
|
+
return '' + str;
|
420
|
+
};
|
421
|
+
}
|
422
|
+
|
423
|
+
/*
|
424
|
+
This function adds capitalization support to every String object
|
425
|
+
Signature:
|
426
|
+
String.capitalize() == String
|
427
|
+
Arguments:
|
428
|
+
N/A
|
429
|
+
Returns:
|
430
|
+
String - all characters will be lower case and the first will be upper
|
431
|
+
Examples:
|
432
|
+
"message_properties".capitalize() == "Message_properties"
|
433
|
+
"message properties".capitalize() == "Message properties"
|
434
|
+
*/
|
435
|
+
if (!String.prototype.capitalize)
|
436
|
+
{
|
437
|
+
String.prototype.capitalize = function()
|
438
|
+
{
|
439
|
+
var str = this.toLowerCase();
|
440
|
+
str = str.substring(0, 1).toUpperCase() + str.substring(1);
|
441
|
+
return '' + str;
|
442
|
+
};
|
443
|
+
}
|
444
|
+
|
445
|
+
/*
|
446
|
+
This function adds dasherization support to every String object
|
447
|
+
Signature:
|
448
|
+
String.dasherize() == String
|
449
|
+
Arguments:
|
450
|
+
N/A
|
451
|
+
Returns:
|
452
|
+
String - replaces all spaces or underbars with dashes
|
453
|
+
Examples:
|
454
|
+
"message_properties".capitalize() == "message-properties"
|
455
|
+
"Message Properties".capitalize() == "Message-Properties"
|
456
|
+
*/
|
457
|
+
if (!String.prototype.dasherize)
|
458
|
+
{
|
459
|
+
String.prototype.dasherize = function()
|
460
|
+
{
|
461
|
+
var str = this;
|
462
|
+
str = str.replace(InflectionJS.space_or_underbar, '-');
|
463
|
+
return '' + str;
|
464
|
+
};
|
465
|
+
}
|
466
|
+
|
467
|
+
/*
|
468
|
+
This function adds titleize support to every String object
|
469
|
+
Signature:
|
470
|
+
String.titleize() == String
|
471
|
+
Arguments:
|
472
|
+
N/A
|
473
|
+
Returns:
|
474
|
+
String - capitalizes words as you would for a book title
|
475
|
+
Examples:
|
476
|
+
"message_properties".titleize() == "Message Properties"
|
477
|
+
"message properties to keep".titleize() == "Message Properties to Keep"
|
478
|
+
*/
|
479
|
+
if (!String.prototype.titleize)
|
480
|
+
{
|
481
|
+
String.prototype.titleize = function()
|
482
|
+
{
|
483
|
+
var str = this.toLowerCase();
|
484
|
+
str = str.replace(InflectionJS.underbar, ' ');
|
485
|
+
var str_arr = str.split(' ');
|
486
|
+
for (var x = 0; x < str_arr.length; x++)
|
487
|
+
{
|
488
|
+
var d = str_arr[x].split('-');
|
489
|
+
for (var i = 0; i < d.length; i++)
|
490
|
+
{
|
491
|
+
if (this._non_titlecased_words.indexOf(d[i].toLowerCase()) < 0)
|
492
|
+
{
|
493
|
+
d[i] = d[i].capitalize();
|
494
|
+
}
|
495
|
+
}
|
496
|
+
str_arr[x] = d.join('-');
|
497
|
+
}
|
498
|
+
str = str_arr.join(' ');
|
499
|
+
str = str.substring(0, 1).toUpperCase() + str.substring(1);
|
500
|
+
return '' + str;
|
501
|
+
};
|
502
|
+
}
|
503
|
+
|
504
|
+
/*
|
505
|
+
This function adds demodulize support to every String object
|
506
|
+
Signature:
|
507
|
+
String.demodulize() == String
|
508
|
+
Arguments:
|
509
|
+
N/A
|
510
|
+
Returns:
|
511
|
+
String - removes module names leaving only class names (Ruby style)
|
512
|
+
Examples:
|
513
|
+
"Message::Bus::Properties".demodulize() == "Properties"
|
514
|
+
*/
|
515
|
+
if (!String.prototype.demodulize)
|
516
|
+
{
|
517
|
+
String.prototype.demodulize = function()
|
518
|
+
{
|
519
|
+
var str = this;
|
520
|
+
var str_arr = str.split('::');
|
521
|
+
str = str_arr[str_arr.length - 1];
|
522
|
+
return '' + str;
|
523
|
+
};
|
524
|
+
}
|
525
|
+
|
526
|
+
/*
|
527
|
+
This function adds tableize support to every String object
|
528
|
+
Signature:
|
529
|
+
String.tableize() == String
|
530
|
+
Arguments:
|
531
|
+
N/A
|
532
|
+
Returns:
|
533
|
+
String - renders camel cased words into their underscored plural form
|
534
|
+
Examples:
|
535
|
+
"MessageBusProperty".tableize() == "message_bus_properties"
|
536
|
+
*/
|
537
|
+
if (!String.prototype.tableize)
|
538
|
+
{
|
539
|
+
String.prototype.tableize = function()
|
540
|
+
{
|
541
|
+
var str = this;
|
542
|
+
str = str.underscore().pluralize();
|
543
|
+
return '' + str;
|
544
|
+
};
|
545
|
+
}
|
546
|
+
|
547
|
+
/*
|
548
|
+
This function adds classification support to every String object
|
549
|
+
Signature:
|
550
|
+
String.classify() == String
|
551
|
+
Arguments:
|
552
|
+
N/A
|
553
|
+
Returns:
|
554
|
+
String - underscored plural nouns become the camel cased singular form
|
555
|
+
Examples:
|
556
|
+
"message_bus_properties".classify() == "MessageBusProperty"
|
557
|
+
*/
|
558
|
+
if (!String.prototype.classify)
|
559
|
+
{
|
560
|
+
String.prototype.classify = function()
|
561
|
+
{
|
562
|
+
var str = this;
|
563
|
+
str = str.camelize().singularize();
|
564
|
+
return '' + str;
|
565
|
+
};
|
566
|
+
}
|
567
|
+
|
568
|
+
/*
|
569
|
+
This function adds foreign key support to every String object
|
570
|
+
Signature:
|
571
|
+
String.foreign_key(dropIdUbar) == String
|
572
|
+
Arguments:
|
573
|
+
dropIdUbar - boolean (optional) - default is to seperate id with an
|
574
|
+
underbar at the end of the class name, you can pass true to skip it
|
575
|
+
Returns:
|
576
|
+
String - camel cased singular class names become underscored with id
|
577
|
+
Examples:
|
578
|
+
"MessageBusProperty".foreign_key() == "message_bus_property_id"
|
579
|
+
"MessageBusProperty".foreign_key(true) == "message_bus_propertyid"
|
580
|
+
*/
|
581
|
+
if (!String.prototype.foreign_key)
|
582
|
+
{
|
583
|
+
String.prototype.foreign_key = function(dropIdUbar)
|
584
|
+
{
|
585
|
+
var str = this;
|
586
|
+
str = str.demodulize().underscore() + ((dropIdUbar) ? ('') : ('_')) + 'id';
|
587
|
+
return '' + str;
|
588
|
+
};
|
589
|
+
}
|
590
|
+
|
591
|
+
/*
|
592
|
+
This function adds ordinalize support to every String object
|
593
|
+
Signature:
|
594
|
+
String.ordinalize() == String
|
595
|
+
Arguments:
|
596
|
+
N/A
|
597
|
+
Returns:
|
598
|
+
String - renders all found numbers their sequence like "22nd"
|
599
|
+
Examples:
|
600
|
+
"the 1 pitch".ordinalize() == "the 1st pitch"
|
601
|
+
*/
|
602
|
+
if (!String.prototype.ordinalize)
|
603
|
+
{
|
604
|
+
String.prototype.ordinalize = function()
|
605
|
+
{
|
606
|
+
var str = this;
|
607
|
+
var str_arr = str.split(' ');
|
608
|
+
for (var x = 0; x < str_arr.length; x++)
|
609
|
+
{
|
610
|
+
var i = parseInt(str_arr[x], 10);
|
611
|
+
if (!isNaN(i))
|
612
|
+
{
|
613
|
+
var ltd = str_arr[x].substring(str_arr[x].length - 2);
|
614
|
+
var ld = str_arr[x].substring(str_arr[x].length - 1);
|
615
|
+
var suf = "th";
|
616
|
+
if (ltd != "11" && ltd != "12" && ltd != "13")
|
617
|
+
{
|
618
|
+
if (ld === "1")
|
619
|
+
{
|
620
|
+
suf = "st";
|
621
|
+
}
|
622
|
+
else if (ld === "2")
|
623
|
+
{
|
624
|
+
suf = "nd";
|
625
|
+
}
|
626
|
+
else if (ld === "3")
|
627
|
+
{
|
628
|
+
suf = "rd";
|
629
|
+
}
|
630
|
+
}
|
631
|
+
str_arr[x] += suf;
|
632
|
+
}
|
633
|
+
}
|
634
|
+
str = str_arr.join(' ');
|
635
|
+
return '' + str;
|
636
|
+
};
|
637
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: material_raingular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Moody
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -103,7 +103,25 @@ files:
|
|
103
103
|
- lib/assets/javascripts/identifier_interceptor.js.coffee
|
104
104
|
- lib/assets/javascripts/material_filters.coffee
|
105
105
|
- lib/assets/javascripts/material_raingular.js.coffee
|
106
|
+
- lib/assets/javascripts/material_raingular/directives/callback/controller.coffee
|
107
|
+
- lib/assets/javascripts/material_raingular/directives/callback/directive.coffee
|
108
|
+
- lib/assets/javascripts/material_raingular/directives/destroy/directive.coffee
|
109
|
+
- lib/assets/javascripts/material_raingular/directives/destroy/linkmodel.coffee
|
110
|
+
- lib/assets/javascripts/material_raingular/directives/update/directive.coffee
|
111
|
+
- lib/assets/javascripts/material_raingular/directives/update/linkmodel.coffee
|
106
112
|
- lib/assets/javascripts/rails_updater.coffee
|
113
|
+
- lib/assets/javascripts/super_classes/angular_compile_model.coffee
|
114
|
+
- lib/assets/javascripts/super_classes/angular_directive.coffee
|
115
|
+
- lib/assets/javascripts/super_classes/angular_directive_model.coffee
|
116
|
+
- lib/assets/javascripts/super_classes/angular_link_model.coffee
|
117
|
+
- lib/assets/javascripts/super_classes/angular_model.coffee
|
118
|
+
- lib/assets/javascripts/super_classes/angular_route_model.coffee
|
119
|
+
- lib/assets/javascripts/super_classes/angular_scoped_model.coffee
|
120
|
+
- lib/assets/javascripts/super_classes/angular_service_model.coffee
|
121
|
+
- lib/assets/javascripts/super_classes/angular_view_model.coffee
|
122
|
+
- lib/assets/javascripts/super_classes/material_modal_model.coffee
|
123
|
+
- lib/assets/javascripts/super_classes/module.coffee
|
124
|
+
- lib/assets/javascripts/super_classes/panel_config.coffee
|
107
125
|
- lib/assets/stylesheets/material-raingular.sass
|
108
126
|
- lib/material_raingular.rb
|
109
127
|
- lib/material_raingular/version.rb
|
@@ -124,6 +142,7 @@ files:
|
|
124
142
|
- vendor/assets/angular/angular-sanitize.js
|
125
143
|
- vendor/assets/angular/angular-touch.js
|
126
144
|
- vendor/assets/angular/angular.js
|
145
|
+
- vendor/assets/angular/inflections.js
|
127
146
|
homepage: ''
|
128
147
|
licenses:
|
129
148
|
- MIT
|