ruby2js 3.4.0 → 3.6.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/README.md +128 -20
- data/lib/ruby2js.rb +30 -2
- data/lib/ruby2js/converter.rb +7 -5
- data/lib/ruby2js/converter/block.rb +5 -0
- data/lib/ruby2js/converter/class2.rb +63 -20
- data/lib/ruby2js/converter/def.rb +1 -1
- data/lib/ruby2js/converter/import.rb +17 -1
- data/lib/ruby2js/converter/ivar.rb +10 -2
- data/lib/ruby2js/converter/literal.rb +14 -2
- data/lib/ruby2js/converter/send.rb +4 -3
- data/lib/ruby2js/converter/xstr.rb +1 -1
- data/lib/ruby2js/filter/active_functions.rb +43 -0
- data/lib/ruby2js/filter/camelCase.rb +4 -3
- data/lib/ruby2js/filter/esm.rb +96 -4
- data/lib/ruby2js/filter/functions.rb +14 -0
- data/lib/ruby2js/filter/node.rb +95 -74
- data/lib/ruby2js/filter/nokogiri.rb +3 -29
- data/lib/ruby2js/filter/return.rb +2 -0
- data/lib/ruby2js/filter/securerandom.rb +33 -0
- data/lib/ruby2js/filter/vue.rb +9 -0
- data/lib/ruby2js/rails.rb +15 -9
- data/lib/ruby2js/serializer.rb +4 -2
- data/lib/ruby2js/version.rb +1 -1
- data/ruby2js.gemspec +1 -1
- metadata +9 -7
- data/lib/ruby2js/filter/esm_migration.rb +0 -72
data/lib/ruby2js/rails.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Example usage:
|
2
2
|
#
|
3
|
-
# $ echo gem 'ruby2js', require: 'ruby2js/rails'
|
3
|
+
# $ echo "gem 'ruby2js', require: 'ruby2js/rails'" >> Gemfile
|
4
4
|
# $ bundle update
|
5
5
|
# $ rails generate controller Say hello
|
6
6
|
# $ echo 'alert "Hello world!"' > app/views/say/hello.js.rb
|
@@ -13,8 +13,8 @@
|
|
13
13
|
#
|
14
14
|
# Asset Pipeline:
|
15
15
|
#
|
16
|
-
# Ruby2JS registers ".
|
17
|
-
# You can add "ruby_thing.js.
|
16
|
+
# Ruby2JS registers ".rb.js" extension.
|
17
|
+
# You can add "ruby_thing.js.rb" to your app/javascript folder
|
18
18
|
# and '= require ruby_thing' from other js sources.
|
19
19
|
#
|
20
20
|
# (options are not yet supported, but by requiring the appropriate files
|
@@ -26,15 +26,17 @@ module Ruby2JS
|
|
26
26
|
class Template
|
27
27
|
cattr_accessor :default_format
|
28
28
|
self.default_format = Mime[:js]
|
29
|
-
def self.call(template)
|
30
|
-
"Ruby2JS.convert(#{template.source.inspect}).to_s"
|
29
|
+
def self.call(template, source)
|
30
|
+
"Ruby2JS.convert(#{template.source.inspect}, file: source).to_s"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
ActiveSupport.on_load(:action_view) do
|
35
|
+
ActionView::Template.register_template_handler :rb, Template
|
36
|
+
end
|
35
37
|
|
36
38
|
class SprocketProcessor
|
37
|
-
def initialize(
|
39
|
+
def initialize(file = nil)
|
38
40
|
@file = file
|
39
41
|
end
|
40
42
|
def render(context , _)
|
@@ -46,10 +48,14 @@ module Ruby2JS
|
|
46
48
|
class Engine < ::Rails::Engine
|
47
49
|
engine_name "ruby2js"
|
48
50
|
|
51
|
+
config.app_generators.javascripts true
|
52
|
+
config.app_generators.javascript_engine :rb
|
53
|
+
|
49
54
|
config.assets.configure do |env|
|
50
|
-
env.
|
55
|
+
env.register_mime_type 'text/ruby', extensions: ['.js.rb', '.rb']
|
56
|
+
env.register_transformer 'text/ruby', 'text/javascript', SprocketProcessor
|
57
|
+
env.register_preprocessor 'text/javascript', SprocketProcessor
|
51
58
|
end
|
52
|
-
|
53
59
|
end
|
54
60
|
|
55
61
|
end
|
data/lib/ruby2js/serializer.rb
CHANGED
@@ -42,6 +42,7 @@ module Ruby2JS
|
|
42
42
|
|
43
43
|
class Serializer
|
44
44
|
attr_reader :timestamps
|
45
|
+
attr_accessor :file_name
|
45
46
|
|
46
47
|
def initialize
|
47
48
|
@sep = '; '
|
@@ -56,6 +57,7 @@ module Ruby2JS
|
|
56
57
|
@timestamps = {}
|
57
58
|
|
58
59
|
@ast = nil
|
60
|
+
@file_name = ''
|
59
61
|
end
|
60
62
|
|
61
63
|
def timestamp(file)
|
@@ -355,7 +357,7 @@ module Ruby2JS
|
|
355
357
|
end
|
356
358
|
|
357
359
|
split = buffer.source[0...pos].split("\n")
|
358
|
-
vlq row, col, source_index, split.length-1, split.last.to_s.length
|
360
|
+
vlq row, col, source_index, [split.length - 1, 0].max, split.last.to_s.length
|
359
361
|
end
|
360
362
|
col += token.length
|
361
363
|
end
|
@@ -363,7 +365,7 @@ module Ruby2JS
|
|
363
365
|
|
364
366
|
@sourcemap = {
|
365
367
|
version: 3,
|
366
|
-
file: @
|
368
|
+
file: @file_name,
|
367
369
|
sources: sources.map(&:name),
|
368
370
|
mappings: @mappings
|
369
371
|
}
|
data/lib/ruby2js/version.rb
CHANGED
data/ruby2js.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
11
11
|
s.require_paths = ["lib".freeze]
|
12
|
-
s.authors = ["Sam Ruby".freeze]
|
12
|
+
s.authors = ["Sam Ruby".freeze, "Jared White".freeze]
|
13
13
|
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".freeze
|
14
14
|
s.email = "rubys@intertwingly.net".freeze
|
15
15
|
s.files = %w(ruby2js.gemspec README.md) + Dir.glob("{lib}/**/*")
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
8
|
-
|
8
|
+
- Jared White
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2020-
|
12
|
+
date: 2020-12-26 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: parser
|
@@ -121,10 +122,10 @@ files:
|
|
121
122
|
- lib/ruby2js/es2021/strict.rb
|
122
123
|
- lib/ruby2js/execjs.rb
|
123
124
|
- lib/ruby2js/filter.rb
|
125
|
+
- lib/ruby2js/filter/active_functions.rb
|
124
126
|
- lib/ruby2js/filter/camelCase.rb
|
125
127
|
- lib/ruby2js/filter/cjs.rb
|
126
128
|
- lib/ruby2js/filter/esm.rb
|
127
|
-
- lib/ruby2js/filter/esm_migration.rb
|
128
129
|
- lib/ruby2js/filter/functions.rb
|
129
130
|
- lib/ruby2js/filter/jquery.rb
|
130
131
|
- lib/ruby2js/filter/matchAll.rb
|
@@ -134,6 +135,7 @@ files:
|
|
134
135
|
- lib/ruby2js/filter/react.rb
|
135
136
|
- lib/ruby2js/filter/require.rb
|
136
137
|
- lib/ruby2js/filter/return.rb
|
138
|
+
- lib/ruby2js/filter/securerandom.rb
|
137
139
|
- lib/ruby2js/filter/tagged_templates.rb
|
138
140
|
- lib/ruby2js/filter/underscore.rb
|
139
141
|
- lib/ruby2js/filter/vue.rb
|
@@ -149,7 +151,7 @@ homepage: http://github.com/rubys/ruby2js
|
|
149
151
|
licenses:
|
150
152
|
- MIT
|
151
153
|
metadata: {}
|
152
|
-
post_install_message:
|
154
|
+
post_install_message:
|
153
155
|
rdoc_options: []
|
154
156
|
require_paths:
|
155
157
|
- lib
|
@@ -164,8 +166,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
166
|
- !ruby/object:Gem::Version
|
165
167
|
version: '0'
|
166
168
|
requirements: []
|
167
|
-
rubygems_version: 3.
|
168
|
-
signing_key:
|
169
|
+
rubygems_version: 3.1.4
|
170
|
+
signing_key:
|
169
171
|
specification_version: 4
|
170
172
|
summary: Minimal yet extensible Ruby to JavaScript conversion.
|
171
173
|
test_files: []
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'ruby2js'
|
2
|
-
|
3
|
-
module Ruby2JS
|
4
|
-
module Filter
|
5
|
-
module ESMMigration
|
6
|
-
include SEXP
|
7
|
-
|
8
|
-
def initialize(*args)
|
9
|
-
@esm_include = nil
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
|
-
def process(node)
|
14
|
-
return super if @esm_include
|
15
|
-
@esm_include = Set.new
|
16
|
-
@esm_exclude = Set.new
|
17
|
-
@esm_export = nil
|
18
|
-
result = super
|
19
|
-
|
20
|
-
esm_walk(result)
|
21
|
-
|
22
|
-
inventory = (@esm_include - @esm_exclude).to_a.sort
|
23
|
-
|
24
|
-
if inventory.empty? and not @esm_export
|
25
|
-
result
|
26
|
-
else
|
27
|
-
list = inventory.map do |name|
|
28
|
-
if name == "React" and defined? Ruby2JS::Filter::React
|
29
|
-
s(:import, "#{name.downcase}", s(:const, nil, name))
|
30
|
-
elsif not %w(JSON Object).include? name
|
31
|
-
s(:import, "./#{name.downcase}.js", s(:const, nil, name))
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
list.push result
|
36
|
-
|
37
|
-
if @esm_export
|
38
|
-
list.push s(:export, :default, s(:const, nil, @esm_export))
|
39
|
-
end
|
40
|
-
|
41
|
-
s(:begin, *list.compact)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# gather constants
|
46
|
-
def esm_walk(node)
|
47
|
-
# extract ivars and cvars
|
48
|
-
if node.type == :const and node.children.first == nil
|
49
|
-
@esm_include << node.children.last.to_s
|
50
|
-
elsif node.type == :xnode
|
51
|
-
name = node.children.first
|
52
|
-
@esm_include << name unless name.empty? or name =~ /^[a-z]/
|
53
|
-
elsif node.type == :casgn and node.children.first == nil
|
54
|
-
@esm_exclude << node.children[1].to_s
|
55
|
-
elsif node.type == :class and node.children.first.type == :const
|
56
|
-
if node.children.first.children.first == nil
|
57
|
-
name = node.children.first.children.last.to_s
|
58
|
-
@esm_exclude << name
|
59
|
-
@esm_export ||= name
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# recurse
|
64
|
-
node.children.each do |child|
|
65
|
-
esm_walk(child) if Parser::AST::Node === child
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
DEFAULTS.push ESMMigration
|
71
|
-
end
|
72
|
-
end
|