Module: Plezi::AssetBaker

Defined in:
lib/plezi/router/assets.rb

Overview

This module is used for asset “baking” (or “belated baking”). It allows us to easily register and support new types of assets.

Class Method Summary collapse

Class Method Details

.bake(name) ⇒ Object

called by Plezi when in need of baking an asset.


56
57
58
59
60
61
62
63
64
# File 'lib/plezi/router/assets.rb', line 56

def self.bake(name)
  ret = nil
  ext = File.extname name
  return false if ext.empty?
  driver = @drivers[ext]
  return false if driver.nil?
  driver.each { |d| ret = d.call(name); return ret if ret }
  nil
end

.register(ext, driver) ⇒ Object

Registers a new Asset Driver of a specific extension (i.e. “css”, “js”, etc')

Multiple Asset Drivers can be registered for the same extension. The will be attempted in the order of their registration.

An Asset Drivers is an object that responsd to `.call(target)`. If the traget is newly rendered, the driver should return the rendered text. If the asset didn't change since the last time `.call(target)` was called, the driver should return 'true' (meanning, yet, the asset exists, it's the same). If the driver doesn't locate the asset, it should return `nil` or `false`, indicating the next driver should be attempted.


50
51
52
# File 'lib/plezi/router/assets.rb', line 50

def self.register(ext, driver)
  (@drivers[".#{ext}".freeze] ||= [].to_set) << driver
end