opal-sprockets 0.4.5.1.0.3.7 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +26 -0
- data/CHANGELOG.md +39 -0
- data/bin/console +14 -0
- data/bin/rake +6 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- data/example/Gemfile.lock +1 -1
- data/lib/opal/environment.rb +4 -0
- data/lib/opal/processor.rb +4 -0
- data/lib/opal/sprockets.rb +13 -81
- data/lib/opal/sprockets/assets_helper.rb +78 -0
- data/lib/opal/sprockets/environment.rb +12 -14
- data/lib/opal/sprockets/erb.rb +12 -16
- data/lib/opal/sprockets/mime_types.rb +19 -0
- data/lib/opal/sprockets/processor.rb +111 -114
- data/lib/opal/sprockets/server.rb +94 -98
- data/lib/opal/sprockets/version.rb +1 -8
- data/opal-sprockets.gemspec +38 -24
- data/spec/fixtures/complex_sprockets.js.rb.erb +1 -1
- data/spec/fixtures/{jst_file.js.jst → jst_file.jst.ejs} +0 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/sprockets/erb_spec.rb +15 -25
- data/spec/sprockets/processor_spec.rb +53 -57
- data/spec/sprockets/server_spec.rb +95 -25
- data/spec/sprockets_spec.rb +9 -9
- data/spec/tilt/opal_spec.rb +1 -1
- metadata +69 -27
- data/.travis.yml +0 -21
- data/lib/opal/sprockets/path_reader.rb +0 -36
- data/spec/shared/path_finder_shared.rb +0 -19
- data/spec/shared/path_reader_shared.rb +0 -31
- data/spec/sprockets/path_reader_spec.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b7553caf49b2308f3315be681e7b7ab68d57eaf46b391927e6b1b5942aa8b4e
|
4
|
+
data.tar.gz: 846dd949a0c534c4053b0a298c927bbb101aa5788a7480ba7a855c902a1f599f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0ed4adf7cab6d38ad475a2393a66ab65fefd0d9522a1aff5acd25fb107f6d56794508dc4fb774da2871fd6d52bb1e8e5823a53fa28dee973239d7585f1c84a5
|
7
|
+
data.tar.gz: 6e96b8ea2acdbd21f38ab91670d8f4c0cd2ed4b4ad3fb0d1c49f78eb45469241efb221bb5a72c0181654012796be7f9673789889c61391f19cfe3d6f688a71e6
|
@@ -0,0 +1,26 @@
|
|
1
|
+
on:
|
2
|
+
- push
|
3
|
+
- pull_request
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
strategy:
|
8
|
+
matrix:
|
9
|
+
os: [ 'ubuntu-latest' ]
|
10
|
+
ruby: [ "3.0", "2.7", "2.6", "2.5" ]
|
11
|
+
opal: [ "1.0.3", "1.1.0" ]
|
12
|
+
|
13
|
+
runs-on: ${{ matrix.os }}
|
14
|
+
|
15
|
+
env:
|
16
|
+
OPAL_VERSION: ${{ matrix.opal }}
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby }}
|
23
|
+
- name: Setup project
|
24
|
+
run: bin/setup
|
25
|
+
- name: Run test
|
26
|
+
run: bin/rake
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,44 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [1.0.0](https://github.com/opal/opal-sprockets/compare/v0.4.9.1.0.3.7...v1.0.0)
|
4
|
+
|
5
|
+
*19 February 2021*
|
6
|
+
|
7
|
+
- Bump the supported sprockets version to v4
|
8
|
+
- Add support for Opal v1.1
|
9
|
+
- Only support Ruby comments in directive preprocessor (no one should have ever used "//", ["/*", or "*/")
|
10
|
+
- Fix the namespaces and move everything under Opal::Sprockets (the legacy namespaces will be dropped in version 1.1)
|
11
|
+
- The version schema has been simplified, not expecting sprockets to have major earthquakes like it was for v4
|
12
|
+
|
13
|
+
|
14
|
+
## [v0.4.9](https://github.com/opal/opal-sprockets/compare/v0.4.8.1.0.3.7...v0.4.9.1.0.3.7)
|
15
|
+
|
16
|
+
*11 September 2020*
|
17
|
+
|
18
|
+
- Avoid OpalLoaded undefined when applications have no dependencies.
|
19
|
+
|
20
|
+
|
21
|
+
## [v0.4.8](https://github.com/opal/opal-sprockets/compare/v0.4.7.1.0.3.7...v0.4.8.1.0.3.7)
|
22
|
+
|
23
|
+
*14 September 2019*
|
24
|
+
|
25
|
+
- Revert the changes in 0.4.7
|
26
|
+
|
27
|
+
|
28
|
+
## [v0.4.7](https://github.com/opal/opal-sprockets/compare/v0.4.6.1.0.3.7...v0.4.7.1.0.3.7)
|
29
|
+
|
30
|
+
*14 September 2019*
|
31
|
+
|
32
|
+
- Require `opal/sprockets` before calling `Opal::Sprockets.loaded_asset`
|
33
|
+
|
34
|
+
|
35
|
+
## [v0.4.6](https://github.com/opal/opal-sprockets/compare/v0.4.5.1.0.3.7...v0.4.6.1.0.3.7)
|
36
|
+
|
37
|
+
*24 July 2019*
|
38
|
+
|
39
|
+
- Allow multiple calls to the code produced by `Opal::Sprockets.load_asset`
|
40
|
+
|
41
|
+
|
3
42
|
## [v0.4.5](https://github.com/opal/opal-sprockets/compare/v0.4.4.1.0.3.7...v0.4.5.1.0.3.7)
|
4
43
|
|
5
44
|
*25 May 2019*
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "opal"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/rake
ADDED
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
data/example/Gemfile.lock
CHANGED
data/lib/opal/sprockets.rb
CHANGED
@@ -1,87 +1,19 @@
|
|
1
1
|
require 'opal'
|
2
|
-
require 'opal/sprockets/
|
3
|
-
require 'opal/sprockets/erb'
|
4
|
-
require 'opal/sprockets/server'
|
2
|
+
require 'opal/sprockets/version'
|
5
3
|
|
6
4
|
module Opal
|
7
5
|
module Sprockets
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# Opal.loaded("jquery.self", "yet_another_carousel.self");
|
18
|
-
# Opal.load("opal", "application");
|
19
|
-
#
|
20
|
-
# @param name [String] The logical name of the main asset to be loaded (without extension)
|
21
|
-
#
|
22
|
-
# @return [String] JavaScript code
|
23
|
-
def self.load_asset(*names)
|
24
|
-
if names.last.is_a?(::Sprockets::Environment)
|
25
|
-
unless @load_asset_warning_displayed
|
26
|
-
@load_asset_warning_displayed = true
|
27
|
-
warn "Passing a sprockets environment to Opal::Sprockets.load_asset no more needed.\n #{caller(1, 3).join("\n ")}"
|
28
|
-
end
|
29
|
-
names.pop
|
30
|
-
end
|
31
|
-
|
32
|
-
names = names.map { |name| name.sub(/(\.(js|rb|opal))*\z/, '') }
|
33
|
-
stubbed = ::Opal::Config.stubbed_files.to_a
|
34
|
-
|
35
|
-
loaded = 'OpalLoaded || []'
|
36
|
-
loaded = "#{stubbed.to_json}.concat(#{loaded})" if stubbed.any?
|
37
|
-
|
38
|
-
[
|
39
|
-
"Opal.loaded(#{loaded});",
|
40
|
-
*names.map { |name| "Opal.load(#{name.to_json});" }
|
41
|
-
].join("\n")
|
42
|
-
end
|
43
|
-
|
44
|
-
# Mark an asset as already loaded.
|
45
|
-
# This is useful for requiring JavaScript files which are not managed by Opal's laoding system.
|
46
|
-
#
|
47
|
-
# @param [String] name The "logical name" of the asset
|
48
|
-
# @return [String] JavaScript code
|
49
|
-
def self.loaded_asset(name)
|
50
|
-
%{if (typeof(OpalLoaded) === 'undefined') OpalLoaded = []; OpalLoaded.push(#{name.to_json});}
|
51
|
-
end
|
52
|
-
|
53
|
-
# Generate a `<script>` tag for Opal assets.
|
54
|
-
#
|
55
|
-
# @param [String] name The logical name of the asset to be loaded (without extension)
|
56
|
-
# @param [Hash] options The options about sprockets
|
57
|
-
# @option options [Sprockets::Environment] :sprockets The sprockets instance
|
58
|
-
# @option options [String] :prefix The prefix String at which is mounted Sprockets, e.g. '/assets'
|
59
|
-
# @option options [Boolean] :debug Wether to enable debug mode along with sourcemaps support
|
60
|
-
#
|
61
|
-
# @return a string of HTML code containing `<script>` tags.
|
62
|
-
def self.javascript_include_tag(name, options = {})
|
63
|
-
sprockets = options.fetch(:sprockets)
|
64
|
-
prefix = options.fetch(:prefix)
|
65
|
-
debug = options.fetch(:debug)
|
66
|
-
|
67
|
-
# Avoid double slashes
|
68
|
-
prefix = prefix.chop if prefix.end_with? '/'
|
69
|
-
|
70
|
-
asset = sprockets[name]
|
71
|
-
raise "Cannot find asset: #{name}" if asset.nil?
|
72
|
-
scripts = []
|
73
|
-
|
74
|
-
if debug
|
75
|
-
asset.to_a.map do |dependency|
|
76
|
-
scripts << %{<script src="#{prefix}/#{dependency.digest_path}?body=1"></script>}
|
77
|
-
end
|
78
|
-
else
|
79
|
-
scripts << %{<script src="#{prefix}/#{name}.js"></script>}
|
80
|
-
end
|
81
|
-
|
82
|
-
scripts << %{<script>#{load_asset('opal', name)}</script>}
|
83
|
-
|
84
|
-
scripts.join "\n"
|
85
|
-
end
|
6
|
+
require 'opal/sprockets/assets_helper'
|
7
|
+
require 'opal/sprockets/mime_types'
|
8
|
+
extend AssetsHelper
|
9
|
+
extend MimeTypes
|
10
|
+
|
11
|
+
require 'opal/sprockets/environment'
|
12
|
+
require 'opal/sprockets/erb'
|
13
|
+
require 'opal/sprockets/processor'
|
14
|
+
require 'opal/sprockets/server'
|
86
15
|
end
|
16
|
+
|
17
|
+
autoload :Processor, 'opal/processor'
|
18
|
+
autoload :Environment, 'opal/environment'
|
87
19
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Opal::Sprockets::AssetsHelper
|
2
|
+
# Bootstraps modules loaded by sprockets on `Opal.modules` marking any
|
3
|
+
# non-Opal asset as already loaded.
|
4
|
+
#
|
5
|
+
# @example
|
6
|
+
#
|
7
|
+
# Opal::Sprockets.load_asset('application')
|
8
|
+
#
|
9
|
+
# @example Will output the following JavaScript:
|
10
|
+
#
|
11
|
+
# Opal.loaded("jquery.self", "yet_another_carousel.self");
|
12
|
+
# Opal.require("opal", "application");
|
13
|
+
#
|
14
|
+
# @param name [String] The logical name of the main asset to be loaded (without extension)
|
15
|
+
#
|
16
|
+
# @return [String] JavaScript code
|
17
|
+
def load_asset(*names)
|
18
|
+
if names.last.is_a?(::Sprockets::Environment)
|
19
|
+
unless @load_asset_warning_displayed
|
20
|
+
@load_asset_warning_displayed = true
|
21
|
+
warn "Passing a sprockets environment to Opal::Sprockets.load_asset no more needed.\n #{caller(1, 3).join("\n ")}"
|
22
|
+
end
|
23
|
+
names.pop
|
24
|
+
end
|
25
|
+
|
26
|
+
names = names.map { |name| name.sub(/(\.(js|rb|opal))*\z/, '') }
|
27
|
+
stubbed = ::Opal::Config.stubbed_files.to_a
|
28
|
+
|
29
|
+
loaded = 'typeof(OpalLoaded) === "undefined" ? [] : OpalLoaded'
|
30
|
+
loaded = "#{stubbed.to_json}.concat(#{loaded})" if stubbed.any?
|
31
|
+
|
32
|
+
[
|
33
|
+
"Opal.loaded(#{loaded});",
|
34
|
+
*names.map { |name| "Opal.require(#{name.to_json});" }
|
35
|
+
].join("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
# Mark an asset as already loaded.
|
39
|
+
# This is useful for requiring JavaScript files which are not managed by Opal's laoding system.
|
40
|
+
#
|
41
|
+
# @param [String] name The "logical name" of the asset
|
42
|
+
# @return [String] JavaScript code
|
43
|
+
def loaded_asset(name)
|
44
|
+
%{if (typeof(OpalLoaded) === 'undefined') OpalLoaded = []; OpalLoaded.push(#{name.to_json});}
|
45
|
+
end
|
46
|
+
|
47
|
+
# Generate a `<script>` tag for Opal assets.
|
48
|
+
#
|
49
|
+
# @param [String] name The logical name of the asset to be loaded (without extension)
|
50
|
+
# @param [Hash] options The options about sprockets
|
51
|
+
# @option options [Sprockets::Environment] :sprockets The sprockets instance
|
52
|
+
# @option options [String] :prefix The prefix String at which is mounted Sprockets, e.g. '/assets'
|
53
|
+
# @option options [Boolean] :debug Wether to enable debug mode along with sourcemaps support
|
54
|
+
#
|
55
|
+
# @return a string of HTML code containing `<script>` tags.
|
56
|
+
def javascript_include_tag(name, options = {})
|
57
|
+
sprockets = options.fetch(:sprockets)
|
58
|
+
prefix = options.fetch(:prefix)
|
59
|
+
debug = options.fetch(:debug)
|
60
|
+
|
61
|
+
# Avoid double slashes
|
62
|
+
prefix = prefix.chop if prefix.end_with? '/'
|
63
|
+
|
64
|
+
asset = sprockets[name, accept: "application/javascript", pipeline: debug ? :debug : nil]
|
65
|
+
raise "Cannot find asset: #{name}" if asset.nil?
|
66
|
+
scripts = []
|
67
|
+
|
68
|
+
if debug
|
69
|
+
scripts << %{<script src="#{prefix}/#{asset.digest_path}"></script>}
|
70
|
+
else
|
71
|
+
scripts << %{<script src="#{prefix}/#{name}.js"></script>}
|
72
|
+
end
|
73
|
+
|
74
|
+
scripts << %{<script>#{load_asset('opal', name)}</script>}
|
75
|
+
|
76
|
+
scripts.join "\n"
|
77
|
+
end
|
78
|
+
end
|
@@ -2,22 +2,20 @@ require 'sprockets'
|
|
2
2
|
require 'opal/sprockets/processor'
|
3
3
|
require 'opal/sprockets/erb'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
5
|
+
class Opal::Sprockets::Environment < ::Sprockets::Environment
|
6
|
+
def initialize *args
|
7
|
+
super
|
8
|
+
append_opal_paths
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def use_gem gem_name
|
12
|
+
Opal.use_gem gem_name
|
13
|
+
append_opal_paths
|
14
|
+
end
|
16
15
|
|
17
|
-
|
16
|
+
private
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
def append_opal_paths
|
19
|
+
Opal.paths.each { |p| append_path p }
|
22
20
|
end
|
23
21
|
end
|
data/lib/opal/sprockets/erb.rb
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
require 'tilt'
|
2
2
|
require 'sprockets'
|
3
3
|
require 'opal/sprockets/processor'
|
4
|
+
require 'opal/erb'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
require_template_library 'opal/erb'
|
11
|
-
end
|
12
|
-
|
13
|
-
def evaluate(context, locals, &block)
|
14
|
-
compiler = Opal::ERB::Compiler.new(@data, context.logical_path.sub(/#{REGEXP_START}templates\//, ''))
|
15
|
-
@data = compiler.prepared_source
|
16
|
-
super
|
17
|
-
end
|
18
|
-
end
|
6
|
+
class Opal::Sprockets::ERB < ::Opal::Sprockets::Processor
|
7
|
+
def call
|
8
|
+
compiler = Opal::ERB::Compiler.new(@data, logical_path.sub(/#{Opal::REGEXP_START}templates\//, ''))
|
9
|
+
@data = compiler.prepared_source
|
10
|
+
super
|
19
11
|
end
|
12
|
+
|
13
|
+
# @deprecated
|
14
|
+
::Opal::ERB::Processor = self
|
20
15
|
end
|
21
16
|
|
22
|
-
|
23
|
-
Sprockets.
|
17
|
+
Sprockets.register_mime_type 'application/html+javascript+ruby', extensions: ['.opalerb', '.opal.erb', '.html.opal.erb']
|
18
|
+
Sprockets.register_transformer 'application/html+javascript+ruby', 'application/javascript', Opal::ERB::Processor
|
19
|
+
Opal::Sprockets.register_mime_type 'application/html+javascript+ruby'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Opal::Sprockets::MimeTypes
|
2
|
+
def register_mime_type(mime_type)
|
3
|
+
mime_types << mime_type
|
4
|
+
end
|
5
|
+
|
6
|
+
def mime_types
|
7
|
+
@mime_types ||= []
|
8
|
+
end
|
9
|
+
|
10
|
+
def sprockets_extnames_regexp(sprockets, opal_only: false)
|
11
|
+
opal_extnames = sprockets.mime_types.map do |type, hash|
|
12
|
+
hash[:extensions] if !opal_only || Opal::Sprockets.mime_types.include?(type)
|
13
|
+
end.compact.flatten
|
14
|
+
|
15
|
+
opal_extnames << ".js" unless opal_only
|
16
|
+
|
17
|
+
Regexp.union(opal_extnames.map { |i| /#{Regexp.escape(i)}\z/ })
|
18
|
+
end
|
19
|
+
end
|