sinatra-support 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +6 -0
- data/lib/sinatra/support/csssupport.rb +25 -9
- data/lib/sinatra/support/version.rb +1 -1
- metadata +2 -2
data/HISTORY.md
CHANGED
@@ -41,6 +41,16 @@
|
|
41
41
|
# register Sinatra::CssSupport
|
42
42
|
# Main.set :css_aggressive_mtime, false
|
43
43
|
#
|
44
|
+
# == Helpers
|
45
|
+
#
|
46
|
+
# {Helpers#css_mtime_for css_mtime_for} - Returns the last modified time for
|
47
|
+
# the given stylesheet.
|
48
|
+
#
|
49
|
+
# <link rel="stylesheet" type="text/css" href="/css/style.css?<%= css_mtime_for(root('app/css/style.css')) %>">
|
50
|
+
#
|
51
|
+
# This takes into account the `css_aggressive_mtime` setting.
|
52
|
+
# Perfect for nocache hacks, like above.
|
53
|
+
#
|
44
54
|
# == Settings
|
45
55
|
#
|
46
56
|
# [+css_max_age+] The maximum time (in seconds) a browser
|
@@ -48,11 +58,13 @@
|
|
48
58
|
# (default: 30 days)
|
49
59
|
# [+css_aggressive_mtime+] If true, ask browsers to recache all CSS files
|
50
60
|
# when one is updated. Default: true
|
51
|
-
#
|
61
|
+
#
|
52
62
|
module Sinatra::CssSupport
|
53
63
|
def self.registered(app)
|
54
64
|
app.set :css_max_age, app.development? ? 0 : 86400*30
|
55
65
|
app.set :css_aggressive_mtime, true
|
66
|
+
|
67
|
+
app.helpers Helpers
|
56
68
|
end
|
57
69
|
|
58
70
|
def serve_css(url_prefix, options={})
|
@@ -63,13 +75,7 @@ module Sinatra::CssSupport
|
|
63
75
|
fname = Dir[File.join(prefix, "#{name}.{css,scss,less}")].first or pass
|
64
76
|
|
65
77
|
content_type :css, :charset => 'utf-8'
|
66
|
-
|
67
|
-
if settings.css_aggressive_mtime
|
68
|
-
last_modified Dir[prefix, "**/*"].map { |f| File.mtime(f).to_i }.max
|
69
|
-
else
|
70
|
-
last_modified File.mtime(fname)
|
71
|
-
end
|
72
|
-
|
78
|
+
last_modified css_mtime_for(prefix, fname)
|
73
79
|
cache_control :public, :must_revalidate, :max_age => settings.css_max_age
|
74
80
|
|
75
81
|
if fname =~ /\.scss$/
|
@@ -83,5 +89,15 @@ module Sinatra::CssSupport
|
|
83
89
|
end
|
84
90
|
end
|
85
91
|
end
|
86
|
-
end
|
87
92
|
|
93
|
+
module Helpers
|
94
|
+
def css_mtime_for(prefix=nil, fname)
|
95
|
+
if settings.css_aggressive_mtime
|
96
|
+
prefix ||= File.basename(fname)
|
97
|
+
Dir[prefix, "**/*"].map { |f| File.mtime(f).to_i }.max
|
98
|
+
else
|
99
|
+
File.mtime(fname).to_i
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sinatra-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Cyril David
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-03-
|
14
|
+
date: 2011-03-30 00:00:00 +08:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|