rack-less 1.2.0 → 1.2.1
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/less/request.rb +21 -9
- data/lib/rack/less/version.rb +1 -1
- metadata +1 -1
data/lib/rack/less/request.rb
CHANGED
@@ -39,17 +39,16 @@ module Rack::Less
|
|
39
39
|
File.extname(path_info)
|
40
40
|
end
|
41
41
|
|
42
|
+
def cache
|
43
|
+
File.join(options(:root), options(:public), options(:hosted_at))
|
44
|
+
end
|
45
|
+
|
42
46
|
# The Rack::Less::Source that the request is for
|
43
47
|
def source
|
44
48
|
@source ||= begin
|
45
|
-
cache = if Rack::Less.config.cache?
|
46
|
-
File.join(options(:root), options(:public), options(:hosted_at))
|
47
|
-
else
|
48
|
-
nil
|
49
|
-
end
|
50
49
|
source_opts = {
|
51
50
|
:folder => File.join(options(:root), options(:source)),
|
52
|
-
:cache => cache,
|
51
|
+
:cache => Rack::Less.config.cache? ? cache : nil,
|
53
52
|
:compress => Rack::Less.config.compress?
|
54
53
|
}
|
55
54
|
Source.new(path_resource_name, source_opts)
|
@@ -62,12 +61,25 @@ module Rack::Less
|
|
62
61
|
CSS_PATH_FORMATS.include?(path_resource_format)
|
63
62
|
end
|
64
63
|
|
64
|
+
def hosted_at?
|
65
|
+
File.basename(File.dirname(path_info)) == File.basename(options(:hosted_at))
|
66
|
+
end
|
67
|
+
|
68
|
+
def exists?
|
69
|
+
File.exists?(File.join(cache, "#{path_resource_name}#{path_resource_format}"))
|
70
|
+
end
|
71
|
+
|
65
72
|
# Determine if the request is for existing LESS CSS file
|
66
73
|
# This will be called on every request so speed is an issue
|
67
|
-
# => first check if the request is a GET on a css resource (fast)
|
68
|
-
# =>
|
74
|
+
# => first check if the request is a GET on a css resource :hosted_at (fast)
|
75
|
+
# => don't process if a file already exists in :hosted_at
|
76
|
+
# => otherwise, check for less source files that match the request (slow)
|
69
77
|
def for_less?
|
70
|
-
get? &&
|
78
|
+
get? &&
|
79
|
+
for_css? &&
|
80
|
+
hosted_at? &&
|
81
|
+
!exists? &&
|
82
|
+
!source.files.empty?
|
71
83
|
end
|
72
84
|
|
73
85
|
end
|
data/lib/rack/less/version.rb
CHANGED