Sha256: 8c12f656441fa2ca453cb5b075528127a52d65a7a3e72228852205358e104ce4

Contents?: true

Size: 970 Bytes

Versions: 7

Compression:

Stored size: 970 Bytes

Contents

module Trackman
  module Path  
    module Rails32Resolver
      include Resolver
      
      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 Sprockets::FileNotFound => e
          Trackman::Utility::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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
trackman-0.6.2 lib/trackman/path/rails32_resolver.rb
trackman-0.6.1 lib/trackman/path/rails32_resolver.rb
trackman-0.6.0 lib/trackman/path/rails32_resolver.rb
trackman-0.5.8 lib/trackman/path/rails32_resolver.rb
trackman-0.5.7 lib/trackman/path/rails32_resolver.rb
trackman-0.5.6 lib/trackman/path/rails32_resolver.rb
trackman-0.5.5 lib/trackman/path/rails32_resolver.rb