require 'oj' require "sinatra/asset_helpers/version" module Sinatra module AssetHelpers 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')) 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() end def javascript_tag(filename) %Q() end def image_tag(filename, alt = '', title = '') %Q(#{alt}) end end def self.registered(app) app.helpers AssetHelpers::Helpers 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