ruby2js 1.10.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -2
- data/lib/ruby2js.rb +3 -0
- data/lib/ruby2js/filter/camelCase.rb +87 -0
- data/lib/ruby2js/version.rb +1 -1
- data/ruby2js.gemspec +3 -3
- metadata +50 -49
data/README.md
CHANGED
@@ -130,10 +130,15 @@ filters are selected, they will all be applied in parallel in one pass through
|
|
130
130
|
the script.
|
131
131
|
|
132
132
|
* [strict](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/filter/strict.rb)
|
133
|
-
adds `'use strict';` to the output
|
133
|
+
adds `'use strict';` to the output.
|
134
134
|
|
135
135
|
* [return](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/filter/return.rb)
|
136
|
-
adds `return` to the last expression in functions
|
136
|
+
adds `return` to the last expression in functions.
|
137
|
+
|
138
|
+
* [camelCase](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/filter/camelCase.rb)
|
139
|
+
converts `underscore_case` to `camelCase`. See
|
140
|
+
[camelCase_spec](https://github.com/rubys/ruby2js/blob/master/spec/camelCase_spec.rb)
|
141
|
+
for examples.
|
137
142
|
|
138
143
|
* [functions](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/filter/functions.rb)
|
139
144
|
|
data/lib/ruby2js.rb
CHANGED
@@ -26,6 +26,9 @@ module Ruby2JS
|
|
26
26
|
def on_sendw(node); on_send(node); end
|
27
27
|
def on_undefined?(node); on_defined?(node); end
|
28
28
|
|
29
|
+
# provide a method so filters can call 'super'
|
30
|
+
def on_sym(node); node; end
|
31
|
+
|
29
32
|
# convert map(&:symbol) to a block
|
30
33
|
def on_send(node)
|
31
34
|
if node.children.length > 2 and node.children.last.type == :block_pass
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'ruby2js'
|
2
|
+
|
3
|
+
module Ruby2JS
|
4
|
+
module Filter
|
5
|
+
module CamelCase
|
6
|
+
include SEXP
|
7
|
+
|
8
|
+
WHITELIST = %w{
|
9
|
+
attr_accessor
|
10
|
+
}
|
11
|
+
|
12
|
+
def camelCase(symbol)
|
13
|
+
symbol.to_s.gsub(/_[a-z]/) {|match| match[1].upcase}
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_send(node)
|
17
|
+
if node.children[0] == nil and WHITELIST.include? node.children[1].to_s
|
18
|
+
super
|
19
|
+
elsif node.children[1] =~ /_.*\w$/
|
20
|
+
super s((node.is_method? ? :send : :attr) , node.children[0],
|
21
|
+
camelCase(node.children[1]), *node.children[2..-1])
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_def(node)
|
28
|
+
if node.children[0] =~ /_.*\w$/
|
29
|
+
super s(:def , camelCase(node.children[0]), *node.children[1..-1])
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def on_optarg(node)
|
36
|
+
if node.children[0] =~ /_.*\w$/
|
37
|
+
super s(:optarg , camelCase(node.children[0]), *node.children[1..-1])
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def on_lvar(node)
|
44
|
+
if node.children[0] =~ /_.*\w$/
|
45
|
+
super s(:lvar , camelCase(node.children[0]), *node.children[1..-1])
|
46
|
+
else
|
47
|
+
super
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def on_arg(node)
|
52
|
+
if node.children[0] =~ /_.*\w$/
|
53
|
+
super s(:arg , camelCase(node.children[0]), *node.children[1..-1])
|
54
|
+
else
|
55
|
+
super
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def on_lvasgn(node)
|
60
|
+
if node.children[0] =~ /_.*\w$/
|
61
|
+
super s(:lvasgn , camelCase(node.children[0]), *node.children[1..-1])
|
62
|
+
else
|
63
|
+
super
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def on_sym(node)
|
68
|
+
if node.children[0] =~ /_.*\w$/
|
69
|
+
super s(:sym , camelCase(node.children[0]), *node.children[1..-1])
|
70
|
+
else
|
71
|
+
super
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def on_defs(node)
|
76
|
+
if node.children[1] =~ /_.*\w$/
|
77
|
+
super s(:defs , node.children[0],
|
78
|
+
camelCase(node.children[1]), *node.children[2..-1])
|
79
|
+
else
|
80
|
+
super
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
DEFAULTS.push CamelCase
|
86
|
+
end
|
87
|
+
end
|
data/lib/ruby2js/version.rb
CHANGED
data/ruby2js.gemspec
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "ruby2js"
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.11.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Sam Ruby"]
|
9
|
-
s.date = "2014-
|
9
|
+
s.date = "2014-11-03"
|
10
10
|
s.description = " The base package maps Ruby syntax to JavaScript semantics.\n Filters may be provided to add Ruby-specific or framework specific\n behavior.\n"
|
11
11
|
s.email = "rubys@intertwingly.net"
|
12
|
-
s.files = ["ruby2js.gemspec", "README.md", "lib/ruby2js
|
12
|
+
s.files = ["ruby2js.gemspec", "README.md", "lib/ruby2js", "lib/ruby2js/converter.rb", "lib/ruby2js/version.rb", "lib/ruby2js/filter", "lib/ruby2js/filter/jquery.rb", "lib/ruby2js/filter/return.rb", "lib/ruby2js/filter/underscore.rb", "lib/ruby2js/filter/angularrb.rb", "lib/ruby2js/filter/minitest-jasmine.rb", "lib/ruby2js/filter/camelCase.rb", "lib/ruby2js/filter/strict.rb", "lib/ruby2js/filter/functions.rb", "lib/ruby2js/filter/angular-resource.rb", "lib/ruby2js/filter/angular-route.rb", "lib/ruby2js/sinatra.rb", "lib/ruby2js/rails.rb", "lib/ruby2js/cgi.rb", "lib/ruby2js/converter", "lib/ruby2js/converter/self.rb", "lib/ruby2js/converter/arg.rb", "lib/ruby2js/converter/dstr.rb", "lib/ruby2js/converter/xstr.rb", "lib/ruby2js/converter/sym.rb", "lib/ruby2js/converter/return.rb", "lib/ruby2js/converter/break.rb", "lib/ruby2js/converter/for.rb", "lib/ruby2js/converter/defined.rb", "lib/ruby2js/converter/cvasgn.rb", "lib/ruby2js/converter/whilepost.rb", "lib/ruby2js/converter/logical.rb", "lib/ruby2js/converter/args.rb", "lib/ruby2js/converter/def.rb", "lib/ruby2js/converter/prototype.rb", "lib/ruby2js/converter/class.rb", "lib/ruby2js/converter/opasgn.rb", "lib/ruby2js/converter/module.rb", "lib/ruby2js/converter/kwbegin.rb", "lib/ruby2js/converter/send.rb", "lib/ruby2js/converter/boolean.rb", "lib/ruby2js/converter/masgn.rb", "lib/ruby2js/converter/hash.rb", "lib/ruby2js/converter/cvar.rb", "lib/ruby2js/converter/ivasgn.rb", "lib/ruby2js/converter/case.rb", "lib/ruby2js/converter/const.rb", "lib/ruby2js/converter/vasgn.rb", "lib/ruby2js/converter/untilpost.rb", "lib/ruby2js/converter/begin.rb", "lib/ruby2js/converter/ivar.rb", "lib/ruby2js/converter/while.rb", "lib/ruby2js/converter/next.rb", "lib/ruby2js/converter/nil.rb", "lib/ruby2js/converter/blockpass.rb", "lib/ruby2js/converter/super.rb", "lib/ruby2js/converter/defs.rb", "lib/ruby2js/converter/array.rb", "lib/ruby2js/converter/block.rb", "lib/ruby2js/converter/if.rb", "lib/ruby2js/converter/until.rb", "lib/ruby2js/converter/regexp.rb", "lib/ruby2js/converter/casgn.rb", "lib/ruby2js/converter/undef.rb", "lib/ruby2js/converter/literal.rb", "lib/ruby2js/converter/var.rb", "lib/ruby2js.rb"]
|
13
13
|
s.homepage = "http://github.com/rubys/ruby2js"
|
14
14
|
s.licenses = ["MIT"]
|
15
15
|
s.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parser
|
@@ -36,67 +36,68 @@ extra_rdoc_files: []
|
|
36
36
|
files:
|
37
37
|
- ruby2js.gemspec
|
38
38
|
- README.md
|
39
|
-
- lib/ruby2js.rb
|
40
39
|
- lib/ruby2js/converter.rb
|
41
40
|
- lib/ruby2js/version.rb
|
42
|
-
- lib/ruby2js/
|
41
|
+
- lib/ruby2js/filter/jquery.rb
|
42
|
+
- lib/ruby2js/filter/return.rb
|
43
|
+
- lib/ruby2js/filter/underscore.rb
|
44
|
+
- lib/ruby2js/filter/angularrb.rb
|
45
|
+
- lib/ruby2js/filter/minitest-jasmine.rb
|
46
|
+
- lib/ruby2js/filter/camelCase.rb
|
47
|
+
- lib/ruby2js/filter/strict.rb
|
48
|
+
- lib/ruby2js/filter/functions.rb
|
49
|
+
- lib/ruby2js/filter/angular-resource.rb
|
50
|
+
- lib/ruby2js/filter/angular-route.rb
|
51
|
+
- lib/ruby2js/sinatra.rb
|
43
52
|
- lib/ruby2js/rails.rb
|
44
|
-
- lib/ruby2js/
|
45
|
-
- lib/ruby2js/converter/begin.rb
|
46
|
-
- lib/ruby2js/converter/undef.rb
|
47
|
-
- lib/ruby2js/converter/kwbegin.rb
|
48
|
-
- lib/ruby2js/converter/const.rb
|
53
|
+
- lib/ruby2js/cgi.rb
|
49
54
|
- lib/ruby2js/converter/self.rb
|
50
|
-
- lib/ruby2js/converter/class.rb
|
51
|
-
- lib/ruby2js/converter/untilpost.rb
|
52
|
-
- lib/ruby2js/converter/while.rb
|
53
|
-
- lib/ruby2js/converter/blockpass.rb
|
54
|
-
- lib/ruby2js/converter/array.rb
|
55
|
-
- lib/ruby2js/converter/for.rb
|
56
|
-
- lib/ruby2js/converter/hash.rb
|
57
|
-
- lib/ruby2js/converter/block.rb
|
58
|
-
- lib/ruby2js/converter/def.rb
|
59
|
-
- lib/ruby2js/converter/nil.rb
|
60
|
-
- lib/ruby2js/converter/if.rb
|
61
|
-
- lib/ruby2js/converter/break.rb
|
62
|
-
- lib/ruby2js/converter/send.rb
|
63
|
-
- lib/ruby2js/converter/module.rb
|
64
|
-
- lib/ruby2js/converter/defs.rb
|
65
|
-
- lib/ruby2js/converter/ivar.rb
|
66
|
-
- lib/ruby2js/converter/var.rb
|
67
|
-
- lib/ruby2js/converter/case.rb
|
68
|
-
- lib/ruby2js/converter/literal.rb
|
69
|
-
- lib/ruby2js/converter/super.rb
|
70
|
-
- lib/ruby2js/converter/opasgn.rb
|
71
|
-
- lib/ruby2js/converter/return.rb
|
72
55
|
- lib/ruby2js/converter/arg.rb
|
73
|
-
- lib/ruby2js/converter/regexp.rb
|
74
|
-
- lib/ruby2js/converter/args.rb
|
75
|
-
- lib/ruby2js/converter/until.rb
|
76
56
|
- lib/ruby2js/converter/dstr.rb
|
77
|
-
- lib/ruby2js/converter/vasgn.rb
|
78
|
-
- lib/ruby2js/converter/whilepost.rb
|
79
57
|
- lib/ruby2js/converter/xstr.rb
|
58
|
+
- lib/ruby2js/converter/sym.rb
|
59
|
+
- lib/ruby2js/converter/return.rb
|
60
|
+
- lib/ruby2js/converter/break.rb
|
61
|
+
- lib/ruby2js/converter/for.rb
|
80
62
|
- lib/ruby2js/converter/defined.rb
|
81
|
-
- lib/ruby2js/converter/next.rb
|
82
|
-
- lib/ruby2js/converter/ivasgn.rb
|
83
63
|
- lib/ruby2js/converter/cvasgn.rb
|
64
|
+
- lib/ruby2js/converter/whilepost.rb
|
84
65
|
- lib/ruby2js/converter/logical.rb
|
85
|
-
- lib/ruby2js/converter/
|
66
|
+
- lib/ruby2js/converter/args.rb
|
67
|
+
- lib/ruby2js/converter/def.rb
|
68
|
+
- lib/ruby2js/converter/prototype.rb
|
69
|
+
- lib/ruby2js/converter/class.rb
|
70
|
+
- lib/ruby2js/converter/opasgn.rb
|
71
|
+
- lib/ruby2js/converter/module.rb
|
72
|
+
- lib/ruby2js/converter/kwbegin.rb
|
73
|
+
- lib/ruby2js/converter/send.rb
|
86
74
|
- lib/ruby2js/converter/boolean.rb
|
87
75
|
- lib/ruby2js/converter/masgn.rb
|
76
|
+
- lib/ruby2js/converter/hash.rb
|
88
77
|
- lib/ruby2js/converter/cvar.rb
|
78
|
+
- lib/ruby2js/converter/ivasgn.rb
|
79
|
+
- lib/ruby2js/converter/case.rb
|
80
|
+
- lib/ruby2js/converter/const.rb
|
81
|
+
- lib/ruby2js/converter/vasgn.rb
|
82
|
+
- lib/ruby2js/converter/untilpost.rb
|
83
|
+
- lib/ruby2js/converter/begin.rb
|
84
|
+
- lib/ruby2js/converter/ivar.rb
|
85
|
+
- lib/ruby2js/converter/while.rb
|
86
|
+
- lib/ruby2js/converter/next.rb
|
87
|
+
- lib/ruby2js/converter/nil.rb
|
88
|
+
- lib/ruby2js/converter/blockpass.rb
|
89
|
+
- lib/ruby2js/converter/super.rb
|
90
|
+
- lib/ruby2js/converter/defs.rb
|
91
|
+
- lib/ruby2js/converter/array.rb
|
92
|
+
- lib/ruby2js/converter/block.rb
|
93
|
+
- lib/ruby2js/converter/if.rb
|
94
|
+
- lib/ruby2js/converter/until.rb
|
95
|
+
- lib/ruby2js/converter/regexp.rb
|
89
96
|
- lib/ruby2js/converter/casgn.rb
|
90
|
-
- lib/ruby2js/
|
91
|
-
- lib/ruby2js/
|
92
|
-
- lib/ruby2js/
|
93
|
-
- lib/ruby2js
|
94
|
-
- lib/ruby2js/filter/return.rb
|
95
|
-
- lib/ruby2js/filter/underscore.rb
|
96
|
-
- lib/ruby2js/filter/strict.rb
|
97
|
-
- lib/ruby2js/filter/minitest-jasmine.rb
|
98
|
-
- lib/ruby2js/filter/angular-route.rb
|
99
|
-
- lib/ruby2js/filter/jquery.rb
|
97
|
+
- lib/ruby2js/converter/undef.rb
|
98
|
+
- lib/ruby2js/converter/literal.rb
|
99
|
+
- lib/ruby2js/converter/var.rb
|
100
|
+
- lib/ruby2js.rb
|
100
101
|
homepage: http://github.com/rubys/ruby2js
|
101
102
|
licenses:
|
102
103
|
- MIT
|