sprockets-babel-miniracer 0.0.8 → 0.0.9

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: 6fb4ec842672837d48c65e2bec9420364b8d982f
4
- data.tar.gz: 463c8f9637f03cf0e8de7d5e3b2c9de6b985bd44
3
+ metadata.gz: 0b9e786bd2a5be9671ffd010be79846e9489f836
4
+ data.tar.gz: ddceedac186a787b8d284e3773a077f4737a08d9
5
5
  SHA512:
6
- metadata.gz: 7b37954b0bb88fe3e055367e0610580299dbdb8b2ebd2130e8f009a0ccfc24eac7359172718a73ad2449a5390c5e17304957299dc6830fd7aad48d13732d72e7
7
- data.tar.gz: 631024e720602d549d95fcfe47e586ff89f1b57ab74c81c022bb8f743b4ffc6e3f20590f9207cd596c21a527bdd61785a7c3e3df87860187407cab19209412a0
6
+ metadata.gz: 468a28fb603e50266bb785d5f2f9d5aecbea4ad300c06c7aed63b8cdf60fefb00f305d3ffb2814a81981aa21f3c6c89c2ad9ad46bf5e0e50c45cf75e6be2d40b
7
+ data.tar.gz: 2a90fd0348433a6dfadaf2e6c4b627933dc5d69be1143908adec8f3a9f2ccf5238c16ea0e210e1ba0c7f734fe10300b5f965cfdb21a1dcc1d5d84f85f5e4c9ac
data/README.md CHANGED
@@ -6,8 +6,34 @@ the ES6 transpiler in a Sprockets 2.x environment.
6
6
 
7
7
  This is intended as a temporary solution until Sprockets 2.x can be upgraded.
8
8
 
9
+ ## Usage
10
+
11
+ Default module defie logic is to use "inline". However, that generates extra boilerplate on every file,
12
+ which accumulates to be plenty with lot fo files.
13
+
14
+ Using 'amd' allows to reduce boilerplate, but requires including "define.js" before es6 files in manifest.
15
+
16
+ config/initializers/babel.rb
17
+ ```
18
+ Babel.options do |opt|
19
+ opt[:modules] = 'amd'
20
+ end
21
+ ```
22
+
23
+ app/assets/javascripts/application.js
24
+ ```
25
+ //= require sprockets-babel-miniracer/define
26
+ ```
27
+
28
+
9
29
  ## Background
10
30
 
31
+ NOTE KI
32
+
33
+ Created to allow support for miniracer, and to fix some minor logic bugs
34
+
35
+ Original: [sprockets-babel](70mainstreet/sprockets-babel)
36
+
11
37
  I created this gem for the following reasons:
12
38
 
13
39
  * I need Babel for IE 8 support, but
@@ -1,6 +1,6 @@
1
1
  (function(global) {
2
2
  global.define = function(moduleId, importIds, body) {
3
- var resolveRelativeModuleId = function(targetId) {
3
+ function resolveRelativeModuleId(targetId) {
4
4
  var targetParts = targetId.split(/\//),
5
5
  basename = targetParts.pop();
6
6
  if ((targetParts.length == 0) || (targetParts[0] != '.' && targetParts[0] != '..')) {
@@ -21,8 +21,9 @@
21
21
  var parts = fromParts.concat(targetParts);
22
22
  return (parts.length == 0) ? basename : parts.join('/') + '/' + basename;
23
23
  };
24
- var toVariableName = function(moduleId) {
25
- return '$__' + encodeURIComponent(moduleId.replace(/^\.\//g, ''))
24
+
25
+ function toVariableName(moduleId) {
26
+ return '$__' + encodeURIComponent(moduleId.replace(/^\.\//, ''))
26
27
  .replace(/%|-/g, '') + '__';
27
28
  };
28
29
 
data/lib/babel.rb CHANGED
@@ -1,7 +1,13 @@
1
+ require 'sprockets/babel/railtie'
2
+
1
3
  module Babel
2
4
  def self.options
3
5
  @options ||= {}
4
6
  yield @options if block_given?
5
7
  @options
6
8
  end
7
- end
9
+
10
+ def self.gem_root_dir
11
+ @gem_root_dir ||= File.expand_path('../..', __FILE__)
12
+ end
13
+ end
@@ -136,8 +136,8 @@ module Sprockets
136
136
  var exports = {};
137
137
  global.#{module_var} = exports;
138
138
 
139
- var define = function(moduleId, importIds, body) {
140
- var resolveRelativeModuleId = function(targetId) {
139
+ function define(moduleId, importIds, body) {
140
+ function resolveRelativeModuleId(targetId) {
141
141
  var targetParts = targetId.split(/\\//),
142
142
  basename = targetParts.pop();
143
143
  if ((targetParts.length == 0) || (targetParts[0] != '.' && targetParts[0] != '..')) {
@@ -169,7 +169,7 @@ module Sprockets
169
169
  }
170
170
 
171
171
  var importId = resolveRelativeModuleId(importIds[i]),
172
- variable = '$__' + encodeURIComponent(importId.replace(/^\\.\\//g, ''))
172
+ variable = '$__' + encodeURIComponent(importId.replace(/^\\.\\//, ''))
173
173
  .replace(/%|-/g, '') + '__';
174
174
  imports.push(global[variable]);
175
175
  }
@@ -0,0 +1,39 @@
1
+ require "sprockets/railtie"
2
+
3
+ module Sprockets
4
+ module Babel
5
+ class Railtie < ::Rails::Railtie
6
+ # assets
7
+ initializer 'base' do |app|
8
+ register_asset_paths(app)
9
+ end
10
+
11
+ rake_tasks do
12
+ Base.load_tasks
13
+ end
14
+
15
+ private
16
+
17
+ def register_asset_paths(app)
18
+ base_dirs = [
19
+ 'app',
20
+ ]
21
+
22
+ asset_dirs = [
23
+ 'javascripts',
24
+ ]
25
+
26
+ assets = app.config.assets
27
+ base_dirs.each do |base_dir|
28
+ asset_dirs.each do |asset_dir|
29
+ path = "#{::Babel.gem_root_dir}/#{base_dir}/assets/#{asset_dir}"
30
+ if File.exist?(path)
31
+ ::Rails.logger.info "asset_path: #{path}"
32
+ config.assets.paths << path
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Babel
3
- VERSION = '0.0.8'
3
+ VERSION = '0.0.9'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-babel-miniracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kari Ikonen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-07 00:00:00.000000000 Z
11
+ date: 2016-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets
@@ -78,10 +78,11 @@ files:
78
78
  - LICENSE.txt
79
79
  - README.md
80
80
  - Rakefile
81
+ - app/assets/javascripts/sprockets-babel-miniracer/define.js
81
82
  - lib/babel.rb
82
- - lib/sprockets-babel-inline-module-loader.js
83
83
  - lib/sprockets-babel-miniracer.rb
84
84
  - lib/sprockets/babel.rb
85
+ - lib/sprockets/babel/railtie.rb
85
86
  - lib/sprockets/babel/version.rb
86
87
  - sprockets-babel-miniracer.gemspec
87
88
  - test/fixtures/Regions.js.es6