Module: Sinatra::AssetPack::Helpers
- Defined in:
- lib/sinatra/assetpack/helpers.rb
Instance Method Summary collapse
- #asset_filter_css(str) ⇒ Object
- #asset_path_for(file, from) ⇒ Object
- #assets_expires ⇒ Object
- #css(*args) ⇒ Object
- #img(src, options = {}) ⇒ Object
- #js(*args) ⇒ Object
- #show_asset_pack(type, *args) ⇒ Object
- #show_one_asset_pack(type, name, options = {}) ⇒ Object
Instance Method Details
#asset_filter_css(str) ⇒ Object
54 55 56 |
# File 'lib/sinatra/assetpack/helpers.rb', line 54 def asset_filter_css(str) Css.preproc str, settings.assets end |
#asset_path_for(file, from) ⇒ Object
58 59 60 |
# File 'lib/sinatra/assetpack/helpers.rb', line 58 def asset_path_for(file, from) settings.assets.dyn_local_file_for file, from end |
#assets_expires ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/sinatra/assetpack/helpers.rb', line 62 def assets_expires if settings.assets.expires.nil? expires 86400*30, :public else expires *settings.assets.expires end 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 27 28 |
# File 'lib/sinatra/assetpack/helpers.rb', line 12 def img(src, ={}) attrs = { :src => src }.merge() local = settings.assets.local_file_for src if local i = Image[local] attrs[:src] = HtmlHelpers.get_file_uri(src, settings.assets) 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
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sinatra/assetpack/helpers.rb', line 30 def show_asset_pack(type, *args) names = Array.new while args.first.is_a?(Symbol) names << args.shift end = args.shift if args.first.is_a?(Hash) names.map { |name| show_one_asset_pack type, name, ( || Hash.new) }.join "\n" end |
#show_one_asset_pack(type, name, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sinatra/assetpack/helpers.rb', line 43 def show_one_asset_pack(type, name, ={}) pack = settings.assets.packages["#{name}.#{type}"] return "" unless pack if settings.environment == :production || settings.environment == :stage pack.to_production_html else pack.to_development_html end end |