javascript 0.0.3 → 0.1.0

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
- SHA1:
3
- metadata.gz: 35a73b23b9db672ea87d3187f92567b94051abca
4
- data.tar.gz: d7fe17e2784bba1dfeb2853732de58a880f663cf
2
+ SHA256:
3
+ metadata.gz: d801576e68027f6910c308edda3c4c6e20c0ec72517baec732265b3af75a2b25
4
+ data.tar.gz: d5acd6b2da7f4c87c2507c8260bc78df208b5edaa55a278cae2c514698e4826e
5
5
  SHA512:
6
- metadata.gz: 4cd10453b98dde3861a11947ced9713145acd06891c330ec4a8ccade93257328a82ccf43cc091a7f0523fedd65a7880f07d82574ab9016bfbd87b98084a86eaa
7
- data.tar.gz: 3c59e0457659f62b27feb126241108a8971ef16076116d2fc40f1a55cf6e60709ef0c6dfb7dc3e44414bb031ea464272a344d6129317cb28135cad65deeaae1c
6
+ metadata.gz: 696cb526b35708eda0e6ebcace8fab9cfe1a941df17c6022c6afaa0a8b42fc68821efa783e6c2a2c39f2cfe62036bc1570fd37d21bf3dd8b0a7200244afbd655
7
+ data.tar.gz: c1a9d78e2c72cb425137eecf698511ca2a01b0fb7331cf71c97490cee62297824354f90aeb05e0415332d0ebecd0d35f8e992cce5a9d4000c317ce23d98da3e8
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.3
3
+ - 2.5
4
4
  - ruby-head
5
5
 
6
6
  notifications:
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in javascript.gemspec
4
4
  gemspec
5
+
6
+ gem "rake", "~> 10.0"
7
+ gem "minitest", "~> 5.11"
8
+ gem "activesupport", "~> 5.2"
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # JavaScript
2
2
 
3
+ [![Build Status](https://travis-ci.org/chancancode/javascript.svg?branch=master)](https://travis-ci.org/chancancode/javascript)
4
+
3
5
  As much as we love writing Ruby, when you need to *get really close to the
4
6
  metal*, you have no choice but to use JavaScript. With this gem, Rubyists can
5
7
  finally harness the raw power of their machines by programming in JavaScript
@@ -32,7 +34,7 @@ javascript {
32
34
 
33
35
  console.log("ZOMG JavaScript");
34
36
 
35
- var a = 1;
37
+ let a = 1;
36
38
 
37
39
  console.log(a);
38
40
 
@@ -40,7 +42,7 @@ javascript {
40
42
 
41
43
  console.log(a);
42
44
 
43
- var b = function(x) {
45
+ let b = function(x) {
44
46
  console.log(x + 1);
45
47
  };
46
48
 
@@ -53,8 +55,8 @@ javascript {
53
55
  c(4);
54
56
 
55
57
  function inspectArguments() {
56
- var args = Array.prototype.join.call(arguments, ", ");
57
- console.log("Arguments: " + args);
58
+ let args = Array.prototype.join.call(arguments, ", ");
59
+ console.log(`Arguments: ${args}`);
58
60
  }
59
61
 
60
62
  inspectArguments("a", "b", "c");
@@ -147,7 +149,6 @@ metal {
147
149
 
148
150
  * Gives you the illusion of programming in a *closer to the metal* syntax.
149
151
  * The examples in this README [actually work](/test/javascript_test.rb).
150
- * [![Build Status](https://travis-ci.org/vanruby/javascript.svg)](https://travis-ci.org/vanruby/javascript)
151
152
 
152
153
  ## Cons
153
154
 
@@ -156,7 +157,7 @@ metal {
156
157
 
157
158
  ## Contributing
158
159
 
159
- 1. Fork it ( https://github.com/vanruby/javascript/fork )
160
+ 1. Fork it ( https://github.com/chancancode/javascript/fork )
160
161
  2. Create your feature branch (`git checkout -b my-new-feature`)
161
162
  3. Commit your changes (`git commit -am 'Add some feature'`)
162
163
  4. Push to the branch (`git push origin my-new-feature`)
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "With this gem, Rubyists can finally get really close " \
13
13
  "to the metal by programming in JavaScript syntax right " \
14
14
  "within their Ruby applications."
15
- spec.homepage = "https://github.com/vanruby/javascript"
15
+ spec.homepage = "https://github.com/chancancode/javascript"
16
16
  spec.license = "MIT"
17
17
 
18
18
  spec.files = `git ls-files -z`.split("\x0")
@@ -24,8 +24,5 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency "binding_of_caller", "~> 0.7.0"
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.7"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "minitest", "~> 5.0"
30
- spec.add_development_dependency "activesupport", "~> 4.1.0"
27
+ spec.add_development_dependency "bundler", "~> 1.16"
31
28
  end
@@ -133,9 +133,16 @@ module JavaScript
133
133
  nil
134
134
  end
135
135
 
136
+ def let(*identifiers)
137
+ end
138
+
136
139
  def var(*identifiers)
137
140
  end
138
141
 
142
+ def `(string)
143
+ __caller__.eval(string.inspect.gsub(/\$(?={)/, '#'))
144
+ end
145
+
139
146
  def new(identifier)
140
147
  ::Object.const_get(identifier.name).new(*identifier.args)
141
148
  end
@@ -1,3 +1,3 @@
1
1
  module JavaScript
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -23,15 +23,34 @@ class JavaScriptTest < TestCase
23
23
  test "this" do
24
24
  require "javascript"
25
25
 
26
- javascript do
26
+ javascript {
27
27
  console.log(this === window);
28
28
  console.log(this === global);
29
- end
29
+ }
30
30
 
31
31
  assert_messages true, true
32
32
  end
33
33
 
34
- test "Local variables" do
34
+ test "Local variables (let)" do
35
+ require "javascript"
36
+
37
+ javascript {
38
+ let a = 1, b = 2;
39
+
40
+ console.log(a);
41
+ console.log(b);
42
+
43
+ a = a + 1;
44
+ b = a + b;
45
+
46
+ console.log(a);
47
+ console.log(b);
48
+ }
49
+
50
+ assert_messages 1, 2, 2, 4
51
+ end
52
+
53
+ test "Local variables (var)" do
35
54
  require "javascript"
36
55
 
37
56
  javascript {
@@ -77,16 +96,30 @@ class JavaScriptTest < TestCase
77
96
  assert_nil javascript { window.a; }
78
97
  end
79
98
 
99
+ test "String interpolation" do
100
+ require "javascript"
101
+
102
+ javascript {
103
+ console.log(`hello world...`);
104
+
105
+ let name = "Godfrey";
106
+
107
+ console.log(`hello ${name}!`);
108
+ }
109
+
110
+ assert_messages "hello world...", "hello Godfrey!"
111
+ end
112
+
80
113
  test "Functions" do
81
114
  require "javascript"
82
115
 
83
116
  javascript {
84
117
  var a = function(msg) {
85
- console.log("a: " + msg);
118
+ console.log(`a: ${msg}`);
86
119
  };
87
120
 
88
121
  function b(msg) {
89
- console.log("b: " + msg);
122
+ console.log(`b: ${msg}`);
90
123
  }
91
124
 
92
125
  var c = "c";
@@ -120,6 +153,94 @@ class JavaScriptTest < TestCase
120
153
  assert_messages "Hello world!", 4
121
154
  end
122
155
 
156
+ test "closure (let variables)" do
157
+ require "javascript"
158
+
159
+ javascript {
160
+ let a = 1;
161
+
162
+ function outer(b) {
163
+ let c = 3;
164
+
165
+ function inner(d) {
166
+ let e = 5;
167
+
168
+ console.log(a);
169
+ console.log(b);
170
+ console.log(c);
171
+ console.log(d);
172
+ console.log(e);
173
+ };
174
+
175
+ inner(4);
176
+ }
177
+
178
+ outer(2);
179
+ }
180
+
181
+ assert_messages 1, 2, 3, 4, 5
182
+ end
183
+
184
+ test "closure (var variables)" do
185
+ require "javascript"
186
+
187
+ javascript {
188
+ var a = 1;
189
+
190
+ function outer(b) {
191
+ var c = 3;
192
+
193
+ function inner(d) {
194
+ var e = 5;
195
+
196
+ console.log(a);
197
+ console.log(b);
198
+ console.log(c);
199
+ console.log(d);
200
+ console.log(e);
201
+ };
202
+
203
+ inner(4);
204
+ }
205
+
206
+ outer(2);
207
+ }
208
+
209
+ assert_messages 1, 2, 3, 4, 5
210
+ end
211
+
212
+ test "closure (functions)" do
213
+ require "javascript"
214
+
215
+ javascript {
216
+ function a() {
217
+ return 1;
218
+ };
219
+
220
+ function outer() {
221
+ function b() {
222
+ return 2;
223
+ }
224
+
225
+ function inner() {
226
+ function c() {
227
+ return 3;
228
+ }
229
+
230
+ console.log(a());
231
+ console.log(b());
232
+ console.log(c());
233
+ };
234
+
235
+ inner();
236
+ }
237
+
238
+ outer();
239
+ }
240
+
241
+ assert_messages 1, 2, 3
242
+ end
243
+
123
244
  test "arguments" do
124
245
  require "javascript"
125
246
 
@@ -231,7 +352,7 @@ class JavaScriptTest < TestCase
231
352
  require "javascript"
232
353
 
233
354
  javascript {
234
- var join = Array.prototype.join;
355
+ let join = Array.prototype.join;
235
356
 
236
357
  console.log(join.call(["a", "b", "c"], "+"));
237
358
  console.log(join.call([1, 2, 3, 4, 5], "-"));
@@ -6,10 +6,8 @@ require "active_support/testing/declarative"
6
6
  require "active_support/testing/setup_and_teardown"
7
7
  require "active_support/testing/isolation"
8
8
 
9
- I18n.enforce_available_locales = true
10
-
11
9
  class TestCase < Minitest::Test
12
10
  extend ActiveSupport::Testing::Declarative
13
- include ActiveSupport::Testing::SetupAndTeardown
11
+ prepend ActiveSupport::Testing::SetupAndTeardown
14
12
  include ActiveSupport::Testing::Isolation
15
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: javascript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Godfrey Chan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-12 00:00:00.000000000 Z
11
+ date: 2018-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -30,56 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.7'
33
+ version: '1.16'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.7'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '10.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '10.0'
55
- - !ruby/object:Gem::Dependency
56
- name: minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '5.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '5.0'
69
- - !ruby/object:Gem::Dependency
70
- name: activesupport
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 4.1.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 4.1.0
40
+ version: '1.16'
83
41
  description: With this gem, Rubyists can finally get really close to the metal by
84
42
  programming in JavaScript syntax right within their Ruby applications.
85
43
  email:
@@ -101,7 +59,7 @@ files:
101
59
  - test/javascript_test.rb
102
60
  - test/no_conflict_test.rb
103
61
  - test/test_helper.rb
104
- homepage: https://github.com/vanruby/javascript
62
+ homepage: https://github.com/chancancode/javascript
105
63
  licenses:
106
64
  - MIT
107
65
  metadata: {}
@@ -121,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
79
  version: '0'
122
80
  requirements: []
123
81
  rubyforge_project:
124
- rubygems_version: 2.4.6
82
+ rubygems_version: 2.7.7
125
83
  signing_key:
126
84
  specification_version: 4
127
85
  summary: Harness the raw power of your machine with JavaScript
@@ -129,4 +87,3 @@ test_files:
129
87
  - test/javascript_test.rb
130
88
  - test/no_conflict_test.rb
131
89
  - test/test_helper.rb
132
- has_rdoc: