opal-sprockets 0.4.0.0.11.dev.3.1.beta1 → 0.4.0.0.11.0.rc1.3.1.beta2

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: 32661426be37d64787c573dce2cc35f816489310
4
- data.tar.gz: de0cef69723ae23293fc0b79f812e62cd703ad7a
3
+ metadata.gz: 7f468bcbf61d1f13cb364f124c53b8ae927ea02a
4
+ data.tar.gz: 6f759a6a77b4e6ae82733c2a504a1b0ffc562fd3
5
5
  SHA512:
6
- metadata.gz: e2094ff150dbb679d7734cf4df0ee5e10e725cb9eecd64e3d24f66b29fabfe257fa5d6006ff4b1fda306ad43a224f05490b3bba39d5e58dff7256be8fde1f600
7
- data.tar.gz: af5c8dab0703e5a7f1ebebaa3f4e80b4f09e80c0f7112f62ba744874f4bca1c3adfb147aa0e592dccdb10363d6aae1889ca7b24a8b79e46d5b2dd6b16917f307
6
+ metadata.gz: b894dc0cd1e9b0b8443f3e915dc18719786a63c0443f096d419ca71b4551e50c3d6f42d7f96f74e61b9c7cad1c01e46490539fcc7d5f686d912380867bb61186
7
+ data.tar.gz: 2718a9c2659da6a27d290102f00b0405af71760547f65a77cb96754205a4165e96aba496561da57f57d272e4c51ad95b7bbc226e399f26e2cd93597888b26095
data/.travis.yml CHANGED
@@ -8,9 +8,9 @@ matrix:
8
8
  env: RACK_VERSION='< 2.0.0' SPROCKETS_VERSION='~> 3.5.2'
9
9
  - rvm: 2.2.5
10
10
  env: SPROCKETS_VERSION='~> 3.6.3'
11
- - rvm: 2.3.1
12
- env: SPROCKETS_VERSION='~> 3.7.0'
13
- - rvm: 2.4.0-preview1
11
+ - rvm: 2.3.4
12
+ env: SPROCKETS_VERSION='~> 3.7.1'
13
+ - rvm: 2.4.0
14
14
 
15
15
  notifications:
16
16
  irc: "irc.freenode.org#opal"
data/README.md CHANGED
@@ -81,8 +81,10 @@ Bundler.require
81
81
 
82
82
  run Opal::Sprockets::Server.new { |s|
83
83
  s.append_path 'app'
84
-
85
84
  s.main = 'application'
85
+
86
+ # This can be used to provide a custom index file.
87
+ # s.index_path = 'my_index.erb'
86
88
  }
87
89
  ```
88
90
 
@@ -6,8 +6,15 @@ module MyApp
6
6
  def initialize
7
7
  @user = User.new('Bill')
8
8
  @user.authenticated?
9
+ rescue
10
+ @user = User.new('Bob')
11
+ @user.authenticated?
12
+ p @user
9
13
  end
10
14
  end
11
15
  end
12
16
 
13
- MyApp::Application.new
17
+ $app = MyApp::Application.new
18
+
19
+ p $app
20
+ puts "Done!"
@@ -141,6 +141,30 @@ module Opal
141
141
  end
142
142
  end
143
143
 
144
+ module Opal::Sprockets::Processor
145
+ module PlainJavaScriptLoader
146
+ def self.call(input)
147
+ sprockets = input[:environment]
148
+ asset = OpenStruct.new(input)
149
+
150
+ opal_extnames = sprockets.engines.map do |ext, engine|
151
+ ext if engine <= ::Opal::Processor
152
+ end.compact
153
+
154
+ path_extnames = -> path { File.basename(path).scan(/\.[^.]+/) }
155
+ processed_by_opal = -> asset { (path_extnames[asset.filename] & opal_extnames).any? }
156
+
157
+ unless processed_by_opal[asset]
158
+ [
159
+ input[:data],
160
+ %{if (typeof(OpalLoaded) === 'undefined') OpalLoaded = []; OpalLoaded.push(#{input[:name].to_json});}
161
+ ].join(";\n")
162
+ end
163
+ end
164
+ end
165
+ end
166
+
167
+
144
168
  if Sprockets.respond_to? :register_transformer
145
169
  extra_args = [{mime_type: 'application/javascript', silence_deprecation: true}]
146
170
  else
@@ -149,3 +173,5 @@ end
149
173
 
150
174
  Sprockets.register_engine '.rb', Opal::Processor, *extra_args
151
175
  Sprockets.register_engine '.opal', Opal::Processor, *extra_args
176
+ Sprockets.register_postprocessor 'application/javascript', Opal::Sprockets::Processor::PlainJavaScriptLoader
177
+
@@ -1,8 +1,8 @@
1
1
  module Opal
2
2
  module Sprockets
3
3
  BASE_VERSION = '0.4.0'
4
- OPAL_VERSION = '0.11.dev'
4
+ OPAL_VERSION = '0.11.0.rc1'
5
5
  SPROCKETS_VERSION = '3.1'
6
- VERSION = "#{BASE_VERSION}.#{OPAL_VERSION}.#{SPROCKETS_VERSION}.beta1"
6
+ VERSION = "#{BASE_VERSION}.#{OPAL_VERSION}.#{SPROCKETS_VERSION}.beta2"
7
7
  end
8
8
  end
@@ -10,7 +10,7 @@ module Opal
10
10
  #
11
11
  # @example
12
12
  #
13
- # Opal::Sprockets.load_asset(Rails.application.assets, 'application')
13
+ # Opal::Sprockets.load_asset('application')
14
14
  #
15
15
  # @example Will output the following JavaScript:
16
16
  #
@@ -20,38 +20,24 @@ module Opal
20
20
  # Opal.load("application");
21
21
  # }
22
22
  #
23
- # @param name [String] The logical name of the main asset to be loaded (without extension)
24
- # @param sprockets [Sprockets::Environment]
23
+ # @param name [String] The logical name of the main asset to be loaded (without extension)
25
24
  #
26
25
  # @return [String] JavaScript code
27
- def self.load_asset(name, sprockets)
28
- asset = sprockets[name.sub(/(\.(js|rb|opal))*#{REGEXP_END}/, '.js')]
29
- return '' if asset.nil?
30
-
31
- opal_extnames = sprockets.engines.map do |ext, engine|
32
- ext if engine <= ::Opal::Processor
33
- end.compact
26
+ def self.load_asset(name, _sprockets = :deprecated)
27
+ if _sprockets != :deprecated && !@load_asset_warning_displayed
28
+ @load_asset_warning_displayed = true
29
+ warn "Passing a sprockets environment to Opal::Sprockets.load_asset no more needed.\n #{caller(1, 3).join("\n ")}"
30
+ end
34
31
 
35
- module_name = -> asset { asset.logical_path.sub(/\.js#{REGEXP_END}/, '') }
36
- path_extnames = -> path { File.basename(path).scan(/\.[^.]+/) }
37
- mark_loaded = -> paths { "Opal.loaded([#{paths.map(&:inspect).join(',')}]);" }
38
- processed_by_opal = -> asset { (path_extnames[asset.pathname] & opal_extnames).any? }
32
+ name = name.sub(/(\.(js|rb|opal))*\z/, '')
39
33
  stubbed_files = ::Opal::Config.stubbed_files
40
34
 
41
- non_opal_assets = ([asset]+asset.dependencies)
42
- .select { |asset| not(processed_by_opal[asset]) }
43
- .map { |asset| module_name[asset] }
44
-
45
- loaded = ['opal'] + non_opal_assets + stubbed_files.to_a
46
-
47
- if processed_by_opal[asset]
48
- load_asset_code = "Opal.load(#{module_name[asset].inspect});"
49
- end
50
-
35
+ loaded = ['opal', 'corelib/runtime'] + stubbed_files.to_a
51
36
 
52
37
  "if (typeof(Opal) !== 'undefined') { "\
53
- "#{mark_loaded[loaded]} "\
54
- "#{load_asset_code} "\
38
+ "Opal.loaded(#{loaded.to_json}); "\
39
+ "if (typeof(OpalLoaded) === 'undefined') Opal.loaded(OpalLoaded); "\
40
+ "if (Opal.modules[#{name.to_json}]) Opal.load(#{name.to_json}); "\
55
41
  "}"
56
42
  end
57
43
 
@@ -84,7 +70,7 @@ module Opal
84
70
  scripts << %{<script src="#{prefix}/#{name}.js"></script>}
85
71
  end
86
72
 
87
- scripts << %{<script>#{::Opal::Sprockets.load_asset(name, sprockets)}</script>}
73
+ scripts << %{<script>#{::Opal::Sprockets.load_asset(name)}</script>}
88
74
 
89
75
  scripts.join "\n"
90
76
  end
@@ -4,11 +4,11 @@ require File.expand_path('../lib/opal/sprockets/version', __FILE__)
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'opal-sprockets'
6
6
  s.version = Opal::Sprockets::VERSION
7
- s.author = 'Adam Beynon'
8
- s.email = 'adam.beynon@gmail.com'
7
+ s.authors = ['Elia Schito', 'Adam Beynon']
8
+ s.email = 'elia@schito.me'
9
9
  s.homepage = 'http://opalrb.org'
10
- s.summary = 'Sprockets support for opal'
11
- s.description = 'Sprockets suppoer for opal.'
10
+ s.summary = 'Sprockets support for Opal.'
11
+ s.description = 'Sprockets support for Opal.'
12
12
 
13
13
  s.files = `git ls-files`.split("\n")
14
14
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -61,7 +61,7 @@ describe Opal::Processor do
61
61
  allow(environment).to receive(:[]).with('bar.js') { asset }
62
62
  allow(environment).to receive(:engines) { {'.rb' => described_class, '.opal' => described_class} }
63
63
 
64
- code = ::Opal::Sprockets.load_asset('bar', environment)
64
+ code = ::Opal::Sprockets.load_asset('bar')
65
65
  expect(code).to match(stubbed_file)
66
66
  end
67
67
  end
@@ -7,21 +7,28 @@ describe Opal::Sprockets do
7
7
 
8
8
  describe '.load_asset' do
9
9
  it 'loads the main asset' do
10
- code = described_class.load_asset('console', env)
10
+ code = described_class.load_asset('console')
11
11
  expect(code).to include('Opal.load("console");')
12
12
  end
13
13
 
14
14
  it 'marks as loaded "opal" plus all non opal assets' do
15
- code = described_class.load_asset('corelib/runtime', env)
15
+ code = described_class.load_asset('corelib/runtime')
16
16
  expect(code).to include('Opal.loaded(["opal","corelib/runtime"]);')
17
17
  end
18
18
 
19
- it 'returns an empty string if the asset is not found' do
20
- code = described_class.load_asset('foo', env)
21
- expect(code).to eq('')
19
+ it 'tries to load an asset if it is registered as opal module' do
20
+ code = described_class.load_asset('foo')
21
+ expect(code).to include('if (Opal.modules["foo"]) Opal.load("foo");')
22
22
  end
23
23
  end
24
24
 
25
+ it 'warns the user that passing an env is not needed, only once' do
26
+ expect(described_class).to receive(:warn).once
27
+ described_class.load_asset('foo', env)
28
+ described_class.load_asset('foo', env)
29
+ described_class.load_asset('foo', env)
30
+ end
31
+
25
32
  describe '.javascript_include_tag' do
26
33
  it 'works with trailing / in the prefix' do
27
34
  code = described_class.javascript_include_tag('corelib/runtime', prefix: '/', sprockets: env, debug: false)
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.0.11.dev.3.1.beta1
4
+ version: 0.4.0.0.11.0.rc1.3.1.beta2
5
5
  platform: ruby
6
6
  authors:
7
+ - Elia Schito
7
8
  - Adam Beynon
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-09-28 00:00:00.000000000 Z
12
+ date: 2017-05-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: sprockets
@@ -30,14 +31,14 @@ dependencies:
30
31
  requirements:
31
32
  - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: 0.11.dev
34
+ version: 0.11.0.rc1
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
39
  - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: 0.11.dev
41
+ version: 0.11.0.rc1
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: tilt
43
44
  requirement: !ruby/object:Gem::Requirement
@@ -94,8 +95,8 @@ dependencies:
94
95
  - - ">="
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0'
97
- description: Sprockets suppoer for opal.
98
- email: adam.beynon@gmail.com
98
+ description: Sprockets support for Opal.
99
+ email: elia@schito.me
99
100
  executables: []
100
101
  extensions: []
101
102
  extra_rdoc_files: []
@@ -164,10 +165,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
165
  version: 1.3.1
165
166
  requirements: []
166
167
  rubyforge_project:
167
- rubygems_version: 2.6.4
168
+ rubygems_version: 2.6.8
168
169
  signing_key:
169
170
  specification_version: 4
170
- summary: Sprockets support for opal
171
+ summary: Sprockets support for Opal.
171
172
  test_files:
172
173
  - spec/fixtures/complex_sprockets.js.rb.erb
173
174
  - spec/fixtures/file_with_directives.js