Sha256: 5842862670a4f72d1586bb99d7ab01ff0eec7d080d2942330b753c11fa882eeb

Contents?: true

Size: 947 Bytes

Versions: 5

Compression:

Stored size: 947 Bytes

Contents

# /compiled_asset/www/js/pjax.coffee
# /raw_asset/www/js/pjax.coffee
Lux.app.before do
  # skip /favicon.ico that forces refresh
  next unless nav.path[1]
  next unless Lux.config(:compile_assets)

  # only allow clear in dev
  # clear assets every 4 seconds max
  if Lux.current.no_cache?
    Lux.cache.fetch('lux-clear-assets', ttl: 4, log: false, force: false) do
      puts '* Clearing assets from ./tmp/assets'.yellow
      `rm -rf ./tmp/assets && mkdir ./tmp/assets`
      true
    end
  end

  case nav.root
  when 'compiled_asset'
    path = nav.reset.drop(1).join('/')

    asset = LuxAssets::Element.new path
    current.response.content_type asset.content_type
    current.response.body asset.compile

  when 'raw_asset'
    path = nav.reset.drop(1).join('/')

    Lux.error "You can watch raw files only in development" unless Lux.dev?

    file = Pathname.new path
    body file.exist? ? file.read : "error: File not found"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lux_assets-0.2.2 ./lib/vendor/lux/assets_routes.rb
lux_assets-0.2.1 ./lib/vendor/lux/assets_routes.rb
lux_assets-0.1.10 ./lib/vendor/lux/assets_routes.rb
lux_assets-0.1.9 ./lib/vendor/lux/assets_routes.rb
lux_assets-0.1.4 ./lib/vendor/lux/assets_routes.rb