asset_digest 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.standard.yml +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +10 -0
- data/lib/asset_digest/digester.rb +63 -0
- data/lib/asset_digest/manifest.rb +32 -0
- data/lib/asset_digest/source_path.rb +17 -0
- data/lib/asset_digest/version.rb +5 -0
- data/lib/asset_digest.rb +11 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2a0094856509e9189f4cbe21483f3b6bbbae80c43813b44a9601629fb44634a2
|
4
|
+
data.tar.gz: 3ae456f738a5adb3f0cfaa90629b416998bdca9867d848399f42eaebf1dede97
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4e5d12592c55edd5c3e190bb8ce31c89216fc9322b1e915e6e06b742a661d2df9d993728369c19cb104d3b2fe744550d4de31c322ca30c3c8be5dbddaa7af38
|
7
|
+
data.tar.gz: 0f924848aaa45e75bb94a1d5929cff1154d55118f62daea88eeaff31f869e5726b8bf7a2cea4900d2e2462a066d0d83ed89afa86462b1b878ae9840929c88c9f
|
data/.standard.yml
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Adam Daniels
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# AssetDigest
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/asset_digest`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/asset_digest.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "digest"
|
2
|
+
require "fileutils"
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module AssetDigest
|
6
|
+
class Digester
|
7
|
+
attr_accessor :source
|
8
|
+
attr_accessor :destination
|
9
|
+
attr_accessor :manifest
|
10
|
+
attr_accessor :manifest_path
|
11
|
+
attr_accessor :algorithm
|
12
|
+
|
13
|
+
def initialize(source:, destination:, manifest_path:, algorithm: Digest::SHA1)
|
14
|
+
@source = source
|
15
|
+
@destination = destination
|
16
|
+
@manifest_path = manifest_path
|
17
|
+
@algorithm = algorithm
|
18
|
+
@manifest = Manifest.new(source: source, destination: destination)
|
19
|
+
end
|
20
|
+
|
21
|
+
def digest_all
|
22
|
+
SourcePath.new(source).each_asset do |source_path|
|
23
|
+
destination_path = generate_destination_path(source, source_path)
|
24
|
+
ensure_folder_exists(destination_path)
|
25
|
+
manifest.add(source_path, destination_path)
|
26
|
+
place_content(source_path, destination_path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def generate_digest(source)
|
33
|
+
digest = algorithm.new
|
34
|
+
|
35
|
+
source.open("rb") do |f|
|
36
|
+
until f.eof?
|
37
|
+
digest.update(f.read(1024))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
digest.hexdigest.slice(0, 10)
|
42
|
+
end
|
43
|
+
|
44
|
+
def generate_destination_path(source, source_path)
|
45
|
+
sha = generate_digest(source_path)
|
46
|
+
ext = source_path.extname
|
47
|
+
filename = source_path.relative_path_from(source).to_s.chomp(ext)
|
48
|
+
|
49
|
+
output = "#{filename}-#{sha}#{ext}"
|
50
|
+
Pathname.new(destination).join(output)
|
51
|
+
end
|
52
|
+
|
53
|
+
def ensure_folder_exists(destination_path)
|
54
|
+
FileUtils.mkdir_p(destination_path.dirname)
|
55
|
+
end
|
56
|
+
|
57
|
+
def place_content(source_path, destination_path)
|
58
|
+
return if destination_path.exist?
|
59
|
+
|
60
|
+
FileUtils.cp(source_path, destination_path)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module AssetDigest
|
4
|
+
class Manifest
|
5
|
+
def initialize(source:, destination:)
|
6
|
+
@source = source
|
7
|
+
@destination = destination
|
8
|
+
@manifest = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def add(source_path, destination_path)
|
12
|
+
relative_source_path = source_path.relative_path_from(source)
|
13
|
+
relative_destination_path = destination_path.relative_path_from(destination)
|
14
|
+
|
15
|
+
@manifest[relative_source_path.to_s] = relative_destination_path.to_s
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_h
|
20
|
+
@manifest
|
21
|
+
end
|
22
|
+
|
23
|
+
def write(destination)
|
24
|
+
destination.write(@manifest.to_json)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_accessor :source
|
30
|
+
attr_accessor :destination
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module AssetDigest
|
4
|
+
class SourcePath
|
5
|
+
def initialize(source)
|
6
|
+
@source = Pathname.new(source)
|
7
|
+
end
|
8
|
+
|
9
|
+
def each_asset
|
10
|
+
@source.glob("**/*").each do |source|
|
11
|
+
next if source.directory?
|
12
|
+
|
13
|
+
yield source
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/asset_digest.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "asset_digest/version"
|
4
|
+
|
5
|
+
module AssetDigest
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
autoload :Digester, __dir__ + "/asset_digest/digester"
|
9
|
+
autoload :Manifest, __dir__ + "/asset_digest/manifest"
|
10
|
+
autoload :SourcePath, __dir__ + "/asset_digest/source_path"
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: asset_digest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Daniels
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- adam@mediadrive.ca
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".standard.yml"
|
21
|
+
- LICENSE.txt
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- lib/asset_digest.rb
|
25
|
+
- lib/asset_digest/digester.rb
|
26
|
+
- lib/asset_digest/manifest.rb
|
27
|
+
- lib/asset_digest/source_path.rb
|
28
|
+
- lib/asset_digest/version.rb
|
29
|
+
homepage: https://github.com/adam12/asset_digest
|
30
|
+
licenses:
|
31
|
+
- MIT
|
32
|
+
metadata:
|
33
|
+
homepage_uri: https://github.com/adam12/asset_digest
|
34
|
+
source_code_uri: https://github.com/adam12/asset_digest
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.6.0
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubygems_version: 3.5.4
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Framework-agnostic asset digesting
|
54
|
+
test_files: []
|