Class: Locomotive::Liquid::AssetHost

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/liquid/asset_host.rb

Constant Summary collapse

IsHTTP =
/^https?\/\//o

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, site, host) ⇒ AssetHost

Returns a new instance of AssetHost.



10
11
12
13
14
# File 'lib/locomotive/liquid/asset_host.rb', line 10

def initialize(request, site, host)
  @request, @site = request, site

  @host = build_host(host, request, site)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/locomotive/liquid/asset_host.rb', line 8

def host
  @host
end

#requestObject (readonly)

Returns the value of attribute request.



8
9
10
# File 'lib/locomotive/liquid/asset_host.rb', line 8

def request
  @request
end

#siteObject (readonly)

Returns the value of attribute site.



8
9
10
# File 'lib/locomotive/liquid/asset_host.rb', line 8

def site
  @site
end

Instance Method Details

#compute(source, timestamp = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/locomotive/liquid/asset_host.rb', line 16

def compute(source, timestamp = nil)
  return source if source.nil?

  return add_timestamp_suffix(source, timestamp) if source =~ IsHTTP

  url = self.host ? URI.join(host, source).to_s : source

  add_timestamp_suffix(url, timestamp)
end