external_asset_pipeline 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/external_asset_pipeline/configuration.rb +17 -0
- data/lib/external_asset_pipeline/dev_server.rb +30 -0
- data/lib/external_asset_pipeline/helper.rb +5 -3
- data/lib/external_asset_pipeline/manifest.rb +1 -1
- data/lib/external_asset_pipeline/priority_manifest.rb +19 -0
- data/lib/external_asset_pipeline/railtie.rb +14 -1
- data/lib/external_asset_pipeline/server_manifest.rb +38 -0
- data/lib/external_asset_pipeline/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bfc5bd2d775a6b807db3e067e4fc0a7b890e4802bce439e56fabd5d24c942e3
|
4
|
+
data.tar.gz: a53ea05568bf8faf693f128a6fa338846ebf07bf8468569aa34001803641be27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aae3b7e92d47fe1f9a5b46ad3896c281e85a44222a010a4ddfc051272a23156b38d30625f2daf1eb50e65c467f9c6a9c108b5d5b86ed01c5b419a645d4444a8a
|
7
|
+
data.tar.gz: 9c9a0cb5c1c9f08c7fa3383d1dd947bc08bcc64a100eabe993588b54562554cc2b506ea0601616f2ff058cdbe63868594eb721a3043874955a906d556bd2224c
|
@@ -1,20 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'logger'
|
4
|
+
|
3
5
|
module ExternalAssetPipeline
|
4
6
|
class Configuration
|
5
7
|
attr_accessor :assets_prefix,
|
6
8
|
:cache_manifest,
|
9
|
+
:dev_server,
|
7
10
|
:fall_back_to_sprockets,
|
11
|
+
:logger,
|
8
12
|
:manifest_filename,
|
9
13
|
:public_path
|
10
14
|
|
11
15
|
alias cache_manifest? cache_manifest
|
12
16
|
alias fall_back_to_sprockets? fall_back_to_sprockets
|
13
17
|
|
18
|
+
class DevServerSettings
|
19
|
+
attr_accessor :connect_timeout,
|
20
|
+
:enabled,
|
21
|
+
:host,
|
22
|
+
:port
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@connect_timeout = 0.01
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
14
29
|
def initialize
|
15
30
|
@assets_prefix = '/packs'
|
16
31
|
@cache_manifest = true
|
32
|
+
@dev_server = DevServerSettings.new
|
17
33
|
@fall_back_to_sprockets = false
|
34
|
+
@logger = Logger.new(STDOUT)
|
18
35
|
@manifest_filename = 'manifest.json'
|
19
36
|
end
|
20
37
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module ExternalAssetPipeline
|
6
|
+
class DevServer
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(path)
|
12
|
+
Net::HTTP.new(@config.host, @config.port).get(path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def origin
|
16
|
+
"http://#{@config.host}:#{@config.port}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def running?
|
20
|
+
Socket.tcp(
|
21
|
+
@config.host,
|
22
|
+
@config.port,
|
23
|
+
connect_timeout: @config.connect_timeout
|
24
|
+
).close
|
25
|
+
true
|
26
|
+
rescue StandardError
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -8,10 +8,12 @@ module ExternalAssetPipeline
|
|
8
8
|
# `ActionView::Helpers::AssetUrlHelper#compute_asset_path` to use the
|
9
9
|
# external asset pipeline, in the same manner that sprockets-rails does:
|
10
10
|
# https://github.com/rails/sprockets-rails/blob/v3.2.1/lib/sprockets/rails/helper.rb#L74-L96
|
11
|
-
def compute_asset_path(source,
|
12
|
-
|
11
|
+
def compute_asset_path(source, options = {})
|
12
|
+
asset = ExternalAssetPipeline.manifest.find(source)
|
13
13
|
|
14
|
-
|
14
|
+
options[:host] = asset[:host] if asset && asset[:host]
|
15
|
+
|
16
|
+
return asset[:path] if asset
|
15
17
|
return super if ExternalAssetPipeline.manifest.fall_back_to_sprockets?
|
16
18
|
|
17
19
|
raise AssetNotFound,
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module ExternalAssetPipeline
|
6
|
+
class PriorityManifest
|
7
|
+
def initialize(*manifests)
|
8
|
+
@manifests = manifests
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(name)
|
12
|
+
@manifests.lazy.map { |manifest| manifest.find name }.find(&:itself)
|
13
|
+
end
|
14
|
+
|
15
|
+
def fall_back_to_sprockets?
|
16
|
+
@manifests.any?(&:fall_back_to_sprockets?)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -4,8 +4,11 @@ require 'rails/railtie'
|
|
4
4
|
|
5
5
|
require 'external_asset_pipeline'
|
6
6
|
require 'external_asset_pipeline/configuration'
|
7
|
+
require 'external_asset_pipeline/dev_server'
|
7
8
|
require 'external_asset_pipeline/helper'
|
8
9
|
require 'external_asset_pipeline/manifest'
|
10
|
+
require 'external_asset_pipeline/priority_manifest'
|
11
|
+
require 'external_asset_pipeline/server_manifest'
|
9
12
|
|
10
13
|
module ExternalAssetPipeline
|
11
14
|
class Railtie < ::Rails::Railtie
|
@@ -17,7 +20,17 @@ module ExternalAssetPipeline
|
|
17
20
|
|
18
21
|
config.after_initialize do
|
19
22
|
ExternalAssetPipeline.manifest =
|
20
|
-
|
23
|
+
if config.external_asset_pipeline.dev_server.enabled
|
24
|
+
PriorityManifest.new(
|
25
|
+
ServerManifest.new(
|
26
|
+
config: config.external_asset_pipeline,
|
27
|
+
server: DevServer.new(config.external_asset_pipeline.dev_server)
|
28
|
+
),
|
29
|
+
Manifest.new(config.external_asset_pipeline)
|
30
|
+
)
|
31
|
+
else
|
32
|
+
Manifest.new(config.external_asset_pipeline)
|
33
|
+
end
|
21
34
|
|
22
35
|
ActiveSupport.on_load(:action_view) do
|
23
36
|
include ExternalAssetPipeline::Helper
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require 'external_asset_pipeline/manifest'
|
6
|
+
|
7
|
+
module ExternalAssetPipeline
|
8
|
+
class ServerManifest < Manifest
|
9
|
+
def initialize(config:, server:)
|
10
|
+
@server = server
|
11
|
+
super(config)
|
12
|
+
end
|
13
|
+
|
14
|
+
def find(name)
|
15
|
+
value = super
|
16
|
+
value&.merge(host: @server.origin)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def data
|
22
|
+
load
|
23
|
+
end
|
24
|
+
|
25
|
+
def load
|
26
|
+
if @server.running?
|
27
|
+
manifest_path = "#{@config.assets_prefix}/#{@config.manifest_filename}"
|
28
|
+
response = @server.get(manifest_path)
|
29
|
+
JSON.parse response.body
|
30
|
+
else
|
31
|
+
warning =
|
32
|
+
"#{@server.class} is not running; returning empty ServerManifest"
|
33
|
+
@config.logger.warn warning
|
34
|
+
{}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: external_asset_pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Macklin
|
@@ -44,18 +44,21 @@ extra_rdoc_files: []
|
|
44
44
|
files:
|
45
45
|
- lib/external_asset_pipeline.rb
|
46
46
|
- lib/external_asset_pipeline/configuration.rb
|
47
|
+
- lib/external_asset_pipeline/dev_server.rb
|
47
48
|
- lib/external_asset_pipeline/helper.rb
|
48
49
|
- lib/external_asset_pipeline/manifest.rb
|
49
50
|
- lib/external_asset_pipeline/origin.rb
|
51
|
+
- lib/external_asset_pipeline/priority_manifest.rb
|
50
52
|
- lib/external_asset_pipeline/railtie.rb
|
53
|
+
- lib/external_asset_pipeline/server_manifest.rb
|
51
54
|
- lib/external_asset_pipeline/version.rb
|
52
55
|
homepage: https://github.com/rails-front-end/external_asset_pipeline
|
53
56
|
licenses:
|
54
57
|
- MIT
|
55
58
|
metadata:
|
56
59
|
homepage_uri: https://github.com/rails-front-end/external_asset_pipeline
|
57
|
-
source_code_uri: https://github.com/rails-front-end/external_asset_pipeline/tree/v0.
|
58
|
-
changelog_uri: https://github.com/rails-front-end/external_asset_pipeline/blob/v0.
|
60
|
+
source_code_uri: https://github.com/rails-front-end/external_asset_pipeline/tree/v0.2.0
|
61
|
+
changelog_uri: https://github.com/rails-front-end/external_asset_pipeline/blob/v0.2.0/CHANGELOG.md
|
59
62
|
post_install_message:
|
60
63
|
rdoc_options: []
|
61
64
|
require_paths:
|