sprockets-iife 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +22 -0
- data/Appraisals +18 -0
- data/Gemfile +9 -0
- data/Rakefile +11 -0
- data/gemfiles/rails_3.gemfile +9 -0
- data/gemfiles/rails_4_with_sprockets_2.gemfile +9 -0
- data/gemfiles/rails_4_with_sprockets_3.gemfile +9 -0
- data/gemfiles/rails_5.gemfile +9 -0
- data/lib/sprockets-iife/processor.rb +42 -10
- data/lib/sprockets-iife/railtie.rb +6 -2
- data/lib/sprockets-iife/template.rb +21 -0
- data/lib/sprockets-iife/version.rb +1 -1
- data/lib/sprockets-iife/wrap.rb +18 -0
- data/lib/sprockets-iife.rb +2 -8
- data/sprockets-iife.gemspec +6 -1
- data/test/fixtures/javascripts/coffeebundle/bar-iife.js.erb +3 -0
- data/test/fixtures/javascripts/coffeebundle/bar.coffee +1 -0
- data/test/fixtures/javascripts/coffeebundle/foo.coffee +1 -0
- data/test/fixtures/javascripts/coffeebundle-iife.js.erb +3 -0
- data/test/fixtures/javascripts/coffeebundle.coffee +5 -0
- data/test/fixtures/javascripts/jsbundle/bar-iife.js.erb +3 -0
- data/test/fixtures/javascripts/jsbundle/bar.js +1 -0
- data/test/fixtures/javascripts/jsbundle/foo.js +1 -0
- data/test/fixtures/javascripts/jsbundle-iife.js.erb +3 -0
- data/test/fixtures/javascripts/jsbundle.js +5 -0
- data/test/fixtures/javascripts/mixedbundle/bar-iife.js.erb +3 -0
- data/test/fixtures/javascripts/mixedbundle/bar.coffee +1 -0
- data/test/fixtures/javascripts/mixedbundle/baz-iife.js.erb +3 -0
- data/test/fixtures/javascripts/mixedbundle/baz.js +1 -0
- data/test/fixtures/javascripts/mixedbundle/foo.js +1 -0
- data/test/fixtures/javascripts/mixedbundle-iife.js.erb +3 -0
- data/test/fixtures/javascripts/mixedbundle.coffee +6 -0
- data/test/test-sprockets-iife.rb +119 -0
- metadata +120 -5
- data/lib/sprockets-iife/legacy-processor.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9054960a6ef80b43a4d1c456cdb5c8bbb5d8a9d9
|
4
|
+
data.tar.gz: b19de6947d03fedc86186bc391c5049eb6c5d21e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 048f6a8ea56c515e51a30e7f2ee40519315df7da21b83da343b8050f24601324f41ca5ba42a8bf0b73ce5e21dedfead6fe83cc088c51598e5910699292b09144
|
7
|
+
data.tar.gz: 6bbc62993e0efd4ed04a5e08253936f43ec8f944957687e031051071dfe2667c1ff20bd28ab929ab56a5062216eb067450fa5dd5ff53ff5258ac65e1e27e1d87
|
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.10
|
6
|
+
- 2.2.5
|
7
|
+
- 2.3.1
|
8
|
+
|
9
|
+
cache: bundler
|
10
|
+
|
11
|
+
gemfile:
|
12
|
+
- gemfiles/rails_3.gemfile
|
13
|
+
- gemfiles/rails_4_with_sprockets_2.gemfile
|
14
|
+
- gemfiles/rails_4_with_sprockets_3.gemfile
|
15
|
+
- gemfiles/rails_5.gemfile
|
16
|
+
|
17
|
+
matrix:
|
18
|
+
exclude:
|
19
|
+
- rvm: 2.0.0
|
20
|
+
gemfile: gemfiles/rails_5.gemfile
|
21
|
+
- rvm: 2.1.10
|
22
|
+
gemfile: gemfiles/rails_5.gemfile
|
data/Appraisals
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
appraise 'rails-3' do
|
2
|
+
gem 'rails', '~> 3'
|
3
|
+
gem 'sprockets', '~> 2'
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise 'rails-4-with-sprockets-2' do
|
7
|
+
gem 'rails', '~> 4'
|
8
|
+
gem 'sprockets', '~> 3'
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise 'rails-4-with-sprockets-3' do
|
12
|
+
gem 'rails', '~> 4'
|
13
|
+
gem 'sprockets', '~> 3'
|
14
|
+
end
|
15
|
+
|
16
|
+
appraise 'rails-5' do
|
17
|
+
gem 'rails', '~> 5'
|
18
|
+
end
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -2,24 +2,56 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module SprocketsIIFE
|
5
|
-
class
|
6
|
-
|
5
|
+
class AbstractProcessor
|
6
|
+
def initialize(script_path, &block)
|
7
|
+
@script_path = script_path
|
8
|
+
@script_source = block.call
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(_, _)
|
12
|
+
self.class.wrap(@script_path, @script_source)
|
13
|
+
end
|
7
14
|
|
8
15
|
class << self
|
9
16
|
def call(input)
|
10
|
-
|
17
|
+
script_path = input[:filename]
|
18
|
+
script_source = input[:data]
|
19
|
+
context = input[:environment].context_class.new(input)
|
20
|
+
context.metadata.merge(data: wrap(script_path, script_source))
|
21
|
+
end
|
22
|
+
|
23
|
+
def wrap(script_path, script_source)
|
24
|
+
raise NotImplementedError
|
11
25
|
end
|
12
26
|
end
|
27
|
+
end
|
13
28
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
29
|
+
class ItemProcessor < AbstractProcessor
|
30
|
+
class << self
|
31
|
+
def wrap(script_path, script_source)
|
32
|
+
script_name = "#{File.basename(script_path, '.*')}.js"
|
33
|
+
seems_to_be_a_bundle = Rails.application.config.assets.precompile.any? do |x|
|
34
|
+
case x
|
35
|
+
when String then x == script_name
|
36
|
+
when Regexp then x =~ script_name
|
37
|
+
else false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
if seems_to_be_a_bundle
|
42
|
+
script_source
|
43
|
+
else
|
44
|
+
SprocketsIIFE.wrap(script_path, script_source)
|
45
|
+
end
|
46
|
+
end
|
19
47
|
end
|
48
|
+
end
|
20
49
|
|
21
|
-
|
22
|
-
|
50
|
+
class BundleProcessor < AbstractProcessor
|
51
|
+
class << self
|
52
|
+
def wrap(script_path, script_source)
|
53
|
+
SprocketsIIFE.wrap(script_path, script_source)
|
54
|
+
end
|
23
55
|
end
|
24
56
|
end
|
25
57
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'rails/railtie'
|
5
|
+
|
4
6
|
module SprocketsIIFE
|
5
7
|
class Railtie < Rails::Railtie
|
6
8
|
def configure_assets(app)
|
@@ -13,10 +15,12 @@ module SprocketsIIFE
|
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
initializer 'sprockets.iife',
|
18
|
+
initializer 'sprockets.iife', after: 'sprockets.environment' do |app|
|
17
19
|
configure_assets(app) do |env|
|
18
20
|
# Sprockets 2, 3, and 4
|
19
|
-
env.register_bundle_processor 'application/javascript', SprocketsIIFE::
|
21
|
+
env.register_bundle_processor 'application/javascript', SprocketsIIFE::BundleProcessor
|
22
|
+
env.register_mime_type 'application/javascript', extensions: ['.js']
|
23
|
+
env.register_postprocessor 'application/javascript', SprocketsIIFE::ItemProcessor
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
module SprocketsIIFE
|
7
|
+
class Template < ERB
|
8
|
+
def initialize(script_iife_path, script_source)
|
9
|
+
@script_source = script_source
|
10
|
+
super(File.read(script_iife_path))
|
11
|
+
end
|
12
|
+
|
13
|
+
def source
|
14
|
+
@script_source
|
15
|
+
end
|
16
|
+
|
17
|
+
def result
|
18
|
+
super(binding)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'sprockets-iife/template'
|
5
|
+
|
6
|
+
module SprocketsIIFE
|
7
|
+
class << self
|
8
|
+
def wrap(script_path, script_source)
|
9
|
+
script_iife_path = File.join(File.dirname(script_path), "#{File.basename(script_path, '.*')}-iife.js.erb")
|
10
|
+
|
11
|
+
if File.readable?(script_iife_path)
|
12
|
+
Template.new(script_iife_path, script_source).result
|
13
|
+
else
|
14
|
+
script_source
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/sprockets-iife.rb
CHANGED
@@ -2,12 +2,6 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'sprockets'
|
5
|
-
|
6
|
-
|
7
|
-
if $&.to_i > 2
|
8
|
-
require 'sprockets-iife/processor'
|
9
|
-
else
|
10
|
-
require 'sprockets-iife/legacy-processor'
|
11
|
-
end
|
12
|
-
|
5
|
+
require 'sprockets-iife/wrap'
|
6
|
+
require 'sprockets-iife/processor'
|
13
7
|
require 'sprockets-iife/railtie' if defined?(Rails)
|
data/sprockets-iife.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.author = 'Yaroslav Konoplov'
|
10
10
|
s.email = 'eahome00@gmail.com'
|
11
11
|
s.summary = 'IIFE wrapper generator for Sprockets'
|
12
|
-
s.description = 'Generates IIFE wrapper for Sprockets JavaScript
|
12
|
+
s.description = 'Generates IIFE wrapper for Sprockets JavaScript files'
|
13
13
|
s.homepage = 'https://github.com/yivo/sprockets-iife'
|
14
14
|
s.license = 'MIT'
|
15
15
|
|
@@ -19,4 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ['lib']
|
20
20
|
|
21
21
|
s.add_dependency 'sprockets', '>= 2.0', '< 5.0'
|
22
|
+
s.add_development_dependency 'bundler', '~> 1.7'
|
23
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
s.add_development_dependency 'appraisal', '~> 2.1'
|
25
|
+
s.add_development_dependency 'test-unit', '~> 3.1'
|
26
|
+
s.add_development_dependency 'coffee-rails'
|
22
27
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
bar.coffee()
|
@@ -0,0 +1 @@
|
|
1
|
+
foo.coffee()
|
@@ -0,0 +1 @@
|
|
1
|
+
bar.js();
|
@@ -0,0 +1 @@
|
|
1
|
+
foo.js();
|
@@ -0,0 +1 @@
|
|
1
|
+
bar.coffee()
|
@@ -0,0 +1 @@
|
|
1
|
+
baz.js();
|
@@ -0,0 +1 @@
|
|
1
|
+
foo.js();
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'sprockets-iife'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
class SprocketsIIFETest < Test::Unit::TestCase
|
9
|
+
def test_registration
|
10
|
+
app = create_rails_application
|
11
|
+
app.initialize!
|
12
|
+
|
13
|
+
assert app.assets.bundle_processors.key?('application/javascript')
|
14
|
+
assert Array === app.assets.bundle_processors['application/javascript']
|
15
|
+
assert app.assets.bundle_processors['application/javascript'].include?(SprocketsIIFE::BundleProcessor)
|
16
|
+
|
17
|
+
assert app.assets.postprocessors.key?('application/javascript')
|
18
|
+
assert Array === app.assets.postprocessors['application/javascript']
|
19
|
+
assert app.assets.postprocessors['application/javascript'].include?(SprocketsIIFE::ItemProcessor)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_compilation
|
23
|
+
app = create_rails_application
|
24
|
+
app.initialize!
|
25
|
+
task = create_sprockets_task(app)
|
26
|
+
task.instance_exec { manifest.compile(assets) }
|
27
|
+
|
28
|
+
expected = <<-JAVASCRIPT.squish
|
29
|
+
(function(/* jsbundle-iife */) {
|
30
|
+
jsbundle.js();
|
31
|
+
foo.js();
|
32
|
+
(function(/* bar-iife */) {
|
33
|
+
bar.js();
|
34
|
+
}).call(this);
|
35
|
+
}).call(this);
|
36
|
+
JAVASCRIPT
|
37
|
+
assert_equal expected, app.assets['jsbundle.js'].to_s.squish
|
38
|
+
|
39
|
+
expected = <<-JAVASCRIPT.squish
|
40
|
+
(function(/* coffeebundle-iife */) {
|
41
|
+
(function() { coffeebundle.coffee(); }).call(this);
|
42
|
+
(function() { foo.coffee(); }).call(this);
|
43
|
+
(function(/* bar-iife */) {
|
44
|
+
(function() { bar.coffee(); }).call(this);
|
45
|
+
}).call(this);
|
46
|
+
}).call(this);
|
47
|
+
JAVASCRIPT
|
48
|
+
assert_equal expected, app.assets['coffeebundle.js'].to_s.squish
|
49
|
+
|
50
|
+
expected = <<-JAVASCRIPT.squish
|
51
|
+
(function(/* mixedbundle-iife */) {
|
52
|
+
(function() { mixedbundle.coffee(); }).call(this);
|
53
|
+
foo.js();
|
54
|
+
(function(/* bar-iife */) {
|
55
|
+
(function() { bar.coffee(); }).call(this);
|
56
|
+
}).call(this);
|
57
|
+
(function(/* baz-iife */) {
|
58
|
+
baz.js();
|
59
|
+
}).call(this);
|
60
|
+
}).call(this);
|
61
|
+
JAVASCRIPT
|
62
|
+
assert_equal expected, app.assets['mixedbundle.js'].to_s.squish
|
63
|
+
end
|
64
|
+
|
65
|
+
def setup
|
66
|
+
super
|
67
|
+
clear_tmp
|
68
|
+
clear_logs
|
69
|
+
end
|
70
|
+
|
71
|
+
def teardown
|
72
|
+
super
|
73
|
+
clear_tmp
|
74
|
+
if defined?(Rails) && Rails.respond_to?(:application=)
|
75
|
+
Rails.application = nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
def create_rails_application
|
81
|
+
require 'rails'
|
82
|
+
require 'sprockets/railtie'
|
83
|
+
require 'sprockets-iife/railtie'
|
84
|
+
|
85
|
+
Class.new(Rails::Application) do
|
86
|
+
config.eager_load = false
|
87
|
+
config.assets.enabled = true
|
88
|
+
config.assets.gzip = false
|
89
|
+
config.assets.paths = [Rails.root.join('test/fixtures/javascripts').to_s]
|
90
|
+
config.assets.precompile = %w( jsbundle.js coffeebundle.js mixedbundle.js )
|
91
|
+
config.paths['public'] = [Rails.root.join('tmp').to_s]
|
92
|
+
config.active_support.deprecation = :stderr
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def create_sprockets_task(app)
|
97
|
+
require 'sprockets/version' # Fix for sprockets 2.x
|
98
|
+
|
99
|
+
if Sprockets::VERSION.start_with?('2')
|
100
|
+
require 'rake/sprocketstask'
|
101
|
+
Rake::SprocketsTask.new do |t|
|
102
|
+
t.environment = app.assets
|
103
|
+
t.output = "#{app.config.paths['public'][0]}#{app.config.assets.prefix}"
|
104
|
+
t.assets = app.config.assets.precompile
|
105
|
+
end
|
106
|
+
else
|
107
|
+
require 'sprockets/rails/task'
|
108
|
+
Sprockets::Rails::Task.new(app)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def clear_tmp
|
113
|
+
FileUtils.rm_rf(File.expand_path('../../tmp', __FILE__))
|
114
|
+
end
|
115
|
+
|
116
|
+
def clear_logs
|
117
|
+
FileUtils.rm_rf(File.expand_path('../../log', __FILE__))
|
118
|
+
end
|
119
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-iife
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Konoplov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sprockets
|
@@ -30,20 +30,117 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '5.0'
|
33
|
-
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.7'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.7'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: appraisal
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.1'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2.1'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: test-unit
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.1'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.1'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: coffee-rails
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
description: Generates IIFE wrapper for Sprockets JavaScript files
|
34
104
|
email: eahome00@gmail.com
|
35
105
|
executables: []
|
36
106
|
extensions: []
|
37
107
|
extra_rdoc_files: []
|
38
108
|
files:
|
39
109
|
- ".gitignore"
|
110
|
+
- ".travis.yml"
|
111
|
+
- Appraisals
|
112
|
+
- Gemfile
|
40
113
|
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- gemfiles/rails_3.gemfile
|
116
|
+
- gemfiles/rails_4_with_sprockets_2.gemfile
|
117
|
+
- gemfiles/rails_4_with_sprockets_3.gemfile
|
118
|
+
- gemfiles/rails_5.gemfile
|
41
119
|
- lib/sprockets-iife.rb
|
42
|
-
- lib/sprockets-iife/legacy-processor.rb
|
43
120
|
- lib/sprockets-iife/processor.rb
|
44
121
|
- lib/sprockets-iife/railtie.rb
|
122
|
+
- lib/sprockets-iife/template.rb
|
45
123
|
- lib/sprockets-iife/version.rb
|
124
|
+
- lib/sprockets-iife/wrap.rb
|
46
125
|
- sprockets-iife.gemspec
|
126
|
+
- test/fixtures/javascripts/coffeebundle-iife.js.erb
|
127
|
+
- test/fixtures/javascripts/coffeebundle.coffee
|
128
|
+
- test/fixtures/javascripts/coffeebundle/bar-iife.js.erb
|
129
|
+
- test/fixtures/javascripts/coffeebundle/bar.coffee
|
130
|
+
- test/fixtures/javascripts/coffeebundle/foo.coffee
|
131
|
+
- test/fixtures/javascripts/jsbundle-iife.js.erb
|
132
|
+
- test/fixtures/javascripts/jsbundle.js
|
133
|
+
- test/fixtures/javascripts/jsbundle/bar-iife.js.erb
|
134
|
+
- test/fixtures/javascripts/jsbundle/bar.js
|
135
|
+
- test/fixtures/javascripts/jsbundle/foo.js
|
136
|
+
- test/fixtures/javascripts/mixedbundle-iife.js.erb
|
137
|
+
- test/fixtures/javascripts/mixedbundle.coffee
|
138
|
+
- test/fixtures/javascripts/mixedbundle/bar-iife.js.erb
|
139
|
+
- test/fixtures/javascripts/mixedbundle/bar.coffee
|
140
|
+
- test/fixtures/javascripts/mixedbundle/baz-iife.js.erb
|
141
|
+
- test/fixtures/javascripts/mixedbundle/baz.js
|
142
|
+
- test/fixtures/javascripts/mixedbundle/foo.js
|
143
|
+
- test/test-sprockets-iife.rb
|
47
144
|
homepage: https://github.com/yivo/sprockets-iife
|
48
145
|
licenses:
|
49
146
|
- MIT
|
@@ -68,4 +165,22 @@ rubygems_version: 2.5.1
|
|
68
165
|
signing_key:
|
69
166
|
specification_version: 4
|
70
167
|
summary: IIFE wrapper generator for Sprockets
|
71
|
-
test_files:
|
168
|
+
test_files:
|
169
|
+
- test/fixtures/javascripts/coffeebundle-iife.js.erb
|
170
|
+
- test/fixtures/javascripts/coffeebundle.coffee
|
171
|
+
- test/fixtures/javascripts/coffeebundle/bar-iife.js.erb
|
172
|
+
- test/fixtures/javascripts/coffeebundle/bar.coffee
|
173
|
+
- test/fixtures/javascripts/coffeebundle/foo.coffee
|
174
|
+
- test/fixtures/javascripts/jsbundle-iife.js.erb
|
175
|
+
- test/fixtures/javascripts/jsbundle.js
|
176
|
+
- test/fixtures/javascripts/jsbundle/bar-iife.js.erb
|
177
|
+
- test/fixtures/javascripts/jsbundle/bar.js
|
178
|
+
- test/fixtures/javascripts/jsbundle/foo.js
|
179
|
+
- test/fixtures/javascripts/mixedbundle-iife.js.erb
|
180
|
+
- test/fixtures/javascripts/mixedbundle.coffee
|
181
|
+
- test/fixtures/javascripts/mixedbundle/bar-iife.js.erb
|
182
|
+
- test/fixtures/javascripts/mixedbundle/bar.coffee
|
183
|
+
- test/fixtures/javascripts/mixedbundle/baz-iife.js.erb
|
184
|
+
- test/fixtures/javascripts/mixedbundle/baz.js
|
185
|
+
- test/fixtures/javascripts/mixedbundle/foo.js
|
186
|
+
- test/test-sprockets-iife.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'tilt'
|
5
|
-
|
6
|
-
module SprocketsIIFE
|
7
|
-
class Processor < Tilt::Template
|
8
|
-
def prepare
|
9
|
-
end
|
10
|
-
|
11
|
-
# Call processor block with `context` and `data`.
|
12
|
-
def evaluate(context, locals, &block)
|
13
|
-
source_file = file
|
14
|
-
iife_file = File.join(File.dirname(source_file), "#{File.basename(source_file, '.*')}-iife.js.erb")
|
15
|
-
File.readable?(iife_file) ? ERB.new(File.read(iife_file)).result(binding) : data
|
16
|
-
end
|
17
|
-
|
18
|
-
alias source data
|
19
|
-
end
|
20
|
-
end
|