opal-rails 1.1.1 → 1.1.2

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
  SHA256:
3
- metadata.gz: 1d61bba3aec7f4e72f6415ff750bc0a41af46a8ce59a701c566b8f85fb5468d7
4
- data.tar.gz: ce19e5c523a251b03a06ef8b2b322e45238909d6bdb4b6a169bcf8c08e6f8223
3
+ metadata.gz: 9fe52f8b8220d7217cdee145bf089a14e6992c1c187c1a62bba8585433d34081
4
+ data.tar.gz: 413cd3f385011549dbaa800d3aeb46df5677d0d25e6dfd2e15eedb96f0c58e8c
5
5
  SHA512:
6
- metadata.gz: fc73e4fc9f70678e509496a0bb17d05b2da13072b0e1568067a82d5839ee0c5f2054646883eb8506d79a86314b5f1b755a7f5d6dc4f2bee88fbafcb907ceabe4
7
- data.tar.gz: 3d653b799aa04cd98e4272df376c62c3df95c29195279e0d734d272166018b84fcd922f490f5cb9a03d6cb6c32174b00bfd4ebf1459a24173db0c17a5b8e665d
6
+ metadata.gz: 87b789a075dd3f62c76e4dae46686ea291a2949a197a03cfd2c38aac96fc19b16c04e0e8903ed406e5aa9e679969a7e7bde793e6e436c54a63a6b12398eb98fd
7
+ data.tar.gz: 855c4c73ad06af2c8334aaf7db85c886600210349568b9ced0cc9e49bf952dddd4143c7083fbd69e5f5816cf78e448fa86186606daf0012829edda5063aedc8c
@@ -21,6 +21,16 @@ Whitespace conventions:
21
21
 
22
22
 
23
23
 
24
+ ## [1.1.2](https://github.com/opal/opal-rails/compare/v1.1.1...v1.1.2) - 2019-09-26
25
+
26
+
27
+ ### Fixed
28
+
29
+ - Default `skip_onload` to `true` when `javascript_asset_tag` is in debug mode, otherwise some assets may be loaded in the browser after the main source, thus being never loading by the Opal runtime.
30
+
31
+
32
+
33
+
24
34
  ## [1.1.1](https://github.com/opal/opal-rails/compare/v1.1.0...v1.1.1) - 2019-09-14
25
35
 
26
36
 
@@ -10,20 +10,21 @@ module OpalHelper
10
10
  end
11
11
 
12
12
  def javascript_include_tag(*sources)
13
- options = sources.extract_options!
13
+ options = sources.extract_options!.symbolize_keys
14
+ debug = options[:debug] != false
14
15
  skip_loader = options.delete(:skip_opal_loader)
15
- skip_onload = options.delete(:force_opal_loader_tag)
16
+ force_opal_loader_tag = options.delete(:force_opal_loader_tag) || debug
16
17
 
17
- return super(*sources, options) if skip_loader
18
+ return super(*sources, options) if skip_loader && !force_opal_loader_tag
18
19
 
19
20
  script_tags = "".html_safe
20
21
  sources.each do |source|
21
22
  load_asset_code = Opal::Sprockets.load_asset(source)
22
23
  loading_code = "if(window.Opal && Opal.modules[#{source.to_json}]){#{load_asset_code}}"
23
24
 
24
- if skip_onload
25
+ if force_opal_loader_tag
25
26
  script_tags << super(source, options)
26
- script_tags << javascript_tag(loading_code)
27
+ script_tags << "\n".html_safe + javascript_tag(loading_code)
27
28
  else
28
29
  script_tags << super(source, options.merge(onload: loading_code))
29
30
  end
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Rails
3
- VERSION = '1.1.1'
3
+ VERSION = '1.1.2'
4
4
  end
5
5
  end
@@ -20,17 +20,29 @@ describe OpalHelper, type: :helper do
20
20
  # sprockets-rails v3 sets Rails.application.assets to nil in production mode
21
21
  allow(Rails.application).to receive(:assets).and_return(nil)
22
22
 
23
- loading_code = %Q{Opal.require("application");}
23
+ loading_code = [
24
+ %<if(window.Opal && Opal.modules["application"]){Opal.loaded(OpalLoaded || []);>,
25
+ %<Opal.require("application");}>,
26
+ ].join("\n")
27
+
24
28
  escaped_loading_code = ERB::Util.h loading_code
29
+ loading_code_in_script_tag = [
30
+ %(<script>), %(//<![CDATA[), loading_code, %(//]]>), %(</script>),
31
+ ].join("\n")
32
+
33
+ expect(helper.javascript_include_tag('application', debug: true)).to include(loading_code_in_script_tag)
34
+ expect(helper.javascript_include_tag('application', debug: true)).not_to include(escaped_loading_code)
25
35
 
26
- expect(helper.javascript_include_tag('application', debug: true)).to include(escaped_loading_code)
27
36
  expect(helper.javascript_include_tag('application', debug: false)).to include(escaped_loading_code)
37
+ expect(helper.javascript_include_tag('application', debug: false)).not_to include(loading_code_in_script_tag)
38
+
28
39
  expect(helper.javascript_include_tag('application', skip_opal_loader: true)).not_to include(escaped_loading_code)
29
- expect(helper.javascript_include_tag('application', skip_opal_loader: true)).not_to include(escaped_loading_code)
40
+ expect(helper.javascript_include_tag('application', skip_opal_loader: false)).to include(loading_code_in_script_tag)
41
+
42
+ expect(helper.javascript_include_tag('application', force_opal_loader_tag: true, debug: true)).to include(loading_code_in_script_tag)
43
+ expect(helper.javascript_include_tag('application', force_opal_loader_tag: true, debug: false)).to include(loading_code_in_script_tag)
30
44
 
31
- expect(helper.javascript_include_tag('application', force_opal_loader_tag: true, debug: true)).to include(loading_code)
32
- expect(helper.javascript_include_tag('application', force_opal_loader_tag: true, debug: false)).to include(loading_code)
33
- expect(helper.javascript_include_tag('application', force_opal_loader_tag: true, skip_opal_loader: true)).not_to include(loading_code)
34
- expect(helper.javascript_include_tag('application', force_opal_loader_tag: true, skip_opal_loader: true)).not_to include(loading_code)
45
+ expect(helper.javascript_include_tag('application', force_opal_loader_tag: true, skip_opal_loader: true)).not_to include(escaped_loading_code)
46
+ expect(helper.javascript_include_tag('application', force_opal_loader_tag: true, skip_opal_loader: true)).to include(loading_code_in_script_tag)
35
47
  end
36
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-14 00:00:00.000000000 Z
11
+ date: 2019-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails