opal-sprockets 0.4.9.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 +11 -0
- data/bin/console +14 -0
- data/bin/rake +6 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- 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/tilt/opal_spec.rb +1 -1
- metadata +66 -24
- 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
@@ -2,115 +2,111 @@ require 'erb'
|
|
2
2
|
require 'rack'
|
3
3
|
require 'sprockets'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
create_app
|
23
|
-
end
|
5
|
+
class Opal::Sprockets::Server
|
6
|
+
attr_accessor :debug, :use_index, :index_path, :main, :public_root,
|
7
|
+
:public_urls, :sprockets, :prefix
|
8
|
+
|
9
|
+
def initialize options = {}
|
10
|
+
@use_index = true
|
11
|
+
@public_root = nil
|
12
|
+
@public_urls = ['/']
|
13
|
+
@sprockets = options.fetch(:sprockets, ::Sprockets::Environment.new)
|
14
|
+
@debug = options.fetch(:debug, true)
|
15
|
+
@prefix = options.fetch(:prefix, '/assets')
|
16
|
+
|
17
|
+
Opal.paths.each { |p| @sprockets.append_path(p) }
|
18
|
+
|
19
|
+
yield self if block_given?
|
20
|
+
create_app
|
21
|
+
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
def public_dir=(dir)
|
24
|
+
@public_root = dir
|
25
|
+
@public_urls = ["/"]
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
def source_map=(enabled)
|
29
|
+
Opal::Config.source_map_enabled = enabled
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
def source_map_enabled
|
33
|
+
Opal::Config.source_map_enabled
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
def append_path path
|
37
|
+
@sprockets.append_path path
|
38
|
+
end
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
def use_gem gem_name
|
41
|
+
@sprockets.use_gem gem_name
|
42
|
+
end
|
45
43
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
44
|
+
def create_app
|
45
|
+
server, sprockets, prefix = self, @sprockets, self.prefix
|
46
|
+
sprockets.logger.level ||= Logger::DEBUG
|
47
|
+
|
48
|
+
@app = Rack::Builder.app do
|
49
|
+
not_found = lambda { |env| [404, {}, []] }
|
50
|
+
use Rack::Deflater
|
51
|
+
use Rack::ShowExceptions
|
52
|
+
use Index, server if server.use_index
|
53
|
+
map(prefix) { run sprockets }
|
54
|
+
run Rack::Static.new(not_found, root: server.public_root, urls: server.public_urls)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def call(env)
|
59
|
+
@app.call env
|
60
|
+
end
|
61
|
+
|
62
|
+
class Index
|
63
|
+
|
64
|
+
def initialize(app, server)
|
65
|
+
@app = app
|
66
|
+
@server = server
|
67
|
+
@index_path = server.index_path
|
68
|
+
end
|
59
69
|
|
60
|
-
|
70
|
+
def call(env)
|
71
|
+
if %w[/ /index.html].include? env['PATH_INFO']
|
72
|
+
[200, { 'Content-Type' => 'text/html' }, [html]]
|
73
|
+
else
|
61
74
|
@app.call env
|
62
75
|
end
|
76
|
+
end
|
63
77
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
def call(env)
|
73
|
-
if %w[/ /index.html].include? env['PATH_INFO']
|
74
|
-
[200, { 'Content-Type' => 'text/html' }, [html]]
|
75
|
-
else
|
76
|
-
@app.call env
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# Returns the html content for the root path. Supports ERB
|
81
|
-
def html
|
82
|
-
if @index_path
|
83
|
-
raise "index does not exist: #{@index_path}" unless File.exist?(@index_path)
|
84
|
-
Tilt.new(@index_path).render(self)
|
85
|
-
else
|
86
|
-
raise "Main asset path not configured (set 'main' within Opal::Server.new block)" if @server.main.nil?
|
87
|
-
source
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def javascript_include_tag name
|
92
|
-
sprockets = @server.sprockets
|
93
|
-
prefix = @server.prefix
|
94
|
-
debug = @server.debug
|
95
|
-
|
96
|
-
::Opal::Sprockets.javascript_include_tag(name, sprockets: sprockets, prefix: prefix, debug: debug)
|
97
|
-
end
|
98
|
-
|
99
|
-
def source
|
100
|
-
<<-HTML
|
101
|
-
<!DOCTYPE html>
|
102
|
-
<html>
|
103
|
-
<head>
|
104
|
-
<meta charset="utf-8">
|
105
|
-
<title>Opal Server</title>
|
106
|
-
</head>
|
107
|
-
<body>
|
108
|
-
#{javascript_include_tag @server.main}
|
109
|
-
</body>
|
110
|
-
</html>
|
111
|
-
HTML
|
112
|
-
end
|
78
|
+
# Returns the html content for the root path. Supports ERB
|
79
|
+
def html
|
80
|
+
if @index_path
|
81
|
+
raise "index does not exist: #{@index_path}" unless File.exist?(@index_path)
|
82
|
+
Tilt.new(@index_path).render(self)
|
83
|
+
else
|
84
|
+
raise "Main asset path not configured (set 'main' within Opal::Server.new block)" if @server.main.nil?
|
85
|
+
source
|
113
86
|
end
|
114
87
|
end
|
88
|
+
|
89
|
+
def javascript_include_tag name
|
90
|
+
sprockets = @server.sprockets
|
91
|
+
prefix = @server.prefix
|
92
|
+
debug = @server.debug
|
93
|
+
|
94
|
+
::Opal::Sprockets.javascript_include_tag(name, sprockets: sprockets, prefix: prefix, debug: debug)
|
95
|
+
end
|
96
|
+
|
97
|
+
def source
|
98
|
+
<<-HTML
|
99
|
+
<!DOCTYPE html>
|
100
|
+
<html>
|
101
|
+
<head>
|
102
|
+
<meta charset="utf-8">
|
103
|
+
<title>Opal Server</title>
|
104
|
+
</head>
|
105
|
+
<body>
|
106
|
+
#{javascript_include_tag @server.main}
|
107
|
+
</body>
|
108
|
+
</html>
|
109
|
+
HTML
|
110
|
+
end
|
115
111
|
end
|
116
112
|
end
|
@@ -1,12 +1,5 @@
|
|
1
1
|
module Opal
|
2
2
|
module Sprockets
|
3
|
-
|
4
|
-
OPAL_VERSION = '1.0.0'
|
5
|
-
SPROCKETS_VERSION = '3.7'
|
6
|
-
|
7
|
-
# Just keep the first two segments of dependencies' versions
|
8
|
-
v = -> v { v.split('.')[0..1].compact.join('.') }
|
9
|
-
|
10
|
-
VERSION = "#{BASE_VERSION}.#{v[OPAL_VERSION]}.#{v[SPROCKETS_VERSION]}"
|
3
|
+
VERSION = '1.0.0'
|
11
4
|
end
|
12
5
|
end
|
data/opal-sprockets.gemspec
CHANGED
@@ -1,25 +1,39 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
require_relative 'lib/opal/sprockets/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'opal-sprockets'
|
5
|
+
spec.version = Opal::Sprockets::VERSION
|
6
|
+
spec.authors = ['Elia Schito', 'Adam Beynon']
|
7
|
+
spec.email = 'elia@schito.me'
|
8
|
+
|
9
|
+
spec.summary = 'Sprockets support for Opal.'
|
10
|
+
spec.homepage = 'https://github.com/opal/opal-sprockets#readme'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
|
13
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
14
|
+
spec.metadata['source_code_uri'] = 'https://github.com/opal/opal-sprockets'
|
15
|
+
spec.metadata['changelog_uri'] = 'https://github.com/opal/opal-sprockets/blob/master/CHANGELOG.md'
|
16
|
+
|
17
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 3.1')
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
|
22
|
+
|
23
|
+
spec.files = files.grep_v(%r{^(test|spec|features)/})
|
24
|
+
spec.test_files = files.grep(%r{^(test|spec|features)/})
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency 'sprockets', "~> 4.0"
|
30
|
+
spec.add_dependency 'opal', [">= 1.0", "< 1.2"]
|
31
|
+
spec.add_dependency 'tilt', '>= 1.4'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'rake'
|
34
|
+
spec.add_development_dependency 'rspec'
|
35
|
+
spec.add_development_dependency 'rack-test'
|
36
|
+
spec.add_development_dependency 'sourcemap'
|
37
|
+
spec.add_development_dependency 'ejs'
|
38
|
+
spec.add_development_dependency 'pry'
|
25
39
|
end
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
data/spec/sprockets/erb_spec.rb
CHANGED
@@ -1,38 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'opal/sprockets/erb'
|
3
3
|
|
4
|
-
describe Opal::ERB
|
4
|
+
describe Opal::Sprockets::ERB do
|
5
5
|
let(:pathname) { Pathname("/Code/app/mylib/opal/foo.#{ext}") }
|
6
|
-
let(:
|
7
|
-
|
8
|
-
:
|
9
|
-
|
10
|
-
engines: double(keys: %w[.rb .js .erb .opal]),
|
11
|
-
) }
|
12
|
-
let(:sprockets_context) { double(Sprockets::Context,
|
13
|
-
logical_path: "foo.#{ext}",
|
14
|
-
environment: environment,
|
15
|
-
pathname: pathname,
|
6
|
+
let(:data) { %{<% print("") %><a href="<%= url %>"><%= name %></a>} }
|
7
|
+
let(:input) { {
|
8
|
+
environment: Opal::Sprockets::Environment.new.tap {|e| e.append_path "/Code/app/mylib/opal"},
|
9
|
+
data: data,
|
16
10
|
filename: pathname.to_s,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
let(:template) { described_class.new { |t| %Q{<% print("") %><a href="<%= url %>"><%= name %></a>} } }
|
22
|
-
before { allow(sprockets_context).to receive(:require_asset) {|asset| required_assets << asset } }
|
23
|
-
|
11
|
+
load_path: "/Code/app/mylib/opal",
|
12
|
+
metadata: {},
|
13
|
+
cache: Sprockets::Cache.new
|
14
|
+
} }
|
24
15
|
let(:ext) { 'opalerb' }
|
25
16
|
|
26
|
-
it "is registered for '.opalerb' files" do
|
27
|
-
expect(Tilt["test.#{ext}"]).to eq(described_class)
|
28
|
-
end
|
29
|
-
|
30
17
|
it 'renders the template' do
|
31
|
-
|
18
|
+
result = described_class.call(input)
|
19
|
+
|
20
|
+
expect(result[:data]).to include('"<a href=\""')
|
32
21
|
end
|
33
22
|
|
34
23
|
it 'implicitly requires "erb"' do
|
35
|
-
|
36
|
-
|
24
|
+
result = described_class.call(input)
|
25
|
+
|
26
|
+
expect(result[:required].first).to include("stdlib/erb.rb")
|
37
27
|
end
|
38
28
|
end
|
@@ -1,79 +1,75 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'opal/sprockets/processor'
|
3
3
|
|
4
|
-
describe Opal::Processor do
|
4
|
+
describe Opal::Sprockets::Processor do
|
5
5
|
let(:pathname) { Pathname("/Code/app/mylib/opal/foo.#{ext}") }
|
6
|
-
let(:
|
7
|
-
|
8
|
-
:
|
9
|
-
|
10
|
-
engines: double(keys: %w[.rb .js .opal]),
|
11
|
-
) }
|
12
|
-
let(:sprockets_context) { double(Sprockets::Context,
|
13
|
-
logical_path: "foo.#{ext}",
|
14
|
-
environment: environment,
|
15
|
-
pathname: pathname,
|
6
|
+
let(:data) { "foo" }
|
7
|
+
let(:input) { {
|
8
|
+
environment: Opal::Sprockets::Environment.new.tap {|e| e.append_path "/Code/app/mylib/opal"},
|
9
|
+
data: data,
|
16
10
|
filename: pathname.to_s,
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
load_path: "/Code/app/mylib/opal",
|
12
|
+
metadata: {},
|
13
|
+
cache: Sprockets::Cache.new
|
14
|
+
} }
|
15
|
+
|
16
|
+
before do
|
17
|
+
allow(Sprockets::SourceMapUtils).to receive(:format_source_map)
|
18
|
+
allow(Sprockets::SourceMapUtils).to receive(:combine_source_maps)
|
19
|
+
end
|
20
20
|
|
21
21
|
%w[.rb .opal].each do |ext|
|
22
|
-
|
22
|
+
describe %{with extension "#{ext}"} do
|
23
|
+
let(:ext) { ext }
|
23
24
|
|
24
|
-
describe %Q{with extension "#{ext}"} do
|
25
25
|
it "is registered for '#{ext}' files" do
|
26
|
-
|
26
|
+
mime_type = Sprockets.mime_types.find { |_,v| v[:extensions].include? ".rb" }.first
|
27
|
+
transformers = Sprockets.transformers[mime_type]
|
28
|
+
transformer = transformers["application/javascript"]
|
29
|
+
expect(transformer.processors).to include(described_class)
|
27
30
|
end
|
28
31
|
|
29
|
-
it "compiles
|
30
|
-
|
31
|
-
|
32
|
+
it "compiles the code" do
|
33
|
+
result = described_class.call(input.merge data: "puts 'Hello, World!'\n")
|
34
|
+
|
35
|
+
expect(result[:data]).to include('"Hello, World!"')
|
32
36
|
end
|
33
|
-
end
|
34
|
-
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
e.run
|
40
|
-
config.stubbed_files.clear
|
41
|
-
end
|
38
|
+
describe '.stubbed_files' do
|
39
|
+
it 'requires non-stubbed files' do
|
40
|
+
result = described_class.call(input.merge(data: 'require "set"'))
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
let(:config) { Opal::Config }
|
42
|
+
expect(result[:required].first).to include("stdlib/set.rb")
|
43
|
+
end
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
45
|
+
it 'skips require of stubbed file' do
|
46
|
+
Opal::Config.stubbed_files << 'set'
|
47
|
+
result = described_class.call(input.merge(data: "require 'set'"))
|
51
48
|
|
52
|
-
|
53
|
-
|
54
|
-
expect(sprockets_context).not_to receive(:require_asset).with(stubbed_file)
|
55
|
-
template.render(sprockets_context)
|
56
|
-
end
|
49
|
+
expect(result[:required]).not_to include("set.rb")
|
50
|
+
end
|
57
51
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
allow(environment).to receive(:[]).with('bar.js') { asset }
|
62
|
-
allow(environment).to receive(:engines) { {'.rb' => described_class, '.opal' => described_class} }
|
52
|
+
it 'marks a stubbed file as loaded' do
|
53
|
+
Opal::Config.stubbed_files << 'set'
|
54
|
+
result = described_class.call(input.merge(data: "require 'set'"))
|
63
55
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
56
|
+
expect(result[:data]).not_to include(::Opal::Sprockets.load_asset('set'))
|
57
|
+
end
|
58
|
+
end
|
68
59
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
60
|
+
describe '.cache_key' do
|
61
|
+
it 'can be reset' do
|
62
|
+
old_cache_key = described_class.cache_key
|
63
|
+
Opal::Config.arity_check_enabled = !Opal::Config.arity_check_enabled
|
64
|
+
stale_cache_key = described_class.cache_key
|
65
|
+
|
66
|
+
described_class.reset_cache_key!
|
67
|
+
reset_cache_key = described_class.cache_key
|
68
|
+
|
69
|
+
expect(stale_cache_key).to eq(old_cache_key)
|
70
|
+
expect(reset_cache_key).not_to eq(old_cache_key)
|
71
|
+
end
|
72
|
+
end
|
77
73
|
end
|
78
74
|
end
|
79
75
|
end
|