Class: Tension::Environment
- Inherits:
-
Object
- Object
- Tension::Environment
- Defined in:
- lib/tension/environment.rb
Overview
This class describes routes and controller contexts, and through those contexts the assets to be included in templates.
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
Instance Method Summary collapse
-
#contexts ⇒ Object
A Hash mapping controller paths to Contexts.
-
#find_asset(logical_path) ⇒ Object
Returns a Sprockets::Asset for the given logical path.
-
#find_context(key) ⇒ Object
Loads a Context for the specified controller path.
-
#initialize(assets_path) ⇒ Environment
constructor
A new instance of Environment.
-
#precompilation_needed?(path) ⇒ Boolean
Determines whether or not a given path refers to an asset that requires precompilation.
Constructor Details
#initialize(assets_path) ⇒ Environment
10 11 12 13 14 |
# File 'lib/tension/environment.rb', line 10 def initialize(assets_path) if assets_cached? cache_assets_from_manifest!(Sprockets::Manifest.new(assets_path)) end end |
Instance Attribute Details
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
8 9 10 |
# File 'lib/tension/environment.rb', line 8 def assets @assets end |
Instance Method Details
#contexts ⇒ Object
A Hash mapping controller paths to Contexts.
36 37 38 |
# File 'lib/tension/environment.rb', line 36 def contexts @contexts ||= Hash.new end |
#find_asset(logical_path) ⇒ Object
Returns a Sprockets::Asset for the given logical path. Will load assets cached from a manifest if available, but in development falls back to the Sprockets::Index as assets may be under development.
26 27 28 29 30 31 32 |
# File 'lib/tension/environment.rb', line 26 def find_asset(logical_path) if assets_cached? assets[logical_path] else Rails.application.assets.find_asset(logical_path) end end |
#find_context(key) ⇒ Object
Loads a Context for the specified controller path.
18 19 20 |
# File 'lib/tension/environment.rb', line 18 def find_context(key) fetch( Tension::Utils.controller_path(key) ) end |
#precompilation_needed?(path) ⇒ Boolean
Determines whether or not a given path refers to an asset that requires precompilation.
43 44 45 46 47 |
# File 'lib/tension/environment.rb', line 43 def precompilation_needed?(path) if cxt = find_context(path) Tension::Utils.shared_asset?(path) || cxt.has_action?( Tension::Utils.action_name(path) ) end end |