Sha256: 4d38dc61a8636e846326e511f5513555a34d37bbea460aada67d87d5f2d97e08
Contents?: true
Size: 1.8 KB
Versions: 12
Compression:
Stored size: 1.8 KB
Contents
# encoding: utf-8 module Middleman module Presentation # 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. class AssetsManager private attr_reader :store public def initialize( store: AssetStore.new ) @store = store end # Add asset def add(asset) store.add asset end # Return assets def know?(asset) store.include? asset end # Show assets which should be imported 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 # Iterate over each loadable asset def each_loadable_asset(&block) store.select { |a| a.valid? && a.loadable? }.each(&block) end # Iterate over each importable asset def each_importable_stylesheet(&block) each_importable_asset.select(&:stylesheet?).each(&block) end # Iterate over each importable asset def each_importable_javascript(&block) each_importable_asset.select(&:script?).each(&block) end # Load assets from list def load_from_list(*lists) lists.flatten.each { |l| store.merge l } end private def each_importable_asset(&_block) store.select { |a| a.valid? && a.importable? } end end end end
Version data entries
12 entries across 12 versions & 1 rubygems