Sha256: 5f0f0ca16df9a3489e856020c6c1a27f14410c0c6b166816a8d75f0e2be46421

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require 'sprockets'

module Trackman
  module Assets
    module Components  
      module Rails32PathResolver
        include PathResolver
        
        def translate url, parent_url 
          root = working_dir.realpath
          
          path = url.dup
          path.slice! /^(\/assets|assets\/)/
          path = Pathname.new path

          path = prepare_for_sprocket(path, parent_url, root) if path.relative?
          begin
            path = sprockets.resolve path
          rescue Exception => e
            Debugger.trace "Could not find path: #{path}\n#{e.message}"
            return nil
          end
          path.relative_path_from(root).to_s
        end
        
        def prepare_for_sprocket path, parent_url, root
          folder = (root + Pathname.new(parent_url)).parent.realpath
          path = (folder + path).to_s
          path.slice! sprockets.paths.select{|p| path.include? p }.first
          path
        end
        
        def sprockets
          ::Rails.application.assets
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trackman-0.4.2 lib/trackman/assets/components/rails32_path_resolver.rb
trackman-0.4.1 lib/trackman/assets/components/rails32_path_resolver.rb