Class: CabezaDeTermo::AssetsPublisher::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/cabeza-de-termo/assets-publisher/assets/asset.rb

Overview

An assets to be included in a template.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(asset_type, asset_uri, location) ⇒ Asset

Initialize the instance.



16
17
18
19
20
21
22
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 16

def initialize(asset_type, asset_uri, location)
  @uri = Pathname.new(asset_uri)
  @type = asset_type
  @location = location
  @real_path = nil
  @uri_parameters = nil
end

Class Method Details

.on_uri(asset_type, asset_uri) ⇒ Object

Answer a new asset on the asset_uri.



11
12
13
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 11

def self.on_uri(asset_type, asset_uri)
  new(asset_type, asset_uri, Location.from(asset_uri))
end

Instance Method Details

#htmlObject

Answer the html to include this asset in a template



61
62
63
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 61

def html()
  type.html_for uri_with_parameters
end

#locationObject

Answer the location of the asset



42
43
44
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 42

def location()
  @location
end

#modification_timeObject



69
70
71
72
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 69

def modification_time()
  return :not_found unless real_path.exist?
  real_path.mtime
end

#real_pathObject

Answer the file path of the asset uri.



47
48
49
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 47

def real_path()
  @real_path ||= location.real_path_of(uri)
end

#set_uri_parameters(string) ⇒ Object



55
56
57
58
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 55

def set_uri_parameters(string)
  @uri_parameters = string
  self
end

#typeObject

Answer the asset type



37
38
39
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 37

def type()
  @type
end

#uriObject

Answer the asset uri.



25
26
27
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 25

def uri()
  @uri
end

#uri_parametersObject



51
52
53
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 51

def uri_parameters()
  @uri_parameters
end

#uri_with_parametersObject

Answer the asset uri with optional parameters



30
31
32
33
34
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 30

def uri_with_parameters()
  return uri.to_s if uri_parameters.nil?

  uri.to_s + '?' + URI.escape(uri_parameters)
end

#validate_real_pathObject



65
66
67
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 65

def validate_real_path()
  raise_asset_not_found_error unless real_path.exist?
end