Class: Tipsy::Handler::AssetHandler
- Inherits:
-
Sprockets::Environment
- Object
- Sprockets::Environment
- Tipsy::Handler::AssetHandler
- Defined in:
- lib/tipsy/handler/asset.rb
Overview
The AssetHandler is a subclass of Sprockets::Environment resposible for delivering assets back to the browser. In development assets should be defined under: javascripts: /assets/javascripts images: /assets/images stylesheets: /assets/stylesheets
Configure delivery urls using Tipsy::Site.asset_path, or Tipsy::Site.type_path where ‘type’ is the type of asset to configure Although assets are stored in the /assets folder, when compiled these directories will be used for the final output. This way assets can be organized during development, but placed anywhere when deployed
Instance Attribute Summary collapse
-
#asset_env ⇒ Object
readonly
Returns the value of attribute asset_env.
Class Method Summary collapse
Instance Method Summary collapse
- #css_exception_response(exception) ⇒ Object
-
#initialize ⇒ AssetHandler
constructor
A new instance of AssetHandler.
-
#javascript_exception_response(exception) ⇒ Object
When exceptions are thrown through Sprockets, ensure that the current indexes are expired.
-
#prepare_compiler ⇒ Object
Setup compressors for compilation.
Constructor Details
#initialize ⇒ AssetHandler
Returns a new instance of AssetHandler.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tipsy/handler/asset.rb', line 33 def initialize ::Sprockets.register_engine '.scss', Tipsy::Handler::SassHandler super(Tipsy.root) do |env| @asset_env = env end append_path "assets/javascripts" append_path "assets/images" append_path "assets/stylesheets" configure_compass! self end |
Instance Attribute Details
#asset_env ⇒ Object (readonly)
Returns the value of attribute asset_env.
19 20 21 |
# File 'lib/tipsy/handler/asset.rb', line 19 def asset_env @asset_env end |
Class Method Details
.map! ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/tipsy/handler/asset.rb', line 22 def map! fpaths = [:javascripts_path, :css_path, :images_path].collect do |p| path = ::Pathname.new(Tipsy::Site.send(p)) (path.absolute? ? path.to_s : path.to_s.sub(/^\//,'')) end fpaths.inject({}) do |hash, path| hash.merge!("#{path}" => self.new) end end |
Instance Method Details
#css_exception_response(exception) ⇒ Object
64 65 66 67 |
# File 'lib/tipsy/handler/asset.rb', line 64 def css_exception_response(exception) expire_index! super(exception) end |
#javascript_exception_response(exception) ⇒ Object
When exceptions are thrown through Sprockets, ensure that the current indexes are expired. This ensures we never receive a CircularDependency error.
59 60 61 62 |
# File 'lib/tipsy/handler/asset.rb', line 59 def javascript_exception_response(exception) expire_index! super(exception) end |
#prepare_compiler ⇒ Object
Setup compressors for compilation
50 51 52 53 |
# File 'lib/tipsy/handler/asset.rb', line 50 def prepare_compiler asset_env.css_compressor = Tipsy::Compressors::CssCompressor.new asset_env.js_compressor = Tipsy::Compressors::JavascriptCompressor.new end |