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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0c608c4887f1a6584bec569e7ea1bd31c1baf0617a1a71e2a33d5340a9a233d
4
- data.tar.gz: 8acdec2d61b41b47644b1c66dbc99705fd615adeb03428b7d852f905e33b8f6c
3
+ metadata.gz: 2bfc5bd2d775a6b807db3e067e4fc0a7b890e4802bce439e56fabd5d24c942e3
4
+ data.tar.gz: a53ea05568bf8faf693f128a6fa338846ebf07bf8468569aa34001803641be27
5
5
  SHA512:
6
- metadata.gz: ca18e90fc4093746261daa6a02d778658d266f3ea2140f3096292f06753de7f7030548630ba38f011481a834c5849721082bacab4027ad66e490b237af4ed5da
7
- data.tar.gz: 6e8f2be51af359e08821858e03c2004277ae5a1fcd00ba9c62ad6c7f4e0b368f74422e36e556a503e260868910a402791ab3da112f392ce39b707c7e393da95b
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, _options = {})
12
- value_in_asset_manifest = ExternalAssetPipeline.manifest.find(source)
11
+ def compute_asset_path(source, options = {})
12
+ asset = ExternalAssetPipeline.manifest.find(source)
13
13
 
14
- return value_in_asset_manifest if value_in_asset_manifest
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,
@@ -10,7 +10,7 @@ module ExternalAssetPipeline
10
10
 
11
11
  def find(name)
12
12
  value = data[name.to_s]
13
- "#{@config.assets_prefix}/#{value}" if value
13
+ { path: "#{@config.assets_prefix}/#{value}" } if value
14
14
  end
15
15
 
16
16
  def fall_back_to_sprockets?
@@ -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
- Manifest.new(config.external_asset_pipeline)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ExternalAssetPipeline
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  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.1.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.1.0
58
- changelog_uri: https://github.com/rails-front-end/external_asset_pipeline/blob/v0.1.0/CHANGELOG.md
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: