Module: Sinatra::AssetPack::Helpers

Defined in:
lib/sinatra/assetpack/helpers.rb

Instance Method Summary collapse

Instance Method Details

#asset_filter_css(str) ⇒ Object



52
53
54
# File 'lib/sinatra/assetpack/helpers.rb', line 52

def asset_filter_css(str)
  Css.preproc str, settings.assets
end

#asset_path_for(file, from) ⇒ Object



56
57
58
# File 'lib/sinatra/assetpack/helpers.rb', line 56

def asset_path_for(file, from)
  settings.assets.dyn_local_file_for file, from
end

#css(*args) ⇒ Object



4
5
6
# File 'lib/sinatra/assetpack/helpers.rb', line 4

def css(*args)
  show_asset_pack :css, *args
end

#img(src, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sinatra/assetpack/helpers.rb', line 12

def img(src, options={})
  attrs = { :src => src }.merge(options)

  local = settings.assets.local_file_for src
  if local
    i = Image[local]
    attrs[:src] = BusterHelpers.add_cache_buster(src, local)
    if i.dimensions?
      attrs[:width]  ||= i.width
      attrs[:height] ||= i.height
    end
  end

  "<img#{HtmlHelpers.kv attrs} />"
end

#js(*args) ⇒ Object



8
9
10
# File 'lib/sinatra/assetpack/helpers.rb', line 8

def js(*args)
  show_asset_pack :js, *args
end

#show_asset_pack(type, *args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sinatra/assetpack/helpers.rb', line 28

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 = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/sinatra/assetpack/helpers.rb', line 41

def show_one_asset_pack(type, name, options={})
  pack = settings.assets.packages["#{name}.#{type}"]
  return ""  unless pack

  if (settings.respond_to? 'compressed_env') ? settings.compressed_env : settings.production?
    pack.to_production_html options
  else
    pack.to_development_html options
  end
end