Class: Tension::Environment

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(assets_path) ⇒ Environment

Returns a new instance of Environment.



10
11
12
13
# File 'lib/tension/environment.rb', line 10

def initialize(assets_path)
  @manifest = Sprockets::Manifest.new(assets_path)
  process_assets!
end

Instance Attribute Details

#assetsObject (readonly)

Returns the value of attribute assets.



8
9
10
# File 'lib/tension/environment.rb', line 8

def assets
  @assets
end

Instance Method Details

#contextsObject

A Hash mapping controller paths to Contexts.



24
25
26
# File 'lib/tension/environment.rb', line 24

def contexts
  @contexts ||= Hash.new
end

#find_context(key) ⇒ Object Also known as: []

Loads a Context for the specified controller path.



17
18
19
# File 'lib/tension/environment.rb', line 17

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.

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/tension/environment.rb', line 31

def precompilation_needed?(path)
  if cxt = find_context(path)
    Tension::Utils.shared_asset?(path) || cxt.has_action?( Tension::Utils.action_name(path) )
  end
end