ruby2js 2.1.21 → 2.1.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -8
- data/lib/ruby2js/converter/block.rb +22 -16
- data/lib/ruby2js/haml.rb +27 -0
- data/lib/ruby2js/rails.rb +3 -2
- data/lib/ruby2js/version.rb +1 -1
- data/ruby2js.gemspec +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfd51a5b122b0cc53549b8fb3c44ae847f1183b6
|
4
|
+
data.tar.gz: befcb08dff3c11d5570fab15f3a2a462f01b442c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3894c89a49fd835b781c2187e0495950742895297d8f5d3e6987064a18ab3c795ea1fb9d4780d6ab042397f8f7bb97a9ed1170cf3ae90dd7f63ef42917bd57e2
|
7
|
+
data.tar.gz: fd8740c03765bf694e9099d35a42f896feea4714644c68a201c1532d5f55aee52674f7a79697938cd7d60ab20ce787ad8857ab93bfca89f00a3addfad9ea06d7
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@ Ruby2js
|
|
3
3
|
|
4
4
|
Minimal yet extensible Ruby to JavaScript conversion.
|
5
5
|
|
6
|
-
[![Build Status](https://travis-ci.org/rubys/ruby2js.svg)](https://travis-ci.org/rubys/ruby2js)
|
6
|
+
[![Build Status](https://travis-ci.org/rubys/ruby2js.svg)](https://travis-ci.org/rubys/ruby2js)
|
7
7
|
[![Gem Version](https://badge.fury.io/rb/ruby2js.svg)](https://badge.fury.io/rb/ruby2js)
|
8
8
|
|
9
9
|
Description
|
@@ -20,7 +20,7 @@ Ruby attribute accessors, methods defined with no parameters and no
|
|
20
20
|
parenthesis, as well as setter method definitions, are
|
21
21
|
mapped to
|
22
22
|
[Object.defineProperty](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FObject%2FdefineProperty),
|
23
|
-
so avoid these if you wish to target users running IE8 or lower.
|
23
|
+
so avoid these if you wish to target users running IE8 or lower.
|
24
24
|
|
25
25
|
Filters may be provided to add Ruby-specific or framework specific
|
26
26
|
behavior. Filters are essentially macro facilities that operate on
|
@@ -83,7 +83,7 @@ objects to handle this. This is the approach that [Opal](http://opalrb.org/)
|
|
83
83
|
takes. It is a fine approach, with a number of benefits. It also has some
|
84
84
|
notable drawbacks. For example,
|
85
85
|
[readability](http://opalrb.org/try/#code:a%20%3D%20%22abc%22%3B%20puts%20a[-1])
|
86
|
-
and
|
86
|
+
and
|
87
87
|
[compatibility with other frameworks](https://github.com/opal/opal/issues/400).
|
88
88
|
|
89
89
|
Another approach is to simply accept JavaScript semantics for what they are.
|
@@ -127,6 +127,7 @@ includes three such integrations:
|
|
127
127
|
* [CGI](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/cgi.rb)
|
128
128
|
* [Sinatra](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/sinatra.rb)
|
129
129
|
* [Rails](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/rails.rb)
|
130
|
+
* [Haml](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/haml.rb)
|
130
131
|
|
131
132
|
As you might expect, CGI is a bit sluggish. By contrast, Sinatra and Rails
|
132
133
|
are quite speedy as the bulk of the time is spent on the initial load of the
|
@@ -201,7 +202,7 @@ the script.
|
|
201
202
|
* `[/r/, n]` becomes `.match(/r/)[n]`
|
202
203
|
* `"string" * length` becomes `new Array(length + 1).join("string")`
|
203
204
|
* `.sub!` and `.gsub!` become equivalent `x = x.replace` statements
|
204
|
-
* `.map!`, `.reverse!`, and `.select` become equivalent
|
205
|
+
* `.map!`, `.reverse!`, and `.select` become equivalent
|
205
206
|
`.splice(0, .length, *.method())` statements
|
206
207
|
* `@foo.call(args)` becomes `this._foo(args)`
|
207
208
|
* `@@foo.call(args)` becomes `this.constructor._foo(args)`
|
@@ -309,7 +310,7 @@ the script.
|
|
309
310
|
* `.zip()` becomes `_.zip()`
|
310
311
|
* `(n...m)` becomes `_.range(n, m)`
|
311
312
|
* `(n..m)` becomes `_.range(n, m+1)`
|
312
|
-
* `.compact!`, `.flatten!`, `shuffle!`, `reject!`, `sort_by!`, and
|
313
|
+
* `.compact!`, `.flatten!`, `shuffle!`, `reject!`, `sort_by!`, and
|
313
314
|
`.uniq` become equivalent `.splice(0, .length, *.method())` statements
|
314
315
|
* for the following methods, if the block consists entirely of a simple
|
315
316
|
expression (or ends with one), a `return` is added prior to the
|
@@ -344,7 +345,7 @@ the script.
|
|
344
345
|
* maps constant assignments in an angular module to a filter
|
345
346
|
* maps class definitions in an angular module to a filter
|
346
347
|
* within a controller or within a `link` method in a directive:
|
347
|
-
* maps `apply`, `broadcast`, `digest`, `emit`, `eval`, `evalAsync`, and
|
348
|
+
* maps `apply`, `broadcast`, `digest`, `emit`, `eval`, `evalAsync`, and
|
348
349
|
`parent` calls to `$scope` functions.
|
349
350
|
* maps `apply!`, `broadcast!`, `digest!`, `eval!`, and `evalAsync!`
|
350
351
|
calls to `$rootScope` functions.
|
@@ -393,7 +394,7 @@ the script.
|
|
393
394
|
use of the jquery filter.
|
394
395
|
|
395
396
|
* [angularjs](https://github.com/rubys/wunderbar/blob/master/demo/angularjs.rb)
|
396
|
-
makes use of the angular filters to implement the
|
397
|
+
makes use of the angular filters to implement the
|
397
398
|
[angular.js tutorial](http://docs.angularjs.org/tutorial). This demo
|
398
399
|
includes:
|
399
400
|
* [view](https://github.com/rubys/wunderbar/blob/master/demo/views/index._html)
|
@@ -404,7 +405,7 @@ Picking a Ruby to JS mapping tool
|
|
404
405
|
---
|
405
406
|
|
406
407
|
> dsl — A domain specific language, where code is written in one language and
|
407
|
-
> errors are given in another.
|
408
|
+
> errors are given in another.
|
408
409
|
> -- [Devil’s Dictionary of Programming](http://programmingisterrible.com/post/65781074112/devils-dictionary-of-programming)
|
409
410
|
|
410
411
|
If you simply want to get a job done, and would like a mature and tested
|
@@ -15,23 +15,29 @@ module Ruby2JS
|
|
15
15
|
call.children[1] == :step and
|
16
16
|
[:irange, :erange].include? call.children.first.children.first.type
|
17
17
|
then
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
put "
|
26
|
-
put "; "; parse var;
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
begin
|
19
|
+
next_token, @next_token = @next_token, :continue
|
20
|
+
|
21
|
+
# convert combinations of range, step and block to a for loop
|
22
|
+
var = args.children.first
|
23
|
+
expression = call.children.first.children.first
|
24
|
+
comp = (expression.type == :irange ? '<=' : '<')
|
25
|
+
put "for (var "; parse var; put " = "; parse expression.children.first
|
26
|
+
put "; "; parse var;
|
27
|
+
if call.children[2].type == :int and call.children[2].children[0] < 0
|
28
|
+
put " #{comp.sub('<', '>')} "; parse expression.children.last
|
29
|
+
put "; "; parse var; put " -= "
|
30
|
+
parse s(:int, -call.children[2].children[0])
|
31
|
+
else
|
32
|
+
put " #{comp} "; parse expression.children.last
|
33
|
+
put "; "; parse var; put " += "; parse call.children[2]
|
34
|
+
end
|
35
|
+
puts ") {"
|
36
|
+
scope block
|
37
|
+
sput "}"
|
38
|
+
ensure
|
39
|
+
@next_token = next_token
|
31
40
|
end
|
32
|
-
puts ") {"
|
33
|
-
scope block
|
34
|
-
sput "}"
|
35
41
|
|
36
42
|
elsif
|
37
43
|
call.children[0] == nil and call.children[1] == :function and
|
data/lib/ruby2js/haml.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Example usage:
|
2
|
+
#
|
3
|
+
# Add:
|
4
|
+
# gem 'ruby2js'
|
5
|
+
# to your gemfile and bundle
|
6
|
+
# Add:
|
7
|
+
# require "ruby2js/haml"
|
8
|
+
# to any initializer ot config/application.rb
|
9
|
+
#
|
10
|
+
# Use :ruby2js filter in your templates like
|
11
|
+
#
|
12
|
+
# :ruby2js
|
13
|
+
# alert "Hello"
|
14
|
+
#
|
15
|
+
# (Note missing brackets: ruby syntax, js sematics)
|
16
|
+
#
|
17
|
+
require "haml"
|
18
|
+
|
19
|
+
module Ruby2JS
|
20
|
+
module Haml::Ruby2JS
|
21
|
+
include Haml::Filters::Base
|
22
|
+
def render(text)
|
23
|
+
converted = Ruby2JS.convert(text).to_s
|
24
|
+
"<script type='text/javascript'>\n#{converted}\n</script>"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/ruby2js/rails.rb
CHANGED
@@ -17,12 +17,13 @@ module Ruby2JS
|
|
17
17
|
module Rails
|
18
18
|
class Template
|
19
19
|
cattr_accessor :default_format
|
20
|
-
self.default_format = Mime
|
20
|
+
self.default_format = Mime[:js]
|
21
21
|
def self.call(template)
|
22
|
-
"Ruby2JS.convert(#{template.source.inspect})"
|
22
|
+
"Ruby2JS.convert(#{template.source.inspect}).to_s"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
ActionView::Template.register_template_handler :rb, Template
|
27
27
|
end
|
28
|
+
|
28
29
|
end
|
data/lib/ruby2js/version.rb
CHANGED
data/ruby2js.gemspec
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: ruby2js 2.1.
|
2
|
+
# stub: ruby2js 2.1.22 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "ruby2js".freeze
|
6
|
-
s.version = "2.1.
|
6
|
+
s.version = "2.1.22"
|
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-
|
11
|
+
s.date = "2017-11-13"
|
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
|
-
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]
|
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/haml.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]
|
15
15
|
s.homepage = "http://github.com/rubys/ruby2js".freeze
|
16
16
|
s.licenses = ["MIT".freeze]
|
17
17
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9.3".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.
|
4
|
+
version: 2.1.22
|
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-
|
11
|
+
date: 2017-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/ruby2js/filter/strict.rb
|
101
101
|
- lib/ruby2js/filter/underscore.rb
|
102
102
|
- lib/ruby2js/filter/vue.rb
|
103
|
+
- lib/ruby2js/haml.rb
|
103
104
|
- lib/ruby2js/rails.rb
|
104
105
|
- lib/ruby2js/serializer.rb
|
105
106
|
- lib/ruby2js/sinatra.rb
|