module Sinatra::AssetPack::Helpers

Public Instance Methods

asset_filter_css(str) click to toggle source
# File lib/sinatra/assetpack/helpers.rb, line 53
def asset_filter_css(str)
  Css.preproc str, settings.assets
end
asset_path_for(file, from) click to toggle source
# File lib/sinatra/assetpack/helpers.rb, line 57
def asset_path_for(file, from)
  settings.assets.dyn_local_file_for file, from
end
assets_expires() click to toggle source
# File lib/sinatra/assetpack/helpers.rb, line 61
def assets_expires
  if settings.assets.expires.nil?
    expires 86400*30, :public
  else
    expires *settings.assets.expires
  end
end
css(*args) click to toggle source
# File lib/sinatra/assetpack/helpers.rb, line 4
def css(*args)
  show_asset_pack :css, *args
end
image_path(src) click to toggle source
# File lib/sinatra/assetpack/helpers.rb, line 19
def image_path(src)
  file_path = HtmlHelpers.get_file_uri(src, settings.assets)

  if file_path =~ /\A(http|https)\:\/\//
    file_path
  else
    File.join(request.script_name, file_path)
  end
end
img(src, options={}) click to toggle source
# File lib/sinatra/assetpack/helpers.rb, line 12
def img(src, options={})
  attrs = { :src => image_path(src) }
  attrs = attrs.merge(options)

  "<img#{HtmlHelpers.kv attrs} />"
end
js(*args) click to toggle source
# File lib/sinatra/assetpack/helpers.rb, line 8
def js(*args)
  show_asset_pack :js, *args
end
show_asset_pack(type, *args) click to toggle source
# File lib/sinatra/assetpack/helpers.rb, line 29
def show_asset_pack(type, *args)
  names = Array.new
  while args.first.is_a?(Symbol)
    names << args.shift
  end

  options = args.shift  if args.first.is_a?(Hash)

  names.map { |name|
    show_one_asset_pack type, name, (options || Hash.new)
  }.join "\n"
end
show_one_asset_pack(type, name, options={}) click to toggle source
# File lib/sinatra/assetpack/helpers.rb, line 42
def show_one_asset_pack(type, name, options={})
  pack = settings.assets.packages["#{name}.#{type}"]
  return ""  unless pack

  if settings.environment.to_sym == :production
    pack.to_production_html request.script_name, options
  else
    pack.to_development_html request.script_name, options
  end
end