Sha256: e3b8256e4ae219eda9c4bb6dd5ec7bcad34687ed5ef147bbe9f286ead01d6352

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

module JsAssets
  class List
    class << self
      attr_accessor :exclude, :allow
    end
    @exclude = ['application.js']
    @allow = ['*.html']
    def self.fetch
      project_assets = {}
      ::Rails.application.assets.logical_paths do |logical_path, filename|
        next if matches_filter(@exclude, logical_path, filename)
        next unless matches_filter(@allow, logical_path, filename)
        if ::Rails.application.assets.file_digest(filename)
          project_assets[logical_path] = File.join('/', ::Rails.application.config.assets.prefix,
            ::Rails.application.assets[logical_path].digest_path)
        else
          project_assets[logical_path] = File.join('/', ::Rails.application.config.assets.prefix,
            logical_path)
        end
      end
      return project_assets
    end

  protected
    # from
    # https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/base.rb:418
    def self.matches_filter(filters, logical_path, filename)
      return true if filters.nil? || filters.empty?

      filters.any? do |filter|
        if filter.is_a?(Regexp)
          filter.match(logical_path)
        elsif filter.respond_to?(:call)
          if filter.arity == 1
            filter.call(logical_path)
          else
            filter.call(logical_path, filename.to_s)
          end
        else
          # puts filter
          File.fnmatch(filter.to_s, logical_path)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
js_assets-0.1.0 lib/js_assets/list.rb