sprockets-jets 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 842c6136e2b8f4efb03f2e78bac691af922dd187e9c3eee9f84681b0bb8fbf93
4
+ data.tar.gz: dade6363a6463d5677c6e7ecde62a206fdebc5fbf04ac9fba10d896390987cd2
5
+ SHA512:
6
+ metadata.gz: 81928fabba5e67cae0f6832b0efa61155f0867f11265d0ef2b2c24a33299e138623b4a1fd609c911352df5de801b12b7c306a34066d4f3e8b725f1f41e3a7454
7
+ data.tar.gz: 23d2041951980d3f1bdf235e6a392fda9316393cbde9ff30b9275f12c7a4d76949e6678122ddd6bf08533e79261de07643202865d640e2bb583582edd89646ae
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ /.bundle
4
+ /.config
5
+ /.yardoc
6
+ /_yardoc
7
+ /coverage
8
+ /doc/
9
+ /Gemfile.lock
10
+ /InstalledFiles
11
+ /lib/bundler/man
12
+ /pkg
13
+ /rdoc
14
+ /spec/reports
15
+ /test/tmp
16
+ /test/version_tmp
17
+ /tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --color
3
+ --format documentation
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
+
6
+ ## [0.1.0]
7
+ - Initial release.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem dependencies in sprockets.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ guard "bundler", cmd: "bundle" do
2
+ watch("Gemfile")
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard :rspec, cmd: "bundle exec rspec" do
7
+ require "guard/rspec/dsl"
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) Tung Nguyen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Sprockets Jets
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/sprockets-jets.png)](http://badge.fury.io/rb/sprockets-jets)
4
+
5
+ [![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
6
+
7
+ [![BoltOps Learn Badge](https://img.boltops.com/boltops-learn/boltops-learn.png)](https://learn.boltops.com)
8
+
9
+ Provides [Sprockets](https://github.com/rails/sprockets) implementation for Jets Asset Pipeline.
10
+
11
+ ## Installation
12
+
13
+ Gemfile
14
+
15
+ ```ruby
16
+ gem "sprockets-jets"
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ jets assets:precompile
22
+ jets assets:clean # keeps most recent 3 copies
23
+ jets assets:clobber
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ task default: :spec
5
+
6
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,22 @@
1
+ require "zeitwerk"
2
+
3
+ module Sprockets
4
+ class Autoloader
5
+ class Inflector < Zeitwerk::Inflector
6
+ def camelize(basename, _abspath)
7
+ map = { cli: "CLI", version: "VERSION" }
8
+ map[basename.to_sym] || super
9
+ end
10
+ end
11
+
12
+ class << self
13
+ def setup
14
+ loader = Zeitwerk::Loader.new
15
+ loader.inflector = Inflector.new
16
+ loader.push_dir(File.dirname(__dir__)) # lib
17
+ loader.ignore("#{File.dirname(__dir__)}/sprockets-jets.rb")
18
+ loader.setup
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,43 @@
1
+ module Sprockets::Jets
2
+ class Engine < ::Jets::Engine
3
+ config.assets = ActiveSupport::OrderedOptions.new
4
+ config.assets.paths = %w[
5
+ app/assets/config
6
+ app/assets/images
7
+ app/assets/javascripts
8
+ app/assets/stylesheets
9
+ ]
10
+ config.assets.prefix = "/assets"
11
+ config.assets.use_precompiled = false # for development false, for production true, but Jets will serve directly with s3 anyway
12
+ config.assets.precompile = []
13
+ # See: https://github.com/rails/sprockets/blob/main/UPGRADING.md#manifestjs
14
+ # In Sprockets 4, the manifest file using the manifest.js is encouraged
15
+ # And using individual files like ["application.js", "application.css"] is discouraged.
16
+
17
+ # Old jets settings. S3 serving of assets. Still need the configs.
18
+ config.assets.base_url = nil # IE: https://cloudfront.com/my/base/path
19
+ config.assets.cache_control = nil # IE: public, max-age=3600 , max_age is a shorter way to set cache_control.
20
+ config.assets.folders = %w[assets images packs files]
21
+ config.assets.max_age = 3600
22
+ config.assets.webpacker_asset_host = "s3_endpoint" # true = use conventional by default
23
+
24
+ initializer "sprockets-jets-helpers" do |app|
25
+ ActiveSupport.on_load(:action_view) do
26
+ include Helper
27
+ end
28
+ end
29
+
30
+ initializer "sprockets-jets-mount-assets" do |app|
31
+ app.routes.prepend do
32
+ # Important: Env.build within block so it's lazy loaded. Otherwise, it
33
+ # may not use the correct config.assets.paths
34
+ sprockets_env = Env.build # Sprockets::Environment.new with config.assets.paths
35
+ mount sprockets_env => Jets.config.assets.prefix, internal: true # /assets
36
+ end
37
+ end
38
+
39
+ rake_tasks do
40
+ RakeTasks.load_tasks
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ module Sprockets::Jets
2
+ class Env
3
+ class << self
4
+ extend Memoist
5
+
6
+ def build
7
+ env = Sprockets::Environment.new
8
+
9
+ # Set any config.assets values that Sprockets::Environment accepts
10
+ Jets.config.assets.each do |key, value|
11
+ setter = :"#{key}="
12
+ if env.respond_to?(setter)
13
+ env.public_send(setter, value)
14
+ end
15
+ end
16
+ # Set paths
17
+ Jets.config.assets.paths.each do |path|
18
+ env.append_path(path)
19
+ end
20
+
21
+ env
22
+ end
23
+ memoize :build
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,67 @@
1
+ module Sprockets::Jets
2
+ module Helper
3
+ extend Memoist
4
+
5
+ # Writes over the built in ActionView::Helpers::AssetUrlHelper#compute_asset_path
6
+ # to use the asset pipeline.
7
+ def compute_asset_path(path, options = {})
8
+ if config_assets.use_precompiled
9
+ # Handle precompiled assets
10
+ manifest = Manifest.build # Sprockets::Manifest
11
+ digest_path = manifest.assets[path]
12
+ else
13
+ # Handle on-the-fly assets
14
+ env = Env.build # Sprockets::Environment
15
+ asset = env.find_asset(path) # returns #<Sprockets::Asset>
16
+ env_path = env[path]
17
+ if env_path.nil?
18
+ puts "ERROR: asset not found: path=#{path.inspect} env_path=#{env_path.inspect}".color(:yellow)
19
+ assets_paths = Jets.config.assets.paths.map {|p| " #{p}" }.join("\n")
20
+ env_paths = env.paths.map {|p| " #{p}" }.join("\n")
21
+ puts <<~EOL
22
+ Are you sure it exists in one of your asset paths?
23
+ Jets.config.assets.paths:
24
+
25
+ #{assets_paths}
26
+
27
+ Sprockets env.paths
28
+
29
+ #{env_paths}
30
+ EOL
31
+ raise AssetNotFound.new(asset_not_found_message(path))
32
+ end
33
+ digest_path = env_path.digest_path
34
+ end
35
+
36
+ if digest_path
37
+ assets_prefix = config_assets.prefix # /assets
38
+ asset_path = [assets_prefix, digest_path].join("/") # /assets/application-1e8f3a4e.css
39
+ # dont call super, otherwise it will add /stylesheets to the path
40
+ # IE: /stylesheets/application.css instead of
41
+ # /assets/application-381287eca19f4d3ca6a8aa9ed68b8805d918bc26f4597e4f39e30f6259188840.css
42
+ else
43
+ raise AssetNotFound.new(asset_not_found_message(path))
44
+ end
45
+ end
46
+
47
+ def asset_not_found_message(path)
48
+ if config_assets.use_precompiled
49
+ <<~EOL
50
+ Precompiled asset not found for: #{path}
51
+ Please run:
52
+
53
+ jets assets:precompile
54
+
55
+ And restart the server
56
+ EOL
57
+ else
58
+ "Precompiled asset not found for: #{path}"
59
+ end
60
+ end
61
+
62
+ # Note: Cannot name config because it conflicts with an ActionView config method
63
+ def config_assets
64
+ Jets.config.assets
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,13 @@
1
+ module Sprockets::Jets
2
+ class Manifest
3
+ class << self
4
+ extend Memoist
5
+
6
+ def build
7
+ env = Env.build # Sprockets::Environment
8
+ Sprockets::Manifest.new(env, "./public/assets")
9
+ end
10
+ memoize :build
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,58 @@
1
+ require 'sprockets'
2
+ require 'rake/sprocketstask'
3
+
4
+ module Sprockets::Jets
5
+ class RakeTasks < Rake::SprocketsTask
6
+ def define
7
+ namespace :assets do
8
+ %w( environment precompile clean clobber ).each do |task|
9
+ Rake::Task[task].clear if Rake::Task.task_defined?(task)
10
+ end
11
+
12
+ # Override this task change the loaded dependencies
13
+ desc "Load asset compile environment"
14
+ task :environment do
15
+ # Load full Jets environment by default
16
+ Rake::Task[:environment].invoke
17
+ end
18
+
19
+ desc "Compile all the assets named in config.assets.precompile"
20
+ task precompile: :environment do
21
+ with_logger do
22
+ manifest.compile(assets)
23
+ end
24
+ end
25
+
26
+ desc "Remove old compiled assets"
27
+ task :clean, [:keep] => :environment do |t, args|
28
+ with_logger do
29
+ manifest.clean(Integer(args.keep || self.keep))
30
+ end
31
+ end
32
+
33
+ desc "Remove compiled assets"
34
+ task clobber: :environment do
35
+ with_logger do
36
+ manifest.clobber
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ class << self
43
+ def load_tasks
44
+ new do |task|
45
+ task.environment = Env.build
46
+ task.output = "public/assets"
47
+ task.assets = [ "manifest.js", "application.js" ]
48
+ task.assets += Jets.config.assets.precompile
49
+
50
+ # task.assets = ["manifest.js"] # dont have to deal with backwards compatibility since this is a new gem
51
+ # See: https://github.com/rails/sprockets/blob/main/UPGRADING.md#manifestjs
52
+ # In Sprockets 4, the manifest file using the manifest.js is encouraged
53
+ # And using individual files like ["application.js", "application.css"] is discouraged.
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Sprockets
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift(File.expand_path("../", __FILE__))
2
+
3
+ require "sprockets/autoloader"
4
+ Sprockets::Autoloader.setup
5
+
6
+ require "memoist"
7
+ require "rainbow/ext/string"
8
+ require "sprockets"
9
+ require "sprockets/jets/engine"
10
+
11
+ module Sprockets::Jets
12
+ class Error < StandardError; end
13
+ class AssetNotFound < StandardError; end
14
+ end
@@ -0,0 +1,17 @@
1
+ ENV["SPROCKETS_TEST"] = "1"
2
+
3
+ # CodeClimate test coverage: https://docs.codeclimate.com/docs/configuring-test-coverage
4
+ # require 'simplecov'
5
+ # SimpleCov.start
6
+
7
+ require "pp"
8
+ require "byebug"
9
+ root = File.expand_path("../", File.dirname(__FILE__))
10
+ require "#{root}/lib/sprockets"
11
+
12
+ module Helper
13
+ end
14
+
15
+ RSpec.configure do |c|
16
+ c.include Helper
17
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "sprockets/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sprockets-jets"
8
+ spec.version = Sprockets::VERSION
9
+ spec.authors = ["Tung Nguyen"]
10
+ spec.email = ["tongueroo@gmail.com"]
11
+ spec.summary = "Sprockets Jets Integration"
12
+ spec.homepage = "https://github.com/rubyonjets/sprockets-jets"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = File.directory?('.git') ? `git ls-files`.split($/) : Dir.glob("**/*")
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "activesupport"
20
+ spec.add_dependency "memoist"
21
+ spec.add_dependency "rainbow"
22
+ spec.add_dependency "sprockets", ">= 3.0.0"
23
+ spec.add_dependency "zeitwerk"
24
+
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "byebug"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-jets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tung Nguyen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: memoist
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sprockets
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: zeitwerk
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - tongueroo@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - CHANGELOG.md
149
+ - Gemfile
150
+ - Guardfile
151
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - lib/sprockets-jets.rb
155
+ - lib/sprockets/autoloader.rb
156
+ - lib/sprockets/jets/engine.rb
157
+ - lib/sprockets/jets/env.rb
158
+ - lib/sprockets/jets/helper.rb
159
+ - lib/sprockets/jets/manifest.rb
160
+ - lib/sprockets/jets/rake_tasks.rb
161
+ - lib/sprockets/version.rb
162
+ - spec/spec_helper.rb
163
+ - sprockets-jets.gemspec
164
+ homepage: https://github.com/rubyonjets/sprockets-jets
165
+ licenses:
166
+ - MIT
167
+ metadata: {}
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubygems_version: 3.4.20
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: Sprockets Jets Integration
187
+ test_files:
188
+ - spec/spec_helper.rb