rack-less 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +23 -11
- data/Rakefile +4 -3
- data/lib/rack/less.rb +14 -3
- data/lib/rack/less/base.rb +1 -1
- data/lib/rack/less/config.rb +52 -12
- data/lib/rack/less/version.rb +2 -2
- metadata +67 -34
data/README.rdoc
CHANGED
@@ -74,15 +74,27 @@ You should now see `Rack::Less` listed in the middleware pipeline:
|
|
74
74
|
* .*combinations* [{}]
|
75
75
|
- Directives for combining the output of many stylesheets and serving them as a single resource.
|
76
76
|
|
77
|
-
* .*
|
77
|
+
* .*cache_bust* [nil]
|
78
78
|
- Directives for timestamping (cache-busting) while using combinations
|
79
|
-
- :*false* - don't explicitly
|
80
|
-
- :*true* -
|
81
|
-
-
|
79
|
+
- :*false* - don't explicitly cache bust (no value added)
|
80
|
+
- :*true* - use Time.now.to_i as the explicit value (will never cache)
|
81
|
+
- :*nil* - change cache bust value if the file is modified (similar to Rails' stylesheet_link_tag)
|
82
|
+
- :*<any other value>* - add the value as "foo.css?<value>"
|
83
|
+
|
84
|
+
=== Using in layouts
|
85
|
+
|
86
|
+
==== Cache Busting
|
87
|
+
|
88
|
+
Rails does a lot of helpful things with 'stylesheet_link_tag' to help reference your stylesheets into your layouts - things like cache busting stylesheet hrefs. However, Rails' will only cache bust your stylesheets if the file exists in the public/stylesheets directory. When using Rack::Less a file may never exist at that path or, when caching is used, only exist after the initial request.
|
89
|
+
|
90
|
+
To help provide this behavior, Rack::Less provides a helper for generating reference paths to your stylesheets.
|
91
|
+
|
92
|
+
# equivalent to: stylesheet_link_tag 'reset'
|
93
|
+
stylesheet_link_tag Rack::Less.stylesheet('reset')
|
82
94
|
|
83
|
-
|
95
|
+
==== Combinations
|
84
96
|
|
85
|
-
At times, it is useful to combine multiple stylesheets and serve them as one resource. For example you may have two sets of stylesheets: one for traditional web views and one for mobile web views. Rails' provides the :cache option on 'stylesheet_link_tag' helper to provide this function
|
97
|
+
At times, it is useful to combine multiple stylesheets and serve them as one resource. For example you may have two sets of stylesheets: one for traditional web views and one for mobile web views. Rails' provides the :cache option on 'stylesheet_link_tag' helper to provide this function.
|
86
98
|
|
87
99
|
stylesheet_link_tag 'reset', 'common', 'app_web', :cache => 'web'
|
88
100
|
stylesheet_link_tag 'reset', 'common', 'iui', 'app_mobile', :cache => 'mobile'
|
@@ -96,13 +108,13 @@ Rack::Less uses combinations, in conjunction with the :cache config setting, to
|
|
96
108
|
}
|
97
109
|
end
|
98
110
|
|
99
|
-
and stylesheet link tags like this
|
111
|
+
and stylesheet link tags like this:
|
100
112
|
|
101
113
|
# equivalent to: stylesheet_link_tag 'reset', 'common', 'app_web'
|
102
|
-
stylesheet_link_tag Rack::Less.
|
114
|
+
stylesheet_link_tag Rack::Less.stylesheet('web')
|
103
115
|
|
104
116
|
# equivalent to: stylesheet_link_tag 'reset', 'common', 'iui', 'app_mobile'
|
105
|
-
stylesheet_link_tag Rack::Less.
|
117
|
+
stylesheet_link_tag Rack::Less.stylesheet('mobile')
|
106
118
|
|
107
119
|
If you configure Rack::Less to cache, with something like this:
|
108
120
|
|
@@ -111,10 +123,10 @@ If you configure Rack::Less to cache, with something like this:
|
|
111
123
|
then the same stylesheet link tags behave like they have the :cache option set, respectively:
|
112
124
|
|
113
125
|
# equivalent to: stylesheet_link_tag 'reset', 'common', 'app_web', :cache => 'web'
|
114
|
-
stylesheet_link_tag Rack::Less.
|
126
|
+
stylesheet_link_tag Rack::Less.stylesheet('web')
|
115
127
|
|
116
128
|
# equivalent to: stylesheet_link_tag 'reset', 'common', 'iui', 'app_mobile', :cache => 'mobile'
|
117
|
-
stylesheet_link_tag Rack::Less.
|
129
|
+
stylesheet_link_tag Rack::Less.stylesheet('mobile')
|
118
130
|
|
119
131
|
== Links
|
120
132
|
|
data/Rakefile
CHANGED
@@ -17,13 +17,14 @@ spec = Gem::Specification.new do |s|
|
|
17
17
|
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib}/**/*")
|
18
18
|
# s.executables = ['rack-less']
|
19
19
|
|
20
|
-
s.add_dependency("rack", [">= 0.4"])
|
21
|
-
s.add_dependency("less", [">= 1.2.21"])
|
22
|
-
|
23
20
|
s.add_development_dependency("shoulda", [">= 2.10.2"])
|
24
21
|
s.add_development_dependency("sinatra", [">= 0.9.4"])
|
25
22
|
s.add_development_dependency("rack-test", [">= 0.5.3"])
|
26
23
|
s.add_development_dependency("webrat", [">= 0.6.0"])
|
24
|
+
s.add_development_dependency("yui-compressor", [">=0.9.1"])
|
25
|
+
|
26
|
+
s.add_dependency("rack", [">= 0.4"])
|
27
|
+
s.add_dependency("less", [">= 1.2.21"])
|
27
28
|
end
|
28
29
|
|
29
30
|
Rake::GemPackageTask.new(spec) do |pkg|
|
data/lib/rack/less.rb
CHANGED
@@ -43,12 +43,23 @@ module Rack::Less
|
|
43
43
|
def combinations(key=nil)
|
44
44
|
@@config.combinations(key)
|
45
45
|
end
|
46
|
+
|
47
|
+
# Stylesheet helper, config convenience method
|
48
|
+
def stylesheet(key)
|
49
|
+
@@config.stylesheet(key)
|
50
|
+
end
|
46
51
|
|
47
|
-
#
|
48
|
-
def
|
49
|
-
@@config.
|
52
|
+
# Cache bust config convenience method
|
53
|
+
def cache_bust
|
54
|
+
@@config.cache_bust
|
50
55
|
end
|
51
56
|
|
57
|
+
# <b>DEPRECATED:</b> Please use <tt>cache_bust</tt> instead.
|
58
|
+
def combination_timestamp
|
59
|
+
warn "[DEPRECATION] `combination_timestamp` is deprecated. Please use `cache_bust` instead."
|
60
|
+
cache_bust
|
61
|
+
end
|
62
|
+
|
52
63
|
end
|
53
64
|
|
54
65
|
# Create a new Rack::Less middleware component
|
data/lib/rack/less/base.rb
CHANGED
data/lib/rack/less/config.rb
CHANGED
@@ -21,24 +21,36 @@ module Rack::Less
|
|
21
21
|
# 'web' => ['reset', 'common', 'app_web'],
|
22
22
|
# 'mobile' => ['reset', 'iui', 'common', 'app_mobile']
|
23
23
|
# }
|
24
|
-
# :
|
24
|
+
# :cache_bust
|
25
25
|
# whether to append a timestamp to the sheet requests generated by combinations
|
26
26
|
class Config
|
27
27
|
|
28
|
-
ATTRIBUTES = [:cache, :compress, :combinations, :
|
28
|
+
ATTRIBUTES = [:cache, :compress, :combinations, :cache_bust]
|
29
29
|
attr_accessor *ATTRIBUTES
|
30
30
|
|
31
31
|
DEFAULTS = {
|
32
32
|
:cache => false,
|
33
33
|
:compress => false,
|
34
|
-
:combinations => {}
|
35
|
-
:combination_timestamp => false
|
34
|
+
:combinations => {}
|
36
35
|
}
|
37
36
|
|
38
37
|
def initialize(settings={})
|
39
38
|
ATTRIBUTES.each do |a|
|
40
39
|
instance_variable_set("@#{a}", settings[a] || DEFAULTS[a])
|
41
|
-
end
|
40
|
+
end
|
41
|
+
@cache_bust = default_cache_bust if @cache_bust.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
# <b>DEPRECATED:</b> Please use <tt>cache_bust</tt> instead.
|
45
|
+
def combination_timestamp
|
46
|
+
warn "[DEPRECATION] `combination_timestamp` is deprecated. Please use `cache_bust` instead."
|
47
|
+
cache_bust
|
48
|
+
end
|
49
|
+
|
50
|
+
# <b>DEPRECATED:</b> Please use <tt>cache_bust=</tt> instead.
|
51
|
+
def combination_timestamp=(value)
|
52
|
+
warn "[DEPRECATION] `combination_timestamp=` is deprecated. Please use `cache_bust=` instead."
|
53
|
+
cache_bust = value
|
42
54
|
end
|
43
55
|
|
44
56
|
def cache?
|
@@ -54,30 +66,58 @@ module Rack::Less
|
|
54
66
|
@combinations
|
55
67
|
else
|
56
68
|
if cache?
|
57
|
-
|
69
|
+
stylesheet_filename(key)
|
58
70
|
else
|
59
71
|
(@combinations[key] || []).collect do |combo|
|
60
|
-
|
72
|
+
stylesheet_filename(combo)
|
61
73
|
end
|
62
74
|
end
|
63
75
|
end
|
64
76
|
end
|
65
77
|
|
78
|
+
def stylesheet(key)
|
79
|
+
if @combinations[key]
|
80
|
+
combinations(key.to_s)
|
81
|
+
else
|
82
|
+
stylesheet_filename(key.to_s)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
66
86
|
private
|
67
87
|
|
68
|
-
def
|
69
|
-
filename =
|
88
|
+
def stylesheet_filename(key)
|
89
|
+
filename = key.strip
|
70
90
|
filename += ".css" unless filename.include?('.css')
|
71
|
-
if !filename.include?('?') &&
|
91
|
+
if !filename.include?('?') && cache_bust
|
72
92
|
filename += "?"
|
73
|
-
filename += if
|
93
|
+
filename += if cache_bust == true
|
74
94
|
Time.now.to_i
|
75
95
|
else
|
76
|
-
|
96
|
+
cache_bust
|
77
97
|
end.to_s
|
78
98
|
end
|
79
99
|
filename
|
80
100
|
end
|
81
101
|
|
102
|
+
def default_cache_bust
|
103
|
+
if defined?(::Sinatra) && defined?(::Sinatra::Application)
|
104
|
+
app_root_cache_bust(::Sinatra::Application)
|
105
|
+
elsif defined?(::Rails)
|
106
|
+
app_root_cache_bust(::Rails)
|
107
|
+
end || false
|
108
|
+
end
|
109
|
+
|
110
|
+
def app_root_cache_bust(app)
|
111
|
+
if app.respond_to?(:root)
|
112
|
+
mtime_cache_bust(app.root.to_s)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def mtime_cache_bust(path)
|
117
|
+
if File.exists?(path)
|
118
|
+
File.mtime(path).to_i
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
82
122
|
end
|
83
123
|
end
|
data/lib/rack/less/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-less
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 1.4.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Kelly Redding
|
@@ -14,92 +15,120 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-08-08 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
22
|
+
name: shoulda
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 35
|
27
30
|
segments:
|
28
|
-
-
|
29
|
-
-
|
30
|
-
|
31
|
-
|
31
|
+
- 2
|
32
|
+
- 10
|
33
|
+
- 2
|
34
|
+
version: 2.10.2
|
35
|
+
type: :development
|
32
36
|
version_requirements: *id001
|
33
37
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
38
|
+
name: sinatra
|
35
39
|
prerelease: false
|
36
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ">="
|
39
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 51
|
40
46
|
segments:
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
version:
|
45
|
-
type: :
|
47
|
+
- 0
|
48
|
+
- 9
|
49
|
+
- 4
|
50
|
+
version: 0.9.4
|
51
|
+
type: :development
|
46
52
|
version_requirements: *id002
|
47
53
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
54
|
+
name: rack-test
|
49
55
|
prerelease: false
|
50
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ">="
|
53
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 13
|
54
62
|
segments:
|
55
|
-
-
|
56
|
-
-
|
57
|
-
-
|
58
|
-
version:
|
63
|
+
- 0
|
64
|
+
- 5
|
65
|
+
- 3
|
66
|
+
version: 0.5.3
|
59
67
|
type: :development
|
60
68
|
version_requirements: *id003
|
61
69
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
70
|
+
name: webrat
|
63
71
|
prerelease: false
|
64
72
|
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
75
|
- - ">="
|
67
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 7
|
68
78
|
segments:
|
69
79
|
- 0
|
70
|
-
-
|
71
|
-
-
|
72
|
-
version: 0.
|
80
|
+
- 6
|
81
|
+
- 0
|
82
|
+
version: 0.6.0
|
73
83
|
type: :development
|
74
84
|
version_requirements: *id004
|
75
85
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
86
|
+
name: yui-compressor
|
77
87
|
prerelease: false
|
78
88
|
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
91
|
- - ">="
|
81
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 57
|
82
94
|
segments:
|
83
95
|
- 0
|
84
|
-
-
|
85
|
-
-
|
86
|
-
version: 0.
|
96
|
+
- 9
|
97
|
+
- 1
|
98
|
+
version: 0.9.1
|
87
99
|
type: :development
|
88
100
|
version_requirements: *id005
|
89
101
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
102
|
+
name: rack
|
91
103
|
prerelease: false
|
92
104
|
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
93
106
|
requirements:
|
94
107
|
- - ">="
|
95
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
96
110
|
segments:
|
97
111
|
- 0
|
98
|
-
-
|
99
|
-
|
100
|
-
|
101
|
-
type: :development
|
112
|
+
- 4
|
113
|
+
version: "0.4"
|
114
|
+
type: :runtime
|
102
115
|
version_requirements: *id006
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
name: less
|
118
|
+
prerelease: false
|
119
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 53
|
125
|
+
segments:
|
126
|
+
- 1
|
127
|
+
- 2
|
128
|
+
- 21
|
129
|
+
version: 1.2.21
|
130
|
+
type: :runtime
|
131
|
+
version_requirements: *id007
|
103
132
|
description:
|
104
133
|
email: kelly@kelredd.com
|
105
134
|
executables: []
|
@@ -130,23 +159,27 @@ rdoc_options:
|
|
130
159
|
require_paths:
|
131
160
|
- lib
|
132
161
|
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
133
163
|
requirements:
|
134
164
|
- - ">="
|
135
165
|
- !ruby/object:Gem::Version
|
166
|
+
hash: 3
|
136
167
|
segments:
|
137
168
|
- 0
|
138
169
|
version: "0"
|
139
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
none: false
|
140
172
|
requirements:
|
141
173
|
- - ">="
|
142
174
|
- !ruby/object:Gem::Version
|
175
|
+
hash: 3
|
143
176
|
segments:
|
144
177
|
- 0
|
145
178
|
version: "0"
|
146
179
|
requirements: []
|
147
180
|
|
148
181
|
rubyforge_project:
|
149
|
-
rubygems_version: 1.3.
|
182
|
+
rubygems_version: 1.3.7
|
150
183
|
signing_key:
|
151
184
|
specification_version: 3
|
152
185
|
summary: A better way to use LESS CSS in Ruby web apps.
|