ruby2js 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2MyOGI2ZTQxMWYwMjJlYjc4M2M1OGFjNGVhNmRhOGJkYTc3ZGFjNA==
4
+ NDlkZTE5MGYzYzBlZDc0YzBmZmU5YmE2NWZmNTU1MWQwYWE1ZjVmNw==
5
5
  data.tar.gz: !binary |-
6
- ZWNmN2FhYmI4OTUyODhjMDI0MGQ3ZjJmZjA1NTczM2EzN2M2NmQ4Ng==
6
+ ZWM4OGU4OTgzMGU0ZjAxMDc1MGFhOGNmMDU2YWZjOWU0ZmNjYWFjNg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YWZjYzYxN2NlMjNhZWNmMGE1ODRlZjY3ODg0ZjQ3YjkxYzFhZDNmNWRiODUy
10
- ZTI0MTExMTQwMjg5YTMzZDQyNjEzOTE5NjdlN2VkNDM3NjZhMjFiOTZhNjQy
11
- YmZmYmNlNmIxZmMxNmI4NTk4Yjg5MTFkNjAzZjc5N2I0ZTQ3ZDk=
9
+ YzNiMmJmNTg5MDBiZmQzMTc1OGQ5ZDNiNTEyYzZjN2FjNjlhNjAwYTA2NGVl
10
+ ZWYxZjZiNDc0NDFhZjI1YmZlMjU3ZGNkOWVlNjEwNTg0NGFlZDhhZmNlZTBj
11
+ YzI0OGYyZGRjMmI3NDRlODk0ZTNkYzBjNGQ4MDYxNWUwYzVhOGQ=
12
12
  data.tar.gz: !binary |-
13
- MzcwYTRlZjI0Mjc5ODM0ZmY5MzQwZDE1NDZlMDE0YzU0NmZjZmI0YTFkMjFl
14
- OTE3ZWM5MjFhMDE3NzRjZWYyMTFiMjI4YzQxNDgzNTJiOTU1NWZiODc4ZmY4
15
- YjViNmZiMmYzMWFhYTliNjk1NjAwMWIzY2JmOGYwNDFlOWE3Nzk=
13
+ NGNiMTlkMGEyYzVjNDg3ODc2OGQ3ZDE1ODcyZTk0YjRiN2Q3MGNlZjlhNWQ1
14
+ MmNlOGFiYjNlM2RiMjJmZDZjYzUxMzc5NGMzZjg4MmU3NDEwZjM3ZDg0NGNi
15
+ NGRmOWQ3OWQwNzI3ZjNhZTNkNDA4MzEzY2YwODY2NWE1NTRmNTM=
@@ -12,10 +12,10 @@ module Ruby2JS
12
12
  whens.map! do |node|
13
13
  *values, code = node.children
14
14
  cases = values.map {|value| "case #{ parse value }:#@ws"}.join
15
- "#{ cases }#{ parse code }#{@sep}break#@sep"
15
+ "#{ cases }#{ parse code, :statement }#{@sep}break#@sep"
16
16
  end
17
17
 
18
- other = "#{@nl}default:#@ws#{ parse other }#@nl" if other
18
+ other = "#{@nl}default:#@ws#{ parse other, :statement }#@nl" if other
19
19
 
20
20
  "switch (#{ parse expr }) {#@nl#{whens.join(@nl)}#{other}}"
21
21
  end
@@ -7,10 +7,13 @@ module Ruby2JS
7
7
  # (...))
8
8
 
9
9
  handle :if do |condition, then_block, else_block|
10
+ # return parse condition if not else_block and not then_block
10
11
  if else_block and not then_block
11
12
  return parse(s(:if, s(:send, condition, :!), else_block, nil), @state)
12
13
  end
13
14
 
15
+ then_block ||= s(:nil)
16
+
14
17
  if @state == :statement
15
18
  output = "if (#{ parse condition }) {#@nl#{ scope then_block }#@nl}"
16
19
  while else_block and else_block.type == :if
@@ -16,6 +16,10 @@ require 'ruby2js'
16
16
  # to match jQuery's convention for getters and setters:
17
17
  # http://learn.jquery.com/using-jquery-core/working-with-selections/
18
18
  #
19
+ # Selected DOM properties (namely checked, disabled, readOnly, and required)
20
+ # can also use getter and setter syntax. Additionally, readOnly may be
21
+ # spelled 'readonly'.
22
+ #
19
23
  # Of course, using jQuery's style of getter and setter calls is supported,
20
24
  # and indeed is convenient when using method chaining.
21
25
  #
@@ -26,12 +30,15 @@ require 'ruby2js'
26
30
  #
27
31
  # Some examples of before/after conversions:
28
32
  #
29
- # `this.val
33
+ # ~this.val
30
34
  # $(this).val()
31
35
  #
32
- # `"button.continue".html = "Next Step..."
36
+ # ~"button.continue".html = "Next Step..."
33
37
  # $("button.continue").html("Next Step...")
34
38
  #
39
+ # ~"button".readonly = false
40
+ # $("button").prop("readOnly", false)
41
+ #
35
42
  # $$.ajax(
36
43
  # url: "/api/getWeather",
37
44
  # data: {zipcode: 97201},
@@ -79,8 +86,23 @@ module Ruby2JS
79
86
  elsif node.children[1] == :~
80
87
  # map ~expression.method to $(expression).method
81
88
 
89
+ if node.children[0] and node.children[0].type == :op_asgn
90
+ asgn = node.children[0]
91
+ if asgn.children[0] and asgn.children[0].type == :send
92
+ inner = asgn.children[0]
93
+ return on_send s(:send, s(:send, inner.children[0],
94
+ (inner.children[1].to_s+'=').to_sym,
95
+ s(:send, s(:send, s(:send, inner.children[0], :~),
96
+ *inner.children[1..-1]), *asgn.children[1..-1])), :~)
97
+ else
98
+ return on_send asgn.updated nil, [s(:send, asgn.children[0], :~),
99
+ *asgn.children[1..-1]]
100
+ end
101
+ end
102
+
82
103
  # See http://api.jquery.com/category/properties/
83
104
  props = :context, :jquery, :browser, :fx, :support, :length, :selector
105
+ domprops = %w(checked disabled readonly readOnly required)
84
106
 
85
107
  rewrite_tilda = proc do |node|
86
108
  # Example conversion:
@@ -105,6 +127,9 @@ module Ruby2JS
105
127
  method, *process_all(node.children[2..-1])]
106
128
  if props.include? node.children[1]
107
129
  node.updated nil, rewrite
130
+ elsif domprops.include? method.to_s
131
+ method = :readOnly if method.to_s == 'readonly'
132
+ s(:send, rewrite[0], :prop, s(:sym, method), *rewrite[2..-1])
108
133
  else
109
134
  s(:send, *rewrite)
110
135
  end
@@ -2,7 +2,7 @@ module Ruby2JS
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/ruby2js.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "ruby2js"
5
- s.version = "1.1.0"
5
+ s.version = "1.1.1"
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 = "2013-11-18"
9
+ s.date = "2013-11-22"
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
12
  s.files = ["ruby2js.gemspec", "README.md", "lib/ruby2js", "lib/ruby2js/version.rb", "lib/ruby2js/converter", "lib/ruby2js/converter/orasgn.rb", "lib/ruby2js/converter/kwbegin.rb", "lib/ruby2js/converter/const.rb", "lib/ruby2js/converter/return.rb", "lib/ruby2js/converter/opasgn.rb", "lib/ruby2js/converter/xstr.rb", "lib/ruby2js/converter/args.rb", "lib/ruby2js/converter/literal.rb", "lib/ruby2js/converter/array.rb", "lib/ruby2js/converter/if.rb", "lib/ruby2js/converter/nil.rb", "lib/ruby2js/converter/logical.rb", "lib/ruby2js/converter/next.rb", "lib/ruby2js/converter/while.rb", "lib/ruby2js/converter/whilepost.rb", "lib/ruby2js/converter/arg.rb", "lib/ruby2js/converter/case.rb", "lib/ruby2js/converter/break.rb", "lib/ruby2js/converter/hash.rb", "lib/ruby2js/converter/for.rb", "lib/ruby2js/converter/boolean.rb", "lib/ruby2js/converter/var.rb", "lib/ruby2js/converter/undef.rb", "lib/ruby2js/converter/blockpass.rb", "lib/ruby2js/converter/until.rb", "lib/ruby2js/converter/regexp.rb", "lib/ruby2js/converter/untilpost.rb", "lib/ruby2js/converter/masgn.rb", "lib/ruby2js/converter/block.rb", "lib/ruby2js/converter/ivar.rb", "lib/ruby2js/converter/send.rb", "lib/ruby2js/converter/vasgn.rb", "lib/ruby2js/converter/defined.rb", "lib/ruby2js/converter/def.rb", "lib/ruby2js/converter/sym.rb", "lib/ruby2js/converter/ivasgn.rb", "lib/ruby2js/converter/casgn.rb", "lib/ruby2js/converter/self.rb", "lib/ruby2js/converter/andasgn.rb", "lib/ruby2js/converter/begin.rb", "lib/ruby2js/converter/dstr.rb", "lib/ruby2js/converter/class.rb", "lib/ruby2js/converter.rb", "lib/ruby2js/filter", "lib/ruby2js/filter/return.rb", "lib/ruby2js/filter/angularrb.rb", "lib/ruby2js/filter/functions.rb", "lib/ruby2js/filter/jquery.rb", "lib/ruby2js.rb"]
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: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-18 00:00:00.000000000 Z
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser