Sha256: b59c835fb801902efea696c2af8fcd017d24bd50654e7631d7315f20529fad19

Contents?: true

Size: 1.04 KB

Versions: 17

Compression:

Stored size: 1.04 KB

Contents

module Sprockets
  module Helpers
    # `FilePath` generates a full path for a regular file
    # in the output path. It's used by #asset_path to generate
    # paths when using asset tags like #javascript_include_tag,
    # #stylesheet_link_tag, and #image_tag
    class FilePath < BasePath
      
      protected
      
      # Hook for rewriting the base path.
      def rewrite_path # :nodoc:
        if uri.path[0] != ?/
          prepend_path File.join('/', options[:dir].to_s)
        end
      end
      
      # Hook for rewriting the query string.
      def rewrite_query # :nodoc:
        if timestamp = compute_mtime
          append_query(timestamp.to_i.to_s)
        end
      end
      
      # Returns the mtime for the given path (relative to
      # the output path). Returns nil if the file doesn't exist.
      def compute_mtime # :nodoc:
        public_path = File.join(Helpers.public_path, uri.path)
        
        if File.exist?(public_path)
          File.mtime(public_path)
        else
          nil
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
sprockets-helpers-1.3.0 lib/sprockets/helpers/file_path.rb
sprockets-helpers-1.2.3 lib/sprockets/helpers/file_path.rb
sprockets-helpers-1.2.2 lib/sprockets/helpers/file_path.rb
arcabouco-0.2.13 vendor/bundle/gems/sprockets-helpers-1.2.1/lib/sprockets/helpers/file_path.rb
sprockets-helpers-1.2.1 lib/sprockets/helpers/file_path.rb
sprockets-helpers-1.2.0 lib/sprockets/helpers/file_path.rb
sprockets-helpers-1.1.0 lib/sprockets/helpers/file_path.rb
sprockets-helpers-1.0.1 lib/sprockets/helpers/file_path.rb
sprockets-helpers-1.0.0 lib/sprockets/helpers/file_path.rb
sprockets-helpers-0.9.1 lib/sprockets/helpers/file_path.rb
sprockets-helpers-0.8.0 lib/sprockets/helpers/file_path.rb
sprockets-helpers-0.7.2 lib/sprockets/helpers/file_path.rb
sprockets-helpers-0.7.1 lib/sprockets/helpers/file_path.rb
sprockets-helpers-0.7.0 lib/sprockets/helpers/file_path.rb
sprockets-helpers-0.6.1 lib/sprockets/helpers/file_path.rb
sprockets-helpers-0.6.0 lib/sprockets/helpers/file_path.rb
sprockets-helpers-0.5.0 lib/sprockets/helpers/file_path.rb