Class: ActiveAssets::ActiveExpansions::Expansions

Inherits:
Object
  • Object
show all
Includes:
AssetScope, Configurable, TypeInferrable, ActiveSupport::Configurable
Defined in:
lib/active_assets/active_expansions/expansions.rb

Instance Method Summary collapse

Methods included from TypeInferrable

#inferred_type

Methods included from AssetScope

#css, #group, #js

Constructor Details

#initializeExpansions

Returns a new instance of Expansions.



12
13
14
# File 'lib/active_assets/active_expansions/expansions.rb', line 12

def initialize
  @expansions = Hash.new(&method(:build_expansions_hash_with_defaults))
end

Instance Method Details

#allObject



66
67
68
# File 'lib/active_assets/active_expansions/expansions.rb', line 66

def all
  @expansions[:js].values + @expansions[:css].values
end

#asset(path, options = {}) ⇒ Object Also known as: a, _



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_assets/active_expansions/expansions.rb', line 28

def asset(path, options = {})
  deferred_expansion_name, deferred_expansion_options = @deferred_expansion_config
  inferred_type, extension = inferred_type(path)

  options = HashWithIndifferentAccess.new(options).reverse_merge(
    :type => inferred_type || @current_type,
    :expansion_name => deferred_expansion_name,
    :group => @current_groups
  )

  expansion_options = update_expansion_options(deferred_expansion_options || {}, options[:type])

  # asset call below is executed in the scope of the ActiveAssets::Expansion
  @expansions[options[:type] || extension][options[:expansion_name]].configure(expansion_options) do
    asset(path, options)
  end
end

#clearObject



70
71
72
# File 'lib/active_assets/active_expansions/expansions.rb', line 70

def clear
  @expansions.clear
end

#expansion(name, options = {}, &blk) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/active_assets/active_expansions/expansions.rb', line 48

def expansion(name, options = {}, &blk)
  options = update_expansion_options(options)

  if options[:type].present?
    @expansions[options[:type]][name].configure(options, &blk)
  else
    defer_expansion(name, options, &blk)
  end
end

#javascriptsObject



58
59
60
# File 'lib/active_assets/active_expansions/expansions.rb', line 58

def javascripts
  Javascripts.new(@expansions[:js])
end

#namespace(name, &blk) ⇒ Object



21
22
23
24
25
26
# File 'lib/active_assets/active_expansions/expansions.rb', line 21

def namespace(name, &blk)
  @current_namespace = name
  instance_eval(&blk)
ensure
  @current_namespace = nil
end

#register(&blk) ⇒ Object



16
17
18
19
# File 'lib/active_assets/active_expansions/expansions.rb', line 16

def register(&blk)
  instance_eval(&blk) if block_given?
  self
end

#stylesheetsObject



62
63
64
# File 'lib/active_assets/active_expansions/expansions.rb', line 62

def stylesheets
  Stylesheets.new(@expansions[:css])
end