Class: CabezaDeTermo::AssetsPublisher::Asset
- Inherits:
-
Object
- Object
- CabezaDeTermo::AssetsPublisher::Asset
- Defined in:
- lib/cabeza-de-termo/assets-publisher/assets/asset.rb
Overview
An assets to be included in a template.
Class Method Summary collapse
-
.on_uri(asset_type, asset_uri) ⇒ Object
Answer a new asset on the asset_uri.
Instance Method Summary collapse
-
#html ⇒ Object
Answer the html to include this asset in a template.
-
#initialize(asset_type, asset_uri, location) ⇒ Asset
constructor
Initialize the instance.
-
#location ⇒ Object
Answer the location of the asset.
- #modification_time ⇒ Object
-
#real_path ⇒ Object
Answer the file path of the asset uri.
- #set_uri_parameters(string) ⇒ Object
-
#type ⇒ Object
Answer the asset type.
-
#uri ⇒ Object
Answer the asset uri.
- #uri_parameters ⇒ Object
-
#uri_with_parameters ⇒ Object
Answer the asset uri with optional parameters.
- #validate_real_path ⇒ Object
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
#html ⇒ Object
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 |
#location ⇒ Object
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_time ⇒ Object
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_path ⇒ Object
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 |
#type ⇒ Object
Answer the asset type
37 38 39 |
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 37 def type() @type end |
#uri ⇒ Object
Answer the asset uri.
25 26 27 |
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 25 def uri() @uri end |
#uri_parameters ⇒ Object
51 52 53 |
# File 'lib/cabeza-de-termo/assets-publisher/assets/asset.rb', line 51 def uri_parameters() @uri_parameters end |
#uri_with_parameters ⇒ Object
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_path ⇒ Object
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 |