module Mumukit::Server::WithAssets

Public Instance Methods

get_asset(route, absolute_path, type=nil) click to toggle source
# File lib/mumukit/server/with_assets.rb, line 17
def get_asset(route, absolute_path, type=nil)
  type ||= infer_asset_type_from(route)
  get "/assets/#{route}" do
    cross_origin
    send_file absolute_path, type: type
  end
end
get_local_asset(route, path, type=nil) click to toggle source
# File lib/mumukit/server/with_assets.rb, line 30
def get_local_asset(route, path, type=nil)
  get_asset route, File.join(local_asset_dir, '..', path), type
end
infer_asset_type_from(route) click to toggle source
# File lib/mumukit/server/with_assets.rb, line 25
def infer_asset_type_from(route)
  extension = File.extname(route)
  MIME::Types.type_for(extension).first.content_type
end
local_asset_dir() click to toggle source
# File lib/mumukit/server/with_assets.rb, line 34
def local_asset_dir
  @local_asset_dir ||= File.dirname caller[1].split(':')[0]
  # Had to use caller[1] because the first entry of the stack is from this file
end