Module: KnockoutAssets

Defined in:
lib/knockout/assets/engine.rb,
app/helpers/knockout_assets.rb,
lib/knockout/assets/version.rb

Defined Under Namespace

Classes: Engine

Constant Summary collapse

VERSION =
'0.0.1'

Instance Method Summary collapse

Instance Method Details

#knockout_assets(options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/knockout_assets.rb', line 2

def knockout_assets(options = {})
  options = {
    exclude: nil,
    preload: true,
  }.merge(options)

  files = {}
  Rails.application.config.assets.paths.each { |p|
    Dir["#{p}/**/*"].select { |f| f =~ /.*\.(png|gif|jpg|jpeg|bmp)/ }.each { |f|
      item_path = f[p.length+1..-1]
      if !options[:exclude] || options[:exclude] !~ item_path
        files[item_path] = path_to_image(item_path)
      end
    }
  }

  render :partial => '/knockout_assets', locals: {asset_files: files, preload: options[:preload]}
end