lib/sinatra/asset_helpers.rb in sinatra-asset_helpers-0.0.1 vs lib/sinatra/asset_helpers.rb in sinatra-asset_helpers-0.0.2
- old
+ new
@@ -6,14 +6,16 @@
module Helpers
def asset_url_for(filename)
return filename if filename =~ /^http|https|\//
halt 500, "Invalid path (#{settings.manifest_path}) to manifest.json" unless File.exists? settings.manifest_path
+ filepath = filename.split('/')
+ filename = filepath.pop
manifest = Oj.load(File.open(settings.manifest_path, 'r'))
- file = manifest[filename]
-
- "#{settings.assets_host}/#{settings.assets_path}/#{file}"
+ asset_url = [(settings.assets_host || ''), settings.assets_path, filepath, manifest[filename]].flatten.join('/')
+ puts asset_url
+ asset_url
end
def stylesheet_tag(filename, media = 'screen')
%Q(<link href="#{asset_url_for(filename)}" media="#{media}" rel="stylesheet">)
end
@@ -27,11 +29,11 @@
end
end
def self.registered(app)
app.helpers AssetHelpers::Helpers
- app.set :assets_path, 'assets'
app.set :assets_host, ENV['ASSETS_HOST']
+ app.set :assets_path, 'assets'
app.set :manifest_path, File.join(app.settings.root, 'public/assets/manifest.json')
end
end
end