Class: ActiveAssets::ActiveExpansions::Expansion

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TypeInferrable

#inferred_type

Methods included from AssetScope

#css, #js

Constructor Details

#initialize(name) ⇒ Expansion

Returns a new instance of Expansion.



14
15
16
17
# File 'lib/active_assets/active_expansions/expansion.rb', line 14

def initialize(name)
  @name = name
  @assets = []
end

Instance Attribute Details

#assetsObject (readonly) Also known as: all

Returns the value of attribute assets.



10
11
12
# File 'lib/active_assets/active_expansions/expansion.rb', line 10

def assets
  @assets
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/active_assets/active_expansions/expansion.rb', line 10

def name
  @name
end

#namespace(&blk) ⇒ Object (readonly)

Returns the value of attribute namespace.

Raises:

  • (NoMethodError)


10
11
12
# File 'lib/active_assets/active_expansions/expansion.rb', line 10

def namespace
  @namespace
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/active_assets/active_expansions/expansion.rb', line 10

def type
  @type
end

Instance Method Details

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



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

def asset(path, options = {})
  options = HashWithIndifferentAccess.new(options)
  # map is for 1.9.2; HashWithIndifferentAccess bug?
  options.assert_valid_keys(*Asset.members.map(&:to_s))

  inferred_type, extension = inferred_type(path)

  options.reverse_merge!(
    :type => inferred_type || @current_type || extension || type,
    :expansion_name => name,
    :group => @current_groups
  )
  options.update(:path => path)

  members = options.values_at(*Asset.members)
  a = Asset.new(*members)

  a.valid!
  @assets << a
end

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



19
20
21
22
23
# File 'lib/active_assets/active_expansions/expansion.rb', line 19

def configure(options = {}, &blk)
  @type, @group, @namespace = options.values_at(:type, :group, :namespace)
  instance_eval(&blk) if block_given?
  self
end

#group(*groups, &blk) ⇒ Object



48
49
50
51
52
53
# File 'lib/active_assets/active_expansions/expansion.rb', line 48

def group(*groups, &blk)
  @current_groups = groups
  instance_eval(&blk)
ensure
  @current_groups = nil
end