Class: Deadfire::AssetRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/deadfire/asset_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAssetRegistry

Returns a new instance of AssetRegistry.



7
8
9
# File 'lib/deadfire/asset_registry.rb', line 7

def initialize
  @settings = Hash.new { |h, k| h[k] = [] }
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



5
6
7
# File 'lib/deadfire/asset_registry.rb', line 5

def settings
  @settings
end

Instance Method Details

#clearObject



43
44
45
# File 'lib/deadfire/asset_registry.rb', line 43

def clear
  @settings.clear
end

#mixins_for(path) ⇒ Object

for a given path, load all the mixins that are registered e.g. admin/ or admin will load all mixins for admin, if admin is a scope all mixins for admin/* will be loaded



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/deadfire/asset_registry.rb', line 23

def mixins_for(path)
  return [] unless path.present?

  mixins = []

  mixins.concat Array.wrap(@settings[path])

  if settings["*"].present?
    mixins.concat Array.wrap(settings["*"])
  end

  scope = scope_from_path(path)

  if scope.present? && settings[scope].present?
    mixins.concat Array.wrap(settings[scope])
  end

  mixins.compact.uniq
end

#register_path(path, *mixins) ⇒ Object

for a given path, load all the mixins that are registered this makes it possible to load admin or other scoped mixins for a specific path



14
15
16
17
18
# File 'lib/deadfire/asset_registry.rb', line 14

def register_path(path, *mixins)
  normalized_mixins = Array.wrap(mixins).map { |p| full_path(p) }
  normalize_path = strip_path(path).to_s
  @settings[normalize_path].concat(normalized_mixins)
end