bankrupt 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13362fcd14a5a3f976a5de6a3055f7f6b7d208e4fdb2e5dffae4e9b41ff13b90
4
- data.tar.gz: 9316fbd60714bdf91517690def44d1ded019fd16b44a1359343931bf42bf4eca
3
+ metadata.gz: 4b25ac977ea77fe68e18e583a9d6bab35e234c99684a07b49afd9d74e58292d7
4
+ data.tar.gz: ec15d4467fc340e988992495526dd6f006964d4a8359928bd894598b41913c9b
5
5
  SHA512:
6
- metadata.gz: be6cb9347bcd9b34994dfe32922428eeb2aab18c65848f1466de412f6c381443ddacf4ab6c7fe5fe579446adfd8aedbf440a4afe113100781cd083bf43fd07f8
7
- data.tar.gz: 78cd04a3fa41eef143431ac56a860a94d70757fe125e9b844f48d7599abdbd79abe10f56234fb2fc17832eaec6bb56320256e0cb0cde2d22090359fe9e3bf2cf
6
+ metadata.gz: b2ab7eaaf4e1d6fb2fc51d885ad3858ee6a432eb784f908fd9bc90c832ffe2fc48a1af0b628354edf4953aea0c34765797e73f56e67d5325b96f903ec51a34d9
7
+ data.tar.gz: 9c18b7c507883b9f3ce121339f6b951f51ddfaf32f7b24ef014fbe03ac5a242fdfb3a6e560ce0f8748ee43824bbfa69f753556e330d3fadc7d9654eed8c1bcfd
@@ -8,7 +8,7 @@ Layout/ExtraSpacing:
8
8
  AllowForAlignment: false
9
9
 
10
10
  Metrics/BlockLength:
11
- Max: 80
11
+ Max: 100
12
12
  Exclude:
13
13
  - 'spec/**/*_spec.rb'
14
14
 
@@ -6,6 +6,7 @@ rvm:
6
6
  - 2.4
7
7
  - 2.5
8
8
  - 2.6
9
+ - 2.7
9
10
 
10
11
  before_install:
11
12
  - gem update --system
@@ -3,6 +3,15 @@
3
3
  This file keeps track of changes between releases for the bankrupt project
4
4
  which adheres to [semantic versioning](https://semver.org).
5
5
 
6
+ ## v2.1.0 2020-01-06
7
+
8
+ Add support for unversioned ("hashless") assets.
9
+
10
+ * Add new configuration file and `hashless` option (file glob array) to upload
11
+ files to the CDN without their md5 hash appended.
12
+ * Add new `raw` helper to just return the full URL of an asset.
13
+ * Add upload support for PDF files.
14
+
6
15
  ## v2.0.1 2019-07-30
7
16
 
8
17
  Add support for uploading font files (`eot`, `ttf`, `woff`, and `woff2`) to
data/README.md CHANGED
@@ -62,7 +62,14 @@ For images you can optionally pass a hash of options to apply additional
62
62
  attributes to the image:
63
63
 
64
64
  ```slim
65
- == image(img.jpg, alt: 'img')
65
+ == image('img.jpg', alt: 'img')
66
+ ```
67
+
68
+ To get the full path of an asset:
69
+
70
+ ```slim
71
+ a href=raw('file.pdf')
72
+ | Click me!
66
73
  ```
67
74
 
68
75
  ### Rake
@@ -107,6 +114,17 @@ task default: if ENV['CLOUDBUILD'].to_s.casecmp?('true')
107
114
  end
108
115
  ```
109
116
 
117
+ Note that it's possible to upload some files to the CDN _without_ their hash
118
+ appended. Create a `.bankrupt.yml` file in the root of your project and provide
119
+ an array of file globs to store "hashless":
120
+
121
+ ```yaml
122
+ ---
123
+ hashless:
124
+ - "*.pdf"
125
+ - "image.png"
126
+ ```
127
+
110
128
  ### Rspec
111
129
 
112
130
  If you're testing your app with rspec or similar you need to stub the `CDN` and
@@ -138,7 +156,7 @@ end
138
156
  ## License
139
157
 
140
158
  ```
141
- Copyright 2018 Mario Finelli
159
+ Copyright 2018-2020 Mario Finelli
142
160
 
143
161
  Licensed under the Apache License, Version 2.0 (the "License");
144
162
  you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2018-2019 Mario Finelli
3
+ # Copyright 2018-2020 Mario Finelli
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -79,6 +79,17 @@ module Bankrupt
79
79
  asset_html(path, STYLESHEET_CDN, STYLESHEET_LOCAL)
80
80
  end
81
81
 
82
+ # Get the full path to the asset for use in e.g. a tags.
83
+ #
84
+ # @param path [String] relative (from public) path to the asset
85
+ # @return [String] full path to the asset
86
+ def raw(path)
87
+ details = ASSETS.fetch(path)
88
+ create_fullpath(path, details[:md5], details[:hashless])
89
+ rescue KeyError
90
+ "/#{path}"
91
+ end
92
+
82
93
  private
83
94
 
84
95
  # Return a precomputed asset path if it exists
@@ -95,19 +106,25 @@ module Bankrupt
95
106
  #
96
107
  # @param file [String] basename of the asset
97
108
  # @param digest [String] md5 hash of the asset
98
- # @return [String] filename with digest e.g, style-123.css
99
- def append_md5(file, digest)
109
+ # @param hashless [Boolean] if the file doesn't have the hash appended
110
+ # @return [String] filename with digest e.g, style-123.css (style.css if
111
+ # hashless)
112
+ def append_md5(file, digest, hashless = false)
113
+ return file if hashless
114
+
100
115
  [[file.split(ex = File.extname(file)).first, digest].join('-'), ex].join
101
116
  end
102
117
 
103
118
  # Generates the full path to the asset including CDN domain, if set.
104
119
  #
105
120
  # @param path [String] local path to the asset
121
+ # @param md5 [String] md5 hash of the asset
122
+ # @param hashless [Boolean] if the files doesn't have the hash appended
106
123
  # @return [String] new, full path to the asset
107
- def create_fullpath(path, md5)
124
+ def create_fullpath(path, md5, hashless = false)
108
125
  return "/#{path}" if CDN.empty?
109
126
 
110
- [CDN, append_md5(path, md5)].join('/')
127
+ [CDN, append_md5(path, md5, hashless)].join('/')
111
128
  end
112
129
 
113
130
  # Generate the asset HTML. If the asset exists in the lookup hash then
@@ -125,7 +142,7 @@ module Bankrupt
125
142
  begin
126
143
  details = ASSETS.fetch(path)
127
144
 
128
- fullpath = create_fullpath(path, details[:md5])
145
+ fullpath = create_fullpath(path, details[:md5], details[:hashless])
129
146
 
130
147
  @_assets["/#{path}"] = Slim::Template.new { cdn }.render(
131
148
  ASSET.new(fullpath, details[:sri])
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2018-2019 Mario Finelli
3
+ # Copyright 2018-2020 Mario Finelli
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ require 'fileutils'
21
21
  require 'json'
22
22
  require 'mini_mime'
23
23
  require 'rake'
24
+ require 'yaml'
24
25
 
25
26
  namespace :bankrupt do
26
27
  desc 'Upload files specified in the manifest to s3/cloudfront'
@@ -31,12 +32,16 @@ namespace :bankrupt do
31
32
  symbolize_names: true).each do |_key, asset|
32
33
  r = s3.put_object(
33
34
  bucket: CDN_BUCKET,
34
- key: File.join(CDN_PREFIX,
35
- [[
36
- asset[:filename].split(
37
- ex = File.extname(asset[:filename])
38
- ).first, asset[:md5]
39
- ].join('-'), ex].join),
35
+ key: if asset[:hashless]
36
+ File.join(CDN_PREFIX, asset[:filename])
37
+ else
38
+ File.join(CDN_PREFIX,
39
+ [[
40
+ asset[:filename].split(
41
+ ex = File.extname(asset[:filename])
42
+ ).first, asset[:md5]
43
+ ].join('-'), ex].join)
44
+ end,
40
45
  body: File.read(f = File.join(APP_ROOT, 'public', asset[:filename])),
41
46
  acl: 'private',
42
47
  # content_md5: Base64.strict_encode64(asset[:md5]),
@@ -90,9 +95,16 @@ namespace :bankrupt do
90
95
  desc 'Generate an asset manifest file with sums and hashes'
91
96
  task :manifest do
92
97
  manifest = {}
93
- file_glob = '*.{css,jpg,js,png,svg,eot,ttf,woff,woff2}'
98
+ file_glob = '*.{css,jpg,js,pdf,png,svg,eot,ttf,woff,woff2}'
94
99
 
95
- Dir.glob(File.join(APP_ROOT, 'public', file_glob)) do |file|
100
+ config = begin
101
+ YAML.safe_load(File.read(File.join(APP_ROOT, '.bankrupt.yml')),
102
+ [], [], true, symbolize_names: true)
103
+ rescue Errno::ENOENT
104
+ {}
105
+ end
106
+
107
+ Dir.glob(File.join(APP_ROOT, 'public', file_glob)).sort.each do |file|
96
108
  md5 = Digest::MD5.file(file).to_s
97
109
  basename = File.basename(file)
98
110
 
@@ -112,6 +124,16 @@ namespace :bankrupt do
112
124
  babble: Digest::MD5.file(file).bubblebabble,
113
125
  sri: 'sha384-' + Digest::SHA384.file(file).base64digest.to_s
114
126
  }
127
+
128
+ Array(config[:hashless]).each do |match|
129
+ # skip unless the file is in a "hashless" glob
130
+ next unless Dir.glob(File.join(APP_ROOT, 'public', match)).map do |f|
131
+ File.basename(f)
132
+ end.include?(basename)
133
+
134
+ manifest[basename][:hashless] = true
135
+ break
136
+ end
115
137
  end
116
138
 
117
139
  LOG.info "Generated asset manifest with #{manifest.keys.size} entries"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2018-2019 Mario Finelli
3
+ # Copyright 2018-2020 Mario Finelli
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,5 +15,5 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module Bankrupt
18
- VERSION = '2.0.1'
18
+ VERSION = '2.1.0'
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bankrupt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Finelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-30 00:00:00.000000000 Z
11
+ date: 2020-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slim