class Writefully::Asset

Attributes

endpoint[R]
path[R]

Public Class Methods

new(index) click to toggle source
# File lib/writefully/asset.rb, line 5
def initialize(index)
  base_path = [Writefully.options[:content], index[:site], index[:resource], index[:slug]]
  @path = File.join(base_path, 'assets')
  @endpoint = File.join(index[:site], index[:resource], index[:slug], 'assets')
end

Public Instance Methods

convert_for(content) click to toggle source
# 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() click to toggle source
# File lib/writefully/asset.rb, line 11
def names
  Dir.chdir(path) { Dir.glob('*') }
end
regex() click to toggle source
# File lib/writefully/asset.rb, line 15
def regex
  ::Regexp.new('assets\/')
end
url(storage_endpoint) click to toggle source
# File lib/writefully/asset.rb, line 19
def url storage_endpoint
  File.join(storage_endpoint, endpoint, '/')
end