Class: Writefully::Asset
- Inherits:
-
Object
- Object
- Writefully::Asset
- Defined in:
- lib/writefully/asset.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #convert_for(content) ⇒ Object
-
#initialize(index) ⇒ Asset
constructor
A new instance of Asset.
- #names ⇒ Object
- #regex ⇒ Object
- #url(storage_endpoint) ⇒ Object
Constructor Details
#initialize(index) ⇒ Asset
Returns a new instance of Asset.
5 6 7 8 9 |
# File 'lib/writefully/asset.rb', line 5 def initialize(index) base_path = [Writefully.[:content], index[:site], index[:resource], index[:slug]] @path = File.join(base_path, 'assets') @endpoint = File.join(index[:site], index[:resource], index[:slug], 'assets') end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
3 4 5 |
# File 'lib/writefully/asset.rb', line 3 def endpoint @endpoint end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/writefully/asset.rb', line 3 def path @path end |
Instance Method Details
#convert_for(content) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/writefully/asset.rb', line 23 def convert_for content if content.is_a?(String) content.gsub(regex, url(Writefully::Storage.endpoint)) elsif content.is_a?(Hash) content.inject({}) do |h, (k, v)| h[k] = v.gsub(regex, url(Writefully::Storage.endpoint)); h end end end |
#names ⇒ Object
11 12 13 |
# File 'lib/writefully/asset.rb', line 11 def names Dir.chdir(path) { Dir.glob('*') } end |
#regex ⇒ Object
15 16 17 |
# File 'lib/writefully/asset.rb', line 15 def regex ::Regexp.new('assets\/') end |
#url(storage_endpoint) ⇒ Object
19 20 21 |
# File 'lib/writefully/asset.rb', line 19 def url storage_endpoint File.join(storage_endpoint, endpoint, '/') end |