es6_module_transpiler-rails 0.1.0 → 0.2.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
2
  SHA1:
3
- metadata.gz: ef492949c9891aea4037b153ed175704b51664a0
4
- data.tar.gz: dfde4e7c2bcda175cfc2c5b499ecb0c726e84e31
3
+ metadata.gz: df247f64aa23e630a5f7a2b1a8ddae37d896fe88
4
+ data.tar.gz: 47b694121e3470f4f0d3dfac9cd2ab56fd2481ec
5
5
  SHA512:
6
- metadata.gz: a8d4a8bc753035f49bb01fc2dcd51207d837eb4c1c88c60c844d1ad306ccaff0e42d48fb7f0a107503460bd5619e0552aa57dfe6e5f33665e590b4b330a68f08
7
- data.tar.gz: 60bec7dbbfe15bacf4d7ec02e49013ef3e0f3efe69f1cf5a73dc6ad3983dd13f4aac4ba7ac2a65fc16a039bc0f94606f1c07aa4aa14446e1a37efc583d592924
6
+ metadata.gz: 0f0f433a5c78e59b54719322aa81d3360faf9a715e5ff811d03e3ba53eddb0f1ae7e949c4ae449b288bbca69a670ee5e46191cb3b22663544a2345a0b46e31e5
7
+ data.tar.gz: cc11c327dca5ec9f92c0662055c9ac601944cc6c2fb30b27d06a90f80dc4673286dc9503721f7117c40d512d020d5fb6314215a5b3fcefe3967e053063f85497
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.2.0
2
+
3
+ * Accept multiple prefix pattern matching
4
+ * Remove single pattern API
5
+
1
6
  ## 0.1.0
2
7
 
3
8
  * Updated es6-module-tranpiler.js to include fix for Herkoku deployment
data/README.md CHANGED
@@ -58,20 +58,23 @@ ES6ModuleTranspiler.compile_to = :cjs
58
58
  ### Custom Module Prefix ###
59
59
 
60
60
  You can match module names based upon a pattern to apply a prefix to the
61
- name:
61
+ name. You can add multiple patterns (which can each have separate prefixes):
62
62
 
63
63
  ```ruby
64
- ES6ModuleTranspiler.prefix_pattern = [/^(controllers|models|views|helpers|routes|router|store)/, 'app']
64
+ ES6ModuleTranspiler.add_prefix_pattern Regexp.new(File.join(Rails.root, 'app')), 'app'
65
+ ES6ModuleTranspiler.add_prefix_pattern Regexp.new(File.join(Rails.root, 'config')), 'config'
65
66
  ```
66
67
 
67
68
  This would match names that start with the pattern and prepend with
68
- `app/`. For example, `controllers/fooController` would now be named
69
- `app/controllers/fooController`.
69
+ `app/` or `config/`. For example, `/home/user/app/controllers/fooController` would now be named
70
+ `app/controllers/fooController`, and `/home/user/config/router` would now be
71
+ named `config/router`.
70
72
 
71
- Note the path is the *logical path* for the asset. For example, if the
73
+ Note the path is made up of the *root path* and the *logical path* for the asset. For example, if the
72
74
  path to your asset is
73
- `app/assets/javascripts/controllers/fooController.js.es6` the logical
74
- path is `controllers/fooController`.
75
+ `/home/user/app/assets/javascripts/controllers/fooController.js.es6` the root path is `/home/user/app/assets/javascripts/` and the logical
76
+ path is `controllers/fooController`. It is entirely dependent upon what
77
+ Sprockets considers to be the mount point for the asset.
75
78
 
76
79
  ## Authors ##
77
80
 
@@ -11,11 +11,17 @@ module ES6ModuleTranspiler
11
11
  @compile_to = target
12
12
  end
13
13
 
14
- def self.prefix_pattern
15
- @prefix_pattern || []
14
+ def self.prefix_patterns
15
+ @prefix_patterns ||= []
16
16
  end
17
17
 
18
- def self.prefix_pattern=(pattern)
19
- @prefix_pattern = pattern
18
+ def self.add_prefix_pattern(pattern, prefix)
19
+ prefix_patterns << [pattern, prefix]
20
+ end
21
+
22
+ def self.lookup_prefix(path)
23
+ _, prefix = prefix_patterns.detect {|pattern, prefix| pattern =~ path }
24
+
25
+ prefix
20
26
  end
21
27
  end
@@ -1,5 +1,5 @@
1
1
  module ES6ModuleTranspiler
2
2
  module Rails
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -30,17 +30,17 @@ module Tilt
30
30
  source = <<-SOURCE
31
31
  var Compiler, compiler, output;
32
32
  Compiler = require("#{transpiler_path}").Compiler;
33
- compiler = new Compiler(#{::JSON.generate(data, quirks_mode: true)}, '#{module_name(scope.logical_path)}');
33
+ compiler = new Compiler(#{::JSON.generate(data, quirks_mode: true)}, '#{module_name(scope.root_path, scope.logical_path)}');
34
34
  return output = compiler.#{compiler_method}();
35
35
  SOURCE
36
36
  end
37
37
 
38
- def module_name(path)
39
- if ES6ModuleTranspiler.prefix_pattern[0] === path
40
- path = "#{ES6ModuleTranspiler.prefix_pattern[1]}/#{path}"
38
+ def module_name(root_path, logical_path)
39
+ if prefix = ES6ModuleTranspiler.lookup_prefix(File.join(root_path, logical_path))
40
+ path = File.join(prefix, logical_path)
41
+ else
42
+ logical_path
41
43
  end
42
-
43
- path
44
44
  end
45
45
 
46
46
  def compiler_method
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
  require 'es6_module_transpiler/tilt'
3
3
  require 'execjs'
4
4
 
5
- Scope = Struct.new('Scope', :logical_path)
5
+ Scope = Struct.new('Scope', :root_path, :logical_path)
6
6
 
7
7
  describe Tilt::ES6ModuleTranspilerTemplate do
8
8
  before do
@@ -14,12 +14,12 @@ var foo = function() {
14
14
  export default = foo;
15
15
  JS
16
16
  @source.rstrip!
17
- @scope = Scope.new('foo')
17
+ @scope = Scope.new('', 'foo')
18
18
  end
19
19
 
20
20
  after do
21
21
  ES6ModuleTranspiler.compile_to = nil
22
- ES6ModuleTranspiler.prefix_pattern = []
22
+ ES6ModuleTranspiler.prefix_patterns.clear
23
23
  end
24
24
 
25
25
  it 'transpiles es6 into amd by default' do
@@ -78,7 +78,7 @@ JS
78
78
  end
79
79
 
80
80
  it 'transpiles with a prefixed name matching a pattern' do
81
- ES6ModuleTranspiler.prefix_pattern = [/^controllers/, 'app']
81
+ ES6ModuleTranspiler.add_prefix_pattern /app/, 'app'
82
82
 
83
83
  expected = <<-JS
84
84
  define("app/controllers/foo",
@@ -93,7 +93,7 @@ define("app/controllers/foo",
93
93
  });
94
94
  JS
95
95
  expected.rstrip!
96
- @scope = Scope.new('controllers/foo')
96
+ @scope = Scope.new('app', 'controllers/foo')
97
97
  template = Tilt::ES6ModuleTranspilerTemplate.new { @source }
98
98
  template.render(@scope).must_equal expected
99
99
 
@@ -110,7 +110,46 @@ define("foo",
110
110
  });
111
111
  JS
112
112
  expected.rstrip!
113
- @scope = Scope.new('foo')
113
+ @scope = Scope.new('', 'foo')
114
+ template = Tilt::ES6ModuleTranspilerTemplate.new { @source }
115
+ template.render(@scope).must_equal expected
116
+ end
117
+
118
+ it "can detect multiple prefix patterns" do
119
+ ES6ModuleTranspiler.add_prefix_pattern /app/, 'app'
120
+ ES6ModuleTranspiler.add_prefix_pattern /config/, 'config'
121
+
122
+ expected = <<-JS
123
+ define("app/models/foo",
124
+ ["exports"],
125
+ function(__exports__) {
126
+ "use strict";
127
+ var foo = function() {
128
+ console.log('bar');
129
+ };
130
+
131
+ __exports__["default"] = foo;
132
+ });
133
+ JS
134
+ expected.rstrip!
135
+ @scope = Scope.new('/home/user/app', 'models/foo')
136
+ template = Tilt::ES6ModuleTranspilerTemplate.new { @source }
137
+ template.render(@scope).must_equal expected
138
+
139
+ expected = <<-JS
140
+ define("config/foo",
141
+ ["exports"],
142
+ function(__exports__) {
143
+ "use strict";
144
+ var foo = function() {
145
+ console.log('bar');
146
+ };
147
+
148
+ __exports__["default"] = foo;
149
+ });
150
+ JS
151
+ expected.rstrip!
152
+ @scope = Scope.new('/home/users/config', 'foo')
114
153
  template = Tilt::ES6ModuleTranspilerTemplate.new { @source }
115
154
  template.render(@scope).must_equal expected
116
155
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: es6_module_transpiler-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cardarella
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-20 00:00:00.000000000 Z
11
+ date: 2013-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs