Sha256: abcdf93900e8168b649d4f62d567bfa0ad408181386181f5ff2aaea0744b2c1e

Contents?: true

Size: 1.36 KB

Versions: 7

Compression:

Stored size: 1.36 KB

Contents

# /compiled_asset/www/js/pjax.coffee
# /raw_asset/www/js/pjax.coffee
Lux.app.before do
  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

  _, root, asset_path = Lux.current.request.path.split('/', 3)

  case root
  when 'compiled_asset'
    asset = LuxAssets::Element.new asset_path
    current.response.content_type asset.content_type
    current.response.body asset.compile

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

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

# additional info for "lux config" cli
Lux.app.info do
  puts
  puts 'assets:'
  for ext in LuxAssets.to_h.keys
    for key, value in LuxAssets.to_h[ext]
      name = '  LuxAsset.%s(:%s)' % [ext, key]
      print name.ljust(35)
      puts ' - %s' % value.length.pluralize(:file)
    end
  end
end

# include files from a plugin
module LuxAssets
  def plugin name
    # load pluigin if needed
    Lux.plugin name

    plugin = Lux.plugin.get name
    add '%s/**' % plugin[:folder]
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lux_assets-0.2.24 ./lib/vendor/lux/misc.rb
lux_assets-0.2.23 ./lib/vendor/lux/misc.rb
lux_assets-0.2.21 ./lib/vendor/lux/misc.rb
lux_assets-0.2.20 ./lib/vendor/lux/misc.rb
lux_assets-0.2.19 ./lib/vendor/lux/misc.rb
lux_assets-0.2.15 ./lib/vendor/lux/misc.rb
lux_assets-0.2.14 ./lib/vendor/lux/misc.rb