es6_module_transpiler-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +57 -17
- data/Rakefile +11 -0
- data/es6_module_transpiler-rails.gemspec +4 -3
- data/lib/es6_module_transpiler/rails.rb +10 -0
- data/lib/es6_module_transpiler/rails/version.rb +2 -2
- data/lib/es6_module_transpiler/sprockets.rb +2 -0
- data/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb +1 -1
- data/test/template_test.rb +62 -0
- data/test/test_helper.rb +15 -0
- metadata +26 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc36efc25f4cc21d7620b5413ba5534d2532f3db
|
4
|
+
data.tar.gz: c3e570f0e999bd2e211298e1db0ed8c18639065a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2822e3fa8c43312cce1e84e025cf8700822caeac49ab7325c65e2221cae9ea23c800f2cc3e4e151015eb58822e57930da5cc53a449bfc035b74787fa70485d4
|
7
|
+
data.tar.gz: 3a263060f62bd31ebafa11c524df2e32e4b66c4ddbc3939f43d0eb3427174b84eeb2b9afe03cbe0cebbbf9a3910e94ae0035c02b489bbba39d238b870e7a4876
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,69 @@
|
|
1
|
-
# Es6ModuleTranspiler
|
1
|
+
# Es6ModuleTranspiler-Rails #
|
2
2
|
|
3
|
-
|
3
|
+
Transpile ES6 Modules in the Rails Asset Pipeline
|
4
4
|
|
5
|
-
## Installation
|
5
|
+
## Installation ##
|
6
6
|
|
7
|
-
|
7
|
+
**Node.js must be installed for the transpiling to happen**
|
8
8
|
|
9
|
-
|
9
|
+
```ruby
|
10
|
+
gem 'es6_module_transpiler-rails'
|
11
|
+
```
|
10
12
|
|
11
|
-
|
13
|
+
## Usage ##
|
12
14
|
|
13
|
-
|
15
|
+
Your modules will transpile are named based upon their directory
|
16
|
+
nesting + filename, as long as the file has the `.es6` extension.
|
17
|
+
For example, `app/assets/javascripts/controllers/fooController.js.es6`
|
14
18
|
|
15
|
-
|
19
|
+
```js
|
20
|
+
var fooController = function() {
|
21
|
+
console.log('fooController is in the house!')
|
22
|
+
};
|
16
23
|
|
17
|
-
|
24
|
+
export default = fooController;
|
25
|
+
```
|
18
26
|
|
19
|
-
|
27
|
+
will compile to
|
20
28
|
|
21
|
-
|
29
|
+
```js
|
30
|
+
define("controllers/fooController",
|
31
|
+
["exports"],
|
32
|
+
function(__exports__) {
|
33
|
+
"use strict";
|
34
|
+
var fooController = function() {
|
35
|
+
console.log('fooController is in the house!')
|
36
|
+
};
|
22
37
|
|
23
|
-
|
38
|
+
__exports__["default"] = fooController;
|
39
|
+
});
|
40
|
+
```
|
24
41
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
42
|
+
### Compiling ###
|
43
|
+
|
44
|
+
By default your module will compile to an AMD. If you wish to compile it as a global just make the following switch:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
ES6ModuleTranspiler.compile_to = :global
|
48
|
+
```
|
49
|
+
|
50
|
+
## Authors ##
|
51
|
+
|
52
|
+
[Brian Cardarella](http://twitter.com/bcardarella)
|
53
|
+
|
54
|
+
[We are very thankful for the many contributors](https://github.com/dockyard/es6_module_transpiler-rails/graphs/contributors)
|
55
|
+
|
56
|
+
## Versioning ##
|
57
|
+
|
58
|
+
This gem follows [Semantic Versioning](http://semver.org)
|
59
|
+
|
60
|
+
## Want to help? ##
|
61
|
+
|
62
|
+
Please do! We are always looking to improve this gem.
|
63
|
+
## Legal ##
|
64
|
+
|
65
|
+
[DockYard](http://dockyard.com), LLC © 2013
|
66
|
+
|
67
|
+
[@dockyard](http://twitter.com/dockyard)
|
68
|
+
|
69
|
+
[Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'es6_module_transpiler/rails/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "es6_module_transpiler-rails"
|
8
|
-
spec.version =
|
8
|
+
spec.version = ES6ModuleTranspiler::Rails::VERSION
|
9
9
|
spec.authors = ["Brian Cardarella"]
|
10
10
|
spec.email = ["bcardarella@gmail.com"]
|
11
11
|
spec.summary = %q{ES6 Module Transpiler for Rails}
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency 'execjs'
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'tilt'
|
24
|
+
spec.add_development_dependency 'sprockets'
|
24
25
|
end
|
@@ -1,3 +1,13 @@
|
|
1
1
|
require 'es6_module_transpiler/rails/version'
|
2
2
|
require 'es6_module_transpiler/tilt'
|
3
3
|
require 'es6_module_transpiler/sprockets'
|
4
|
+
|
5
|
+
module ES6ModuleTranspiler
|
6
|
+
def self.compile_to
|
7
|
+
@compile_to || :amd
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.compile_to=(target)
|
11
|
+
@compile_to = target
|
12
|
+
end
|
13
|
+
end
|
@@ -27,7 +27,7 @@ module Tilt
|
|
27
27
|
var Compiler, compiler, output;
|
28
28
|
Compiler = require("#{transpiler_path}").Compiler;
|
29
29
|
compiler = new Compiler(#{::JSON.generate(data, quirks_mode: true)}, '#{scope.logical_path}');
|
30
|
-
return output = compiler.toAMD();
|
30
|
+
return output = compiler.#{ES6ModuleTranspiler.compile_to.to_sym == :global ? 'toGlobals' : 'toAMD'}();
|
31
31
|
SOURCE
|
32
32
|
end
|
33
33
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'es6_module_transpiler/tilt'
|
3
|
+
require 'execjs'
|
4
|
+
|
5
|
+
Scope = Struct.new('Scope', :logical_path)
|
6
|
+
|
7
|
+
describe Tilt::ES6ModuleTranspilerTemplate do
|
8
|
+
before do
|
9
|
+
@source = <<-JS
|
10
|
+
var foo = function() {
|
11
|
+
console.log('bar');
|
12
|
+
};
|
13
|
+
|
14
|
+
export default = foo;
|
15
|
+
JS
|
16
|
+
@source.rstrip!
|
17
|
+
end
|
18
|
+
|
19
|
+
after do
|
20
|
+
ES6ModuleTranspiler.compile_to = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'transpiles es6 into amd by default' do
|
24
|
+
expected = <<-JS
|
25
|
+
define("foo",
|
26
|
+
["exports"],
|
27
|
+
function(__exports__) {
|
28
|
+
"use strict";
|
29
|
+
var foo = function() {
|
30
|
+
console.log('bar');
|
31
|
+
};
|
32
|
+
|
33
|
+
__exports__["default"] = foo;
|
34
|
+
});
|
35
|
+
JS
|
36
|
+
expected.rstrip!
|
37
|
+
|
38
|
+
template = Tilt::ES6ModuleTranspilerTemplate.new { @source }
|
39
|
+
scope = Scope.new('foo')
|
40
|
+
template.render(scope).must_equal expected
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'transpiles es6 into global when set' do
|
44
|
+
ES6ModuleTranspiler.compile_to = :global
|
45
|
+
|
46
|
+
expected = <<-JS
|
47
|
+
(function(__exports__) {
|
48
|
+
"use strict";
|
49
|
+
var foo = function() {
|
50
|
+
console.log('bar');
|
51
|
+
};
|
52
|
+
|
53
|
+
__exports__.foo = foo;
|
54
|
+
})(window);
|
55
|
+
JS
|
56
|
+
expected.rstrip!
|
57
|
+
|
58
|
+
template = Tilt::ES6ModuleTranspilerTemplate.new { @source }
|
59
|
+
scope = Scope.new('foo')
|
60
|
+
template.render(scope).must_equal expected
|
61
|
+
end
|
62
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'byebug'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'es6_module_transpiler/rails'
|
4
|
+
|
5
|
+
if defined?(M)
|
6
|
+
require 'minitest/spec'
|
7
|
+
else
|
8
|
+
require 'minitest/autorun'
|
9
|
+
end
|
10
|
+
|
11
|
+
class MiniTest::Spec
|
12
|
+
class << self
|
13
|
+
alias :context :describe
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es6_module_transpiler-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Cardarella
|
@@ -25,21 +25,35 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
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: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: tilt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sprockets
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - '>='
|
@@ -72,6 +86,8 @@ files:
|
|
72
86
|
- lib/es6_module_transpiler/support/es6_node_runner.js
|
73
87
|
- lib/es6_module_transpiler/tilt.rb
|
74
88
|
- lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb
|
89
|
+
- test/template_test.rb
|
90
|
+
- test/test_helper.rb
|
75
91
|
homepage: https://github.com/dockyard/es6_module_transpiler-rails
|
76
92
|
licenses:
|
77
93
|
- MIT
|
@@ -96,4 +112,6 @@ rubygems_version: 2.1.5
|
|
96
112
|
signing_key:
|
97
113
|
specification_version: 4
|
98
114
|
summary: ES6 Module Transpiler for Rails
|
99
|
-
test_files:
|
115
|
+
test_files:
|
116
|
+
- test/template_test.rb
|
117
|
+
- test/test_helper.rb
|