lux_assets 0.2.15 → 0.2.19

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: 4a981569c1fe2a2bf9f9fb8caf7a73a5987af1e21d06f5ba9e5b29ad27f8931f
4
- data.tar.gz: 6cf4469a3657a33b722248803a46ef1e0ab224ca34db7bd45ddfcd6c60534b81
3
+ metadata.gz: 26be1a6eda380c7ac142aa001e3075dd57379f1d63e2e121fdddc074e7669a6d
4
+ data.tar.gz: c45fb60c37bfc1495c346235f2ee04d3c0d32219ebd208708bc2b271fff32b3c
5
5
  SHA512:
6
- metadata.gz: c0b1dd8f817de916961284e73021e610904a3fda24cf5286d58c2723ac7f1ab347442f5e2362971b1ae4baf296a8ef64310065b19711ba374ce8abb60d8c58dd
7
- data.tar.gz: d01039bc7edcd6f038ac6fbd4f9d98fbe9fdc73c16470edd00cd2633dedec96e4372b91da1dd3b3d9b16e350841b3d7fb2e97292f70d6f49a3e18059c8cb4f35
6
+ metadata.gz: bb6c626705f2df785dc82f515eba8468dbf5f8fce1393079e7da2b070b643d6e4ae3dfe4910b2eaa43f6d952e67ed2fad9cd81dc1ad253ed9066157627b91724
7
+ data.tar.gz: 11eaa505bbcd8eece08353e8f0b7efbcc916dc8ef0eeeed7c0d62b6bb0462d03b8b1a571e520704ebeb324f64bd183df7864d761c87612d955cb933566cb256c
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.15
1
+ 0.2.19
@@ -81,7 +81,7 @@ class LuxAssets::Asset
81
81
  def compile_js
82
82
  save_data @data.join(";\n") do
83
83
  # babel fix and minify
84
- command = 'node_modules/babel-cli/.bin/babel --minified --no-comments --compact true -o "%{file}" "%{file}"' % { file: @asset_path }
84
+ command = './node_modules/babel-cli/.bin/babel --minified --no-comments --compact true -o "%{file}" "%{file}"' % { file: @asset_path }
85
85
  LuxAssets::Cli.run command, message: "Babel filter and minify: #{@asset_path}"
86
86
  end
87
87
  end
@@ -104,6 +104,9 @@ module LuxAssets
104
104
  # touch all files and reset the timestamp
105
105
  Dir['./public/assets/*']
106
106
  .each { |file| system 'touch -t 201001010101 %s' % file }
107
+
108
+ # add integirty checks
109
+ LuxAssets::Manifest.update_integrity
107
110
  end
108
111
 
109
112
  # get all files as a hash
@@ -76,7 +76,7 @@ class LuxAssets::Element
76
76
  end
77
77
 
78
78
  def compile_ts
79
- LuxAssets::Cli.run "node_modules/typescript/.bin/tsc --outFile '#{@cache}' '#{@source}'", cache_file: @cache, message: "Compile TypeScript: #{@source}"
79
+ LuxAssets::Cli.run "./node_modules/typescript/.bin/tsc --outFile '#{@cache}' '#{@source}'", cache_file: @cache, message: "Compile TypeScript: #{@source}"
80
80
  end
81
81
 
82
82
  end
@@ -1,25 +1,37 @@
1
1
  # manifest file
2
2
 
3
3
  module LuxAssets::Manifest
4
- MANIFEST = Pathname.new(ENV.fetch('ASSETS_MANIFEST') { './public/manifest.json' })
5
- MANIFEST.write '{"files":{}}' unless MANIFEST.exist?
4
+ INTEGRITY = 'sha512'
5
+ MANIFEST = Pathname.new(ENV.fetch('ASSETS_MANIFEST') { './public/manifest.json' })
6
+ MANIFEST.write '{"files":{},"integrity":{}}' unless MANIFEST.exist?
6
7
 
7
8
  extend self
8
9
 
9
10
  def add name, path
10
- json = JSON.load MANIFEST.read
11
-
12
11
  unless json['files'][name] == path
13
- json['files'][name] = path
14
- MANIFEST.write JSON.pretty_generate(json)
12
+ json['files'][name] = path
13
+ write
15
14
  end
16
15
 
17
16
  !File.exist?('./public'+path)
18
17
  end
19
18
 
20
- def get name
21
- json = JSON.load MANIFEST.read
22
- json['files'][name]
19
+ def update_integrity
20
+ for name, path in json['files']
21
+ json['integrity'][name] = '%s-%s' % [INTEGRITY, `openssl dgst -#{INTEGRITY} -binary ./public#{path} | openssl base64 -A`.chomp]
22
+ end
23
+
24
+ write
25
+ end
26
+
27
+ private
28
+
29
+ def json
30
+ @json ||= JSON.load MANIFEST.read
31
+ end
32
+
33
+ def write
34
+ MANIFEST.write JSON.pretty_generate(@json)
23
35
  end
24
36
  end
25
37
 
@@ -5,16 +5,25 @@ module HtmlHelper
5
5
  def asset_include path, opts={}
6
6
  raise ArgumentError.new("Asset path can't be empty") if path.empty?
7
7
 
8
- ext = path.split('?').first.split('.').last
9
- type = ['css', 'sass', 'scss'].include?(ext) ? :style : :script
10
- type = :style if path.include?('fonts.googleapis.com')
8
+ ext = path.split('?').first.split('.').last
9
+ type = ['css', 'sass', 'scss'].include?(ext) ? :style : :script
10
+ type = :style if path.include?('fonts.googleapis.com')
11
11
 
12
12
  current.response.early_hints path, type
13
13
 
14
+ data = {}
15
+
16
+ data[:crossorigin] = opts[:crossorigin] || :anonymous
17
+ data[:integrity] = opts[:integrity] if opts[:integrity]
18
+
14
19
  if type == :style
15
- %[<link rel="stylesheet" href="#{path}" />]
20
+ data[:media] = opts[:media] || :all
21
+ data[:rel] = :stylesheet
22
+ data[:href] = path
23
+ data.tag :link
16
24
  else
17
- %[<script src="#{path}"></script>]
25
+ data[:src] = path
26
+ data.tag :script
18
27
  end
19
28
  end
20
29
 
@@ -55,6 +64,7 @@ module HtmlHelper
55
64
 
56
65
  nil
57
66
  else
67
+ opts[:integrity] = manifest['integrity'][file]
58
68
  return asset_include(Lux.config.assets_root.to_s + mfile, opts)
59
69
  end
60
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lux_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.15
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-12 00:00:00.000000000 Z
11
+ date: 2019-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize