rack-sprockets 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rack/sprockets/request.rb +21 -9
- data/lib/rack/sprockets/version.rb +1 -1
- metadata +1 -1
@@ -38,17 +38,16 @@ module Rack::Sprockets
|
|
38
38
|
File.extname(path_info)
|
39
39
|
end
|
40
40
|
|
41
|
+
def cache
|
42
|
+
File.join(options(:root), options(:public), options(:hosted_at))
|
43
|
+
end
|
44
|
+
|
41
45
|
# The Rack::Sprockets::Source that the request is for
|
42
46
|
def source
|
43
47
|
@source ||= begin
|
44
|
-
cache = if Rack::Sprockets.config.cache?
|
45
|
-
File.join(options(:root), options(:public), options(:hosted_at))
|
46
|
-
else
|
47
|
-
nil
|
48
|
-
end
|
49
48
|
source_opts = {
|
50
49
|
:folder => File.join(options(:root), options(:source)),
|
51
|
-
:cache => cache,
|
50
|
+
:cache => Rack::Sprockets.config.cache? ? cache : nil,
|
52
51
|
:compress => Rack::Sprockets.config.compress,
|
53
52
|
:secretary => {
|
54
53
|
:root => options(:root),
|
@@ -66,12 +65,25 @@ module Rack::Sprockets
|
|
66
65
|
JS_PATH_FORMATS.include?(path_resource_format)
|
67
66
|
end
|
68
67
|
|
68
|
+
def hosted_at?
|
69
|
+
File.basename(File.dirname(path_info)) == File.basename(options(:hosted_at))
|
70
|
+
end
|
71
|
+
|
72
|
+
def exists?
|
73
|
+
File.exists?(File.join(cache, "#{path_resource_name}#{path_resource_format}"))
|
74
|
+
end
|
75
|
+
|
69
76
|
# Determine if the request is for an existing Sprockets source file
|
70
77
|
# This will be called on every request so speed is an issue
|
71
|
-
# => first check if the request is a GET on a js resource (fast)
|
72
|
-
# =>
|
78
|
+
# => first check if the request is a GET on a js resource in :hosted_at (fast)
|
79
|
+
# => don't process if a file already exists in :hosted_at
|
80
|
+
# => otherwise, check for sprockets source files that match the request (slow)
|
73
81
|
def for_sprockets?
|
74
|
-
get? &&
|
82
|
+
get? &&
|
83
|
+
for_js? &&
|
84
|
+
hosted_at? &&
|
85
|
+
!exists? &&
|
86
|
+
!source.files.empty?
|
75
87
|
end
|
76
88
|
|
77
89
|
end
|