opal-activesupport 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -3
- data/README.md +12 -3
- data/lib/opal/activesupport/version.rb +1 -1
- data/opal-activesupport.gemspec +2 -2
- data/opal/active_support/core_ext.rb +4 -1
- data/opal/active_support/core_ext/enumerable.rb +32 -0
- data/opal/active_support/core_ext/object/json.rb +37 -0
- data/opal/active_support/core_ext/string.rb +6 -7
- data/opal/active_support/core_ext/string/inflections.rb +9 -0
- data/opal/active_support/inflections.rb +62 -0
- data/opal/active_support/inflector.rb +2 -0
- data/opal/active_support/inflector/inflections.rb +67 -0
- data/spec/spec_helper.rb +1 -0
- metadata +34 -21
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 68c3aa1ca269d78c62c238b7d32662a999ab0078
|
|
4
|
+
data.tar.gz: 5d55aed5af016912fdaabf71ac1a9470a153e01c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c17e86c15b2d703f89eb8a6ef63719fff43ecaf245917a4b7ed6327e4253c4511004466228b9368b5730d9126c1406adcabdf57c6a5fa851d210f0e0983f7f73
|
|
7
|
+
data.tar.gz: f5f730351e43750e5a06747bbb2528776fe6cbf488eec25dbadeae2d309eb83a0b9fd5f4dc4012b2b91bdf797d60013dceaac09033a7c64c44b148adb8a729c8
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
# Opal
|
|
1
|
+
# Opal: ActiveSupport
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> @AstonJ But it's vanilla Ruby. It's not like you have ActiveSupport available, which somewhat defeats it for me.
|
|
4
|
+
— @dhh, https://twitter.com/dhh/status/260783823254601728
|
|
4
5
|
|
|
5
6
|
## Installation
|
|
6
7
|
|
|
@@ -16,9 +17,17 @@ Or install it yourself as:
|
|
|
16
17
|
|
|
17
18
|
$ gem install opal-activesupport
|
|
18
19
|
|
|
20
|
+
|
|
19
21
|
## Usage
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
Inside your `application.js.rb`:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
require 'active_support' # to require the whole active support lib
|
|
27
|
+
require 'active_support/core_ext' # require only the corelib extensions
|
|
28
|
+
require 'active_support/core_ext/string' # require only the corelib extensions
|
|
29
|
+
```
|
|
30
|
+
|
|
22
31
|
|
|
23
32
|
## Contributing
|
|
24
33
|
|
data/opal-activesupport.gemspec
CHANGED
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
|
|
|
20
20
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
21
21
|
gem.require_paths = ['lib']
|
|
22
22
|
|
|
23
|
-
gem.add_dependency 'opal'
|
|
23
|
+
gem.add_dependency 'opal', ['>= 0.5.0', '< 1.0.0']
|
|
24
|
+
gem.add_development_dependency 'opal-rspec', '~> 0.4.0'
|
|
24
25
|
gem.add_development_dependency 'rake'
|
|
25
|
-
gem.add_development_dependency 'opal-rspec'
|
|
26
26
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Enumerable
|
|
2
|
+
def index_by(&block)
|
|
3
|
+
return enum_for :index_by unless block_given?
|
|
4
|
+
|
|
5
|
+
hash = Hash.new
|
|
6
|
+
|
|
7
|
+
%x{
|
|
8
|
+
var result;
|
|
9
|
+
|
|
10
|
+
self.$each._p = function() {
|
|
11
|
+
var param = #{Opal.destructure(`arguments`)},
|
|
12
|
+
value = $opal.$yield1(block, param);
|
|
13
|
+
|
|
14
|
+
if (value === $breaker) {
|
|
15
|
+
result = $breaker.$v;
|
|
16
|
+
return $breaker;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#{hash[`value`] = `param`};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
self.$each();
|
|
23
|
+
|
|
24
|
+
if (result !== undefined) {
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
hash
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
class Object
|
|
4
|
+
def as_json
|
|
5
|
+
nil
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class Boolean
|
|
10
|
+
def as_json
|
|
11
|
+
self
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class NilClass
|
|
16
|
+
def as_json
|
|
17
|
+
self
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class Numeric
|
|
22
|
+
def as_json
|
|
23
|
+
self
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class String
|
|
28
|
+
def as_json
|
|
29
|
+
self
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class Array
|
|
34
|
+
def as_json(options = nil) #:nodoc:
|
|
35
|
+
map { |v| options ? v.as_json(options.dup) : v.as_json }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -4,9 +4,9 @@ class String
|
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
def dasherize
|
|
7
|
-
`#{self}.replace(/[-_
|
|
8
|
-
.replace(/([A-Z
|
|
9
|
-
.replace(/([a-z
|
|
7
|
+
`#{self}.replace(/[-_\s]+/g, '-')
|
|
8
|
+
.replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1-$2')
|
|
9
|
+
.replace(/([a-z\d])([A-Z])/g, '$1-$2')
|
|
10
10
|
.toLowerCase()`
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -23,9 +23,9 @@ class String
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def underscore
|
|
26
|
-
`#{self}.replace(/[
|
|
27
|
-
.replace(/([A-Z
|
|
28
|
-
.replace(/([a-z
|
|
26
|
+
`#{self}.replace(/[-\s]+/g, '_')
|
|
27
|
+
.replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1_$2')
|
|
28
|
+
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
|
|
29
29
|
.replace(/-/g, '_')
|
|
30
30
|
.toLowerCase()`
|
|
31
31
|
end
|
|
@@ -37,5 +37,4 @@ class String
|
|
|
37
37
|
})`
|
|
38
38
|
end
|
|
39
39
|
alias_method :camelcase, :camelize
|
|
40
|
-
|
|
41
40
|
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module ActiveSupport
|
|
2
|
+
Inflector.inflections(:en) do |inflect|
|
|
3
|
+
inflect.plural(/$/, 's')
|
|
4
|
+
inflect.plural(/s$/i, 's')
|
|
5
|
+
inflect.plural(/^(ax|test)is$/i, '\1es')
|
|
6
|
+
inflect.plural(/(octop|vir)us$/i, '\1i')
|
|
7
|
+
inflect.plural(/(octop|vir)i$/i, '\1i')
|
|
8
|
+
inflect.plural(/(alias|status)$/i, '\1es')
|
|
9
|
+
inflect.plural(/(bu)s$/i, '\1ses')
|
|
10
|
+
inflect.plural(/(buffal|tomat)o$/i, '\1oes')
|
|
11
|
+
inflect.plural(/([ti])um$/i, '\1a')
|
|
12
|
+
inflect.plural(/([ti])a$/i, '\1a')
|
|
13
|
+
inflect.plural(/sis$/i, 'ses')
|
|
14
|
+
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
|
|
15
|
+
inflect.plural(/(hive)$/i, '\1s')
|
|
16
|
+
inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
|
|
17
|
+
inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
|
|
18
|
+
inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '\1ices')
|
|
19
|
+
inflect.plural(/^(m|l)ouse$/i, '\1ice')
|
|
20
|
+
inflect.plural(/^(m|l)ice$/i, '\1ice')
|
|
21
|
+
inflect.plural(/^(ox)$/i, '\1en')
|
|
22
|
+
inflect.plural(/^(oxen)$/i, '\1')
|
|
23
|
+
inflect.plural(/(quiz)$/i, '\1zes')
|
|
24
|
+
|
|
25
|
+
inflect.singular(/s$/i, '')
|
|
26
|
+
inflect.singular(/(ss)$/i, '\1')
|
|
27
|
+
inflect.singular(/(n)ews$/i, '\1ews')
|
|
28
|
+
inflect.singular(/([ti])a$/i, '\1um')
|
|
29
|
+
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '\1sis')
|
|
30
|
+
inflect.singular(/(^analy)(sis|ses)$/i, '\1sis')
|
|
31
|
+
inflect.singular(/([^f])ves$/i, '\1fe')
|
|
32
|
+
inflect.singular(/(hive)s$/i, '\1')
|
|
33
|
+
inflect.singular(/(tive)s$/i, '\1')
|
|
34
|
+
inflect.singular(/([lr])ves$/i, '\1f')
|
|
35
|
+
inflect.singular(/([^aeiouy]|qu)ies$/i, '\1y')
|
|
36
|
+
inflect.singular(/(s)eries$/i, '\1eries')
|
|
37
|
+
inflect.singular(/(m)ovies$/i, '\1ovie')
|
|
38
|
+
inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
|
|
39
|
+
inflect.singular(/^(m|l)ice$/i, '\1ouse')
|
|
40
|
+
inflect.singular(/(bus)(es)?$/i, '\1')
|
|
41
|
+
inflect.singular(/(o)es$/i, '\1')
|
|
42
|
+
inflect.singular(/(shoe)s$/i, '\1')
|
|
43
|
+
inflect.singular(/(cris|test)(is|es)$/i, '\1is')
|
|
44
|
+
inflect.singular(/^(a)x[ie]s$/i, '\1xis')
|
|
45
|
+
inflect.singular(/(octop|vir)(us|i)$/i, '\1us')
|
|
46
|
+
inflect.singular(/(alias|status)(es)?$/i, '\1')
|
|
47
|
+
inflect.singular(/^(ox)en/i, '\1')
|
|
48
|
+
inflect.singular(/(vert|ind)ices$/i, '\1ex')
|
|
49
|
+
inflect.singular(/(matr)ices$/i, '\1ix')
|
|
50
|
+
inflect.singular(/(quiz)zes$/i, '\1')
|
|
51
|
+
inflect.singular(/(database)s$/i, '\1')
|
|
52
|
+
|
|
53
|
+
inflect.irregular('person', 'people')
|
|
54
|
+
inflect.irregular('man', 'men')
|
|
55
|
+
inflect.irregular('child', 'children')
|
|
56
|
+
inflect.irregular('sex', 'sexes')
|
|
57
|
+
inflect.irregular('move', 'moves')
|
|
58
|
+
inflect.irregular('zombie', 'zombies')
|
|
59
|
+
|
|
60
|
+
inflect.uncountable(%w(equipment information rice money species series fish sheep jeans police))
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module ActiveSupport
|
|
2
|
+
module Inflector
|
|
3
|
+
extend self
|
|
4
|
+
|
|
5
|
+
def inflections
|
|
6
|
+
if block_given?
|
|
7
|
+
yield Inflections.instance
|
|
8
|
+
else
|
|
9
|
+
Inflections.instance
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def pluralize(word)
|
|
14
|
+
apply_inflections(word, inflections.plurals)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def singularize(word)
|
|
18
|
+
apply_inflections(word, inflections.singulars)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def apply_inflections(word, rules)
|
|
22
|
+
result = word.to_s
|
|
23
|
+
|
|
24
|
+
if inflections.uncountables.include?(result.downcase)
|
|
25
|
+
result
|
|
26
|
+
else
|
|
27
|
+
rules.each do |rule, replacement|
|
|
28
|
+
changed = result.sub(rule, replacement)
|
|
29
|
+
unless changed == result
|
|
30
|
+
result = changed
|
|
31
|
+
break
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
result
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class Inflections
|
|
40
|
+
def self.instance
|
|
41
|
+
@__instance__ ||= new
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
attr_reader :plurals, :singulars, :uncountables
|
|
45
|
+
|
|
46
|
+
def initialize
|
|
47
|
+
@plurals, @singulars, @uncountables = [], [], Set.new
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def plural(rule, replacement)
|
|
51
|
+
@plurals.unshift([rule, replacement])
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def singular(rule, replacement)
|
|
55
|
+
@singulars.unshift([rule, replacement])
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def uncountable(words)
|
|
59
|
+
words.each { |w| @uncountables << w.downcase }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def irregular()
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,55 +1,61 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opal-activesupport
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Elia Schito
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: opal
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- -
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 0.5.0
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 1.0.0
|
|
20
23
|
type: :runtime
|
|
21
24
|
prerelease: false
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
26
|
requirements:
|
|
24
|
-
- -
|
|
27
|
+
- - ">="
|
|
25
28
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
29
|
+
version: 0.5.0
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.0.0
|
|
27
33
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
34
|
+
name: opal-rspec
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
|
30
36
|
requirements:
|
|
31
|
-
- -
|
|
37
|
+
- - "~>"
|
|
32
38
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
39
|
+
version: 0.4.0
|
|
34
40
|
type: :development
|
|
35
41
|
prerelease: false
|
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
43
|
requirements:
|
|
38
|
-
- -
|
|
44
|
+
- - "~>"
|
|
39
45
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
46
|
+
version: 0.4.0
|
|
41
47
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
48
|
+
name: rake
|
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
|
44
50
|
requirements:
|
|
45
|
-
- -
|
|
51
|
+
- - ">="
|
|
46
52
|
- !ruby/object:Gem::Version
|
|
47
53
|
version: '0'
|
|
48
54
|
type: :development
|
|
49
55
|
prerelease: false
|
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
57
|
requirements:
|
|
52
|
-
- -
|
|
58
|
+
- - ">="
|
|
53
59
|
- !ruby/object:Gem::Version
|
|
54
60
|
version: '0'
|
|
55
61
|
description: The port of the glorious ActiveSupport for Opal
|
|
@@ -59,7 +65,7 @@ executables: []
|
|
|
59
65
|
extensions: []
|
|
60
66
|
extra_rdoc_files: []
|
|
61
67
|
files:
|
|
62
|
-
- .gitignore
|
|
68
|
+
- ".gitignore"
|
|
63
69
|
- Gemfile
|
|
64
70
|
- LICENSE.txt
|
|
65
71
|
- README.md
|
|
@@ -70,6 +76,7 @@ files:
|
|
|
70
76
|
- opal-activesupport.gemspec
|
|
71
77
|
- opal/active_support.rb
|
|
72
78
|
- opal/active_support/core_ext.rb
|
|
79
|
+
- opal/active_support/core_ext/enumerable.rb
|
|
73
80
|
- opal/active_support/core_ext/integer.rb
|
|
74
81
|
- opal/active_support/core_ext/integer/time.rb
|
|
75
82
|
- opal/active_support/core_ext/numeric.rb
|
|
@@ -77,7 +84,12 @@ files:
|
|
|
77
84
|
- opal/active_support/core_ext/numeric/time.rb
|
|
78
85
|
- opal/active_support/core_ext/object.rb
|
|
79
86
|
- opal/active_support/core_ext/object/blank.rb
|
|
87
|
+
- opal/active_support/core_ext/object/json.rb
|
|
80
88
|
- opal/active_support/core_ext/string.rb
|
|
89
|
+
- opal/active_support/core_ext/string/inflections.rb
|
|
90
|
+
- opal/active_support/inflections.rb
|
|
91
|
+
- opal/active_support/inflector.rb
|
|
92
|
+
- opal/active_support/inflector/inflections.rb
|
|
81
93
|
- opal/active_support/time.rb
|
|
82
94
|
- opal/opal-activesupport.rb
|
|
83
95
|
- spec/core_ext/numeric_spec.rb
|
|
@@ -91,26 +103,26 @@ licenses: []
|
|
|
91
103
|
metadata: {}
|
|
92
104
|
post_install_message:
|
|
93
105
|
rdoc_options:
|
|
94
|
-
- --main
|
|
106
|
+
- "--main"
|
|
95
107
|
- README
|
|
96
|
-
- --line-numbers
|
|
97
|
-
- --include
|
|
108
|
+
- "--line-numbers"
|
|
109
|
+
- "--include"
|
|
98
110
|
- opal
|
|
99
111
|
require_paths:
|
|
100
112
|
- lib
|
|
101
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
114
|
requirements:
|
|
103
|
-
- -
|
|
115
|
+
- - ">="
|
|
104
116
|
- !ruby/object:Gem::Version
|
|
105
117
|
version: '0'
|
|
106
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
119
|
requirements:
|
|
108
|
-
- -
|
|
120
|
+
- - ">="
|
|
109
121
|
- !ruby/object:Gem::Version
|
|
110
122
|
version: '0'
|
|
111
123
|
requirements: []
|
|
112
124
|
rubyforge_project:
|
|
113
|
-
rubygems_version: 2.
|
|
125
|
+
rubygems_version: 2.4.5
|
|
114
126
|
signing_key:
|
|
115
127
|
specification_version: 4
|
|
116
128
|
summary: The port of the glorious ActiveSupport for Opal
|
|
@@ -121,3 +133,4 @@ test_files:
|
|
|
121
133
|
- spec/empty_bool.rb
|
|
122
134
|
- spec/inflector_test_cases.rb
|
|
123
135
|
- spec/spec_helper.rb
|
|
136
|
+
has_rdoc:
|