ruby2js 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19d8eddc8012fef1657da5408d86e0be5b6d3aac
4
- data.tar.gz: 2a7a41d3e3a64965c32ea625273cf754bea743a8
3
+ metadata.gz: 14b0c4f156b0f543afde3c3a0a8e339b5ece18bc
4
+ data.tar.gz: 363dafc8a9f6814ea754af8025f60c1668ec2e70
5
5
  SHA512:
6
- metadata.gz: 9ad39b7ca03a48876499314942e22da4fd636512c2b793e23c1cd4b13d96749e3a9612c887c972a02493beec9898e6f6cab9635fff5f52adb420db22f1749dec
7
- data.tar.gz: 5695f7a816be85ffd21756553ccb9917d18b723e8c39c9c3647fcd7fa6e3242135a6f64b8e8c41a3faea98201d8c50438ea94ca7bcfaaf1d8194757bd316b694
6
+ metadata.gz: 1d58ad86fa85e3ecbe88be541faa486013407a993cf3b0a14e0b05771863219f0f69eeb67e8b5597eeeedb8d54d515d48058aa2b4792099aba4421286833972d
7
+ data.tar.gz: b03e0fa66154948bd4abdff01b766b916b6758efffe70de8b6e3515d76f171e353e5c3ba06a5f3694f761970cc58d07d7fc8dab9b237e9c82298604238d96758
@@ -10,11 +10,17 @@ module Ruby2JS
10
10
  :once, :set, :watch
11
11
  ]
12
12
 
13
+ VUE_LIFECYCLE = [
14
+ :data, :render, :beforeCreate, :created, :beforeMount, :mounted,
15
+ :beforeUpdate, :updated, :beforeDestroy, :destroyed
16
+ ]
17
+
13
18
  def initialize(*args)
14
19
  @vue_h = nil
15
20
  @vue_self = nil
16
21
  @vue_apply = nil
17
22
  @vue_inventory = Hash.new {|h, k| h[k] = []}
23
+ @vue_instance = []
18
24
  super
19
25
  end
20
26
 
@@ -45,6 +51,8 @@ module Ruby2JS
45
51
 
46
52
  hash = []
47
53
  methods = []
54
+ computed = []
55
+ setters = []
48
56
 
49
57
  # insert constructor if none present
50
58
  unless body.any? {|statement|
@@ -55,6 +63,18 @@ module Ruby2JS
55
63
  end
56
64
 
57
65
  @vue_inventory = vue_walk(node)
66
+ @vue_instance = []
67
+
68
+ # collect instance methods (including getters and setters)
69
+ body.each do |statement|
70
+ if statement.type == :def
71
+ method = statement.children.first
72
+ unless VUE_LIFECYCLE.include? method or method == :initialize
73
+ method = method.to_s[0..-2].to_sym if method.to_s.end_with? '='
74
+ @vue_instance << method unless @vue_instance.include? method
75
+ end
76
+ end
77
+ end
58
78
 
59
79
  # convert body into hash
60
80
  body.each do |statement|
@@ -137,14 +157,21 @@ module Ruby2JS
137
157
  end
138
158
  end
139
159
 
160
+ if statement.is_method?
161
+ method_type = :proc
162
+ else
163
+ method_type = :lambda
164
+ end
165
+
140
166
  # add to hash in the appropriate location
141
- pair = s(:pair, s(:sym, method),
142
- s(:block, s(:send, nil, :lambda), args, process(block)))
143
- if %w(data render beforeCreate created beforeMount mounted
144
- beforeUpdate updated beforeDestroy destroyed
145
- ).include? method.to_s
146
- then
167
+ pair = s(:pair, s(:sym, method.to_s.chomp('=')),
168
+ s(:block, s(:send, nil, method_type), args, process(block)))
169
+ if VUE_LIFECYCLE.include? method
147
170
  hash << pair
171
+ elsif not statement.is_method?
172
+ computed << pair
173
+ elsif method.to_s.end_with? '='
174
+ setters << pair
148
175
  else
149
176
  methods << pair
150
177
  end
@@ -167,6 +194,30 @@ module Ruby2JS
167
194
  hash << s(:pair, s(:sym, :methods), s(:hash, *methods))
168
195
  end
169
196
 
197
+ @vue_instance = []
198
+
199
+ # add setters to computed list
200
+ setters.each do |setter|
201
+ index = computed.find_index do |pair|
202
+ pair.children[0].children[0].to_s ==
203
+ setter.children[0].children[0]
204
+ end
205
+
206
+ if index
207
+ computed[index] = s(:pair, setter.children[0],
208
+ s(:hash, s(:pair, s(:sym, :get), computed[index].children[1]),
209
+ s(:pair, s(:sym, :set), setter.children[1])))
210
+ else
211
+ computed << s(:pair, setter.children[0],
212
+ s(:hash, s(:pair, s(:sym, :set), setter.children[1])))
213
+ end
214
+ end
215
+
216
+ # add computed to hash
217
+ unless computed.empty?
218
+ hash << s(:pair, s(:sym, :computed), s(:hash, *computed))
219
+ end
220
+
170
221
  # convert class name to camel case
171
222
  camel = cname.children.last.to_s.gsub(/[^\w]/, '-').
172
223
  sub(/^[A-Z]/) {|c| c.downcase}.
@@ -210,6 +261,12 @@ module Ruby2JS
210
261
  end
211
262
  end
212
263
 
264
+ # calls to methods (including getters) defined in this class
265
+ if node.children[0]==nil and @vue_instance.include? node.children[1]
266
+ return node.updated nil, [s(:self), node.children[1],
267
+ *process_all(node.children[2..-1])]
268
+ end
269
+
213
270
  return super unless @vue_h
214
271
 
215
272
  if node.children[0] == nil and node.children[1] =~ /^_\w/
@@ -703,6 +760,12 @@ module Ruby2JS
703
760
  node.children[1], process(node.children[2])]
704
761
  end
705
762
 
763
+ def on_lvasgn(node)
764
+ return super unless @vue_instance.include? node.children.first
765
+ s(:send, s(:self), "#{node.children.first}=",
766
+ process(node.children[1]))
767
+ end
768
+
706
769
  # gather ivar and cvar usage
707
770
  def vue_walk(node, inventory = Hash.new {|h, k| h[k] = []})
708
771
  # extract ivars and cvars
@@ -2,7 +2,7 @@ module Ruby2JS
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/ruby2js.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ruby2js 2.1.1 ruby lib
2
+ # stub: ruby2js 2.1.2 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ruby2js".freeze
6
- s.version = "2.1.1"
6
+ s.version = "2.1.2"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Sam Ruby".freeze]
11
- s.date = "2017-09-06"
11
+ s.date = "2017-09-07"
12
12
  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
13
13
  s.email = "rubys@intertwingly.net".freeze
14
14
  s.files = ["README.md".freeze, "lib/ruby2js".freeze, "lib/ruby2js.rb".freeze, "lib/ruby2js/cgi.rb".freeze, "lib/ruby2js/converter".freeze, "lib/ruby2js/converter.rb".freeze, "lib/ruby2js/converter/arg.rb".freeze, "lib/ruby2js/converter/args.rb".freeze, "lib/ruby2js/converter/array.rb".freeze, "lib/ruby2js/converter/begin.rb".freeze, "lib/ruby2js/converter/block.rb".freeze, "lib/ruby2js/converter/blockpass.rb".freeze, "lib/ruby2js/converter/boolean.rb".freeze, "lib/ruby2js/converter/break.rb".freeze, "lib/ruby2js/converter/case.rb".freeze, "lib/ruby2js/converter/casgn.rb".freeze, "lib/ruby2js/converter/class.rb".freeze, "lib/ruby2js/converter/const.rb".freeze, "lib/ruby2js/converter/cvar.rb".freeze, "lib/ruby2js/converter/cvasgn.rb".freeze, "lib/ruby2js/converter/def.rb".freeze, "lib/ruby2js/converter/defined.rb".freeze, "lib/ruby2js/converter/defs.rb".freeze, "lib/ruby2js/converter/dstr.rb".freeze, "lib/ruby2js/converter/for.rb".freeze, "lib/ruby2js/converter/hash.rb".freeze, "lib/ruby2js/converter/if.rb".freeze, "lib/ruby2js/converter/in.rb".freeze, "lib/ruby2js/converter/ivar.rb".freeze, "lib/ruby2js/converter/ivasgn.rb".freeze, "lib/ruby2js/converter/kwbegin.rb".freeze, "lib/ruby2js/converter/literal.rb".freeze, "lib/ruby2js/converter/logical.rb".freeze, "lib/ruby2js/converter/masgn.rb".freeze, "lib/ruby2js/converter/module.rb".freeze, "lib/ruby2js/converter/next.rb".freeze, "lib/ruby2js/converter/nil.rb".freeze, "lib/ruby2js/converter/nthref.rb".freeze, "lib/ruby2js/converter/opasgn.rb".freeze, "lib/ruby2js/converter/prototype.rb".freeze, "lib/ruby2js/converter/regexp.rb".freeze, "lib/ruby2js/converter/return.rb".freeze, "lib/ruby2js/converter/self.rb".freeze, "lib/ruby2js/converter/send.rb".freeze, "lib/ruby2js/converter/super.rb".freeze, "lib/ruby2js/converter/sym.rb".freeze, "lib/ruby2js/converter/undef.rb".freeze, "lib/ruby2js/converter/until.rb".freeze, "lib/ruby2js/converter/untilpost.rb".freeze, "lib/ruby2js/converter/var.rb".freeze, "lib/ruby2js/converter/vasgn.rb".freeze, "lib/ruby2js/converter/while.rb".freeze, "lib/ruby2js/converter/whilepost.rb".freeze, "lib/ruby2js/converter/xstr.rb".freeze, "lib/ruby2js/execjs.rb".freeze, "lib/ruby2js/filter".freeze, "lib/ruby2js/filter/angular-resource.rb".freeze, "lib/ruby2js/filter/angular-route.rb".freeze, "lib/ruby2js/filter/angularrb.rb".freeze, "lib/ruby2js/filter/camelCase.rb".freeze, "lib/ruby2js/filter/functions.rb".freeze, "lib/ruby2js/filter/jquery.rb".freeze, "lib/ruby2js/filter/minitest-jasmine.rb".freeze, "lib/ruby2js/filter/react.rb".freeze, "lib/ruby2js/filter/require.rb".freeze, "lib/ruby2js/filter/return.rb".freeze, "lib/ruby2js/filter/rubyjs.rb".freeze, "lib/ruby2js/filter/strict.rb".freeze, "lib/ruby2js/filter/underscore.rb".freeze, "lib/ruby2js/filter/vue.rb".freeze, "lib/ruby2js/rails.rb".freeze, "lib/ruby2js/serializer.rb".freeze, "lib/ruby2js/sinatra.rb".freeze, "lib/ruby2js/version.rb".freeze, "ruby2js.gemspec".freeze]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby2js
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-06 00:00:00.000000000 Z
11
+ date: 2017-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser