Class: Middleman::Presentation::AssetsManager

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-presentation-core/assets_manager.rb

Overview

Manager for assets

It knows about all assets. This information is used when adding assets to ‘sprockets`. It gets its information normally from through `plugins` or through reading the bower components directory in filesystem.

Instance Method Summary collapse

Constructor Details

#initialize(store: AssetStore.new) ⇒ AssetsManager

Returns a new instance of AssetsManager.



16
17
18
19
20
# File 'lib/middleman-presentation-core/assets_manager.rb', line 16

def initialize(
  store: AssetStore.new
)
  @store   = store
end

Instance Method Details

#add(asset) ⇒ Object

Add asset



23
24
25
# File 'lib/middleman-presentation-core/assets_manager.rb', line 23

def add(asset)
  store.add asset
end

#each_importable_javascript(&block) ⇒ Object

Iterate over each importable asset



57
58
59
# File 'lib/middleman-presentation-core/assets_manager.rb', line 57

def each_importable_javascript(&block)
  each_importable_asset.select(&:script?).each(&block)
end

#each_importable_stylesheet(&block) ⇒ Object

Iterate over each importable asset



52
53
54
# File 'lib/middleman-presentation-core/assets_manager.rb', line 52

def each_importable_stylesheet(&block)
  each_importable_asset.select(&:stylesheet?).each(&block)
end

#each_loadable_asset(&block) ⇒ Object

Iterate over each loadable asset



47
48
49
# File 'lib/middleman-presentation-core/assets_manager.rb', line 47

def each_loadable_asset(&block)
  store.select { |a| a.valid? && a.loadable? }.each(&block)
end

#know?(asset) ⇒ Boolean

Return assets

Returns:

  • (Boolean)


28
29
30
# File 'lib/middleman-presentation-core/assets_manager.rb', line 28

def know?(asset)
  store.include? asset
end

#load_from_list(*lists) ⇒ Object

Load assets from list



62
63
64
# File 'lib/middleman-presentation-core/assets_manager.rb', line 62

def load_from_list(*lists)
  lists.flatten.each { |l| store.merge l }
end

#to_sObject

Show assets which should be imported



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/middleman-presentation-core/assets_manager.rb', line 33

def to_s
  data = store.assets.sort.reduce([]) do |a, e|
    a << {
      source_path: e.relative_source_path,
      destination_path: e.destination_path,
      loadable: e.loadable?,
      importable: e.importable?
    }
  end

  List.new(data).to_s(fields: [:source_path, :destination_path, :loadable, :importable], vertical: true)
end