rack-less 1.0.0 → 1.1.0
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/README.rdoc +58 -23
- data/lib/rack/less.rb +16 -5
- data/lib/rack/less/config.rb +58 -0
- data/lib/rack/less/options.rb +1 -24
- data/lib/rack/less/request.rb +2 -2
- data/lib/rack/less/source.rb +6 -2
- data/lib/rack/less/version.rb +1 -1
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -16,10 +16,17 @@ or uses Rack::Builder to construct the application pipeline, simply require
|
|
16
16
|
and use as follows:
|
17
17
|
|
18
18
|
require 'rack/less'
|
19
|
+
|
20
|
+
# optional - use as necessary
|
21
|
+
Rack::Less.configure do |config|
|
22
|
+
config.compress = true
|
23
|
+
# other configs ...
|
24
|
+
end
|
19
25
|
|
20
26
|
use Rack::Less,
|
21
|
-
:source
|
22
|
-
:
|
27
|
+
:source => 'app/less',
|
28
|
+
:hosted_at => '/'
|
29
|
+
# additional options ...
|
23
30
|
|
24
31
|
run app
|
25
32
|
|
@@ -29,56 +36,84 @@ Add this to your `config/environment.rb`:
|
|
29
36
|
|
30
37
|
config.middleware.use "Rack::Less"
|
31
38
|
|
39
|
+
Add any configs in an initializer (optional - use as necessary):
|
40
|
+
|
41
|
+
Rack::Less.configure do |config|
|
42
|
+
config.cache = true
|
43
|
+
# additional configs ...
|
44
|
+
end
|
45
|
+
|
32
46
|
You should now see `Rack::Less` listed in the middleware pipeline:
|
33
47
|
|
34
48
|
rake middleware
|
35
49
|
|
36
50
|
== Available Options
|
37
|
-
[
|
51
|
+
key: name [default]: description
|
38
52
|
|
39
53
|
* *root* ["."]:
|
40
54
|
the app root. the reference point for the source and public options.
|
41
55
|
|
42
56
|
* *source* ['app/stylesheets']:
|
43
|
-
the path (relative to the root) where LESS files are located
|
57
|
+
the path (relative to the root) where LESS source files are located
|
44
58
|
|
45
59
|
* *public* ['public']:
|
46
|
-
the path (relative to the root)
|
60
|
+
the path (relative to the root) static files are located
|
47
61
|
|
48
62
|
* *hosted_at* ['/stylesheets']:
|
49
|
-
the public HTTP
|
63
|
+
the public HTTP path for hosted stylesheets
|
64
|
+
|
65
|
+
== Available Configurations
|
66
|
+
key: name [default]: description
|
50
67
|
|
51
68
|
* *cache* [false]:
|
52
|
-
whether to cache the compilation output to a corresponding file
|
69
|
+
whether to cache the compilation output to a corresponding static file
|
53
70
|
|
54
71
|
* *compress* [false]:
|
55
72
|
whether to remove extraneous whitespace from compilation output
|
56
|
-
|
57
|
-
== Combinations
|
58
73
|
|
59
|
-
|
74
|
+
* *combinations* [{}]:
|
75
|
+
directives for combining the output of many stylesheets and serving them as a single resource
|
76
|
+
|
77
|
+
=== Combinations
|
78
|
+
|
79
|
+
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, ie:
|
80
|
+
|
81
|
+
stylesheet_link_tag 'reset', 'common', 'app_web', :cache => 'web'
|
82
|
+
stylesheet_link_tag 'reset', 'common', 'iui', 'app_mobile', :cache => 'mobile'
|
83
|
+
|
84
|
+
Rack::Less uses combinations, in conjunction with the :cache config setting, to provide this function. Combinations are configured using a hash, where the key is the resource name and the value is an array of names corresponding to stylesheets to combine as the named resource. For the above example, use a configuration like this:
|
85
|
+
|
86
|
+
Rack::Less.configure do |config|
|
87
|
+
config.combinations = {
|
88
|
+
'web' => ['reset', 'common', 'app_web'],
|
89
|
+
'mobile' => ['reset', 'common', 'iui', 'app_mobile']
|
90
|
+
}
|
91
|
+
end
|
60
92
|
|
61
|
-
|
93
|
+
and stylesheet link tags like this, respectively:
|
94
|
+
|
95
|
+
# equivalent to: stylesheet_link_tag 'reset', 'common', 'app_web'
|
96
|
+
stylesheet_link_tag Rack::Less.combinations('web')
|
97
|
+
|
98
|
+
# equivalent to: stylesheet_link_tag 'reset', 'common', 'iui', 'app_mobile'
|
99
|
+
stylesheet_link_tag Rack::Less.combinations('mobile')
|
62
100
|
|
63
|
-
Rack::Less
|
101
|
+
If you configure Rack::Less to cache, with something like this:
|
64
102
|
|
65
|
-
Rack::Less.
|
66
|
-
|
67
|
-
|
103
|
+
Rack::Less.config.cache = true
|
104
|
+
|
105
|
+
then the same stylesheet link tags behave like they have the :cache option set, respectively:
|
68
106
|
|
69
|
-
|
107
|
+
# equivalent to: stylesheet_link_tag 'reset', 'common', 'app_web', :cache => 'web'
|
108
|
+
stylesheet_link_tag Rack::Less.combinations('web')
|
70
109
|
|
71
|
-
stylesheet_link_tag
|
110
|
+
# equivalent to: stylesheet_link_tag 'reset', 'common', 'iui', 'app_mobile', :cache => 'mobile'
|
111
|
+
stylesheet_link_tag Rack::Less.combinations('mobile')
|
72
112
|
|
73
|
-
* *combine* [{}]:
|
74
|
-
directives for combining the ouput of one or more LESS compilations, for example:
|
75
|
-
{ 'app' => ['one', 'two', 'three'] }
|
76
|
-
will direct Rack::Less to respond to a request for app.css with the concatenated output of compiling one.less, two.less, and three.less
|
77
|
-
|
78
113
|
== Links
|
79
114
|
|
80
115
|
GitHub: http://github.com/kelredd/rack-less
|
81
|
-
|
116
|
+
|
82
117
|
Less: http://lesscss.org
|
83
118
|
|
84
119
|
== License
|
data/lib/rack/less.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rack'
|
2
|
+
require 'rack/less/config'
|
2
3
|
require 'rack/less/base'
|
3
4
|
require 'rack/less/options'
|
4
5
|
require 'rack/less/request'
|
@@ -22,15 +23,25 @@ require 'rack/less/source'
|
|
22
23
|
|
23
24
|
module Rack::Less
|
24
25
|
MIME_TYPE = "text/css"
|
26
|
+
@@config = Config.new
|
25
27
|
|
26
28
|
class << self
|
27
29
|
|
28
|
-
#
|
29
|
-
|
30
|
-
|
30
|
+
# Configuration accessors for Rack::Less
|
31
|
+
# (see config.rb for details)
|
32
|
+
def configure
|
33
|
+
yield @@config if block_given?
|
31
34
|
end
|
32
|
-
def
|
33
|
-
|
35
|
+
def config
|
36
|
+
@@config
|
37
|
+
end
|
38
|
+
def config=(value)
|
39
|
+
@@config = value
|
40
|
+
end
|
41
|
+
|
42
|
+
# Combinations config convenience method
|
43
|
+
def combinations(key=nil)
|
44
|
+
@@config.combinations(key)
|
34
45
|
end
|
35
46
|
|
36
47
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Rack::Less
|
2
|
+
|
3
|
+
# Handles configuration for Rack::Less
|
4
|
+
# Available config settings:
|
5
|
+
# :cache
|
6
|
+
# whether to cache the compilation output to
|
7
|
+
# a corresponding static file. Also determines
|
8
|
+
# what value config#combinations(:key) returns
|
9
|
+
# :compress
|
10
|
+
# whether to remove extraneous whitespace from
|
11
|
+
# compilation output
|
12
|
+
# :combinations
|
13
|
+
# Rack::Less uses combinations as directives for
|
14
|
+
# combining the output of many stylesheets and
|
15
|
+
# serving them as a single resource. Combinations
|
16
|
+
# are defined using a hash, where the key is the
|
17
|
+
# resource name and the value is an array of
|
18
|
+
# names specifying the stylesheets to combine
|
19
|
+
# as that resource. For example:
|
20
|
+
# Rack::Less.config.combinations = {
|
21
|
+
# 'web' => ['reset', 'common', 'app_web'],
|
22
|
+
# 'mobile' => ['reset', 'iui', 'common', 'app_mobile']
|
23
|
+
# }
|
24
|
+
class Config
|
25
|
+
|
26
|
+
ATTRIBUTES = [:cache, :compress, :combinations]
|
27
|
+
attr_accessor *ATTRIBUTES
|
28
|
+
|
29
|
+
DEFAULTS = {
|
30
|
+
:cache => false,
|
31
|
+
:compress => false,
|
32
|
+
:combinations => {}
|
33
|
+
}
|
34
|
+
|
35
|
+
def initialize(settings={})
|
36
|
+
ATTRIBUTES.each do |a|
|
37
|
+
instance_variable_set("@#{a}", settings[a] || DEFAULTS[a])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def cache?
|
42
|
+
!!@cache
|
43
|
+
end
|
44
|
+
|
45
|
+
def compress?
|
46
|
+
!!@compress
|
47
|
+
end
|
48
|
+
|
49
|
+
def combinations(key=nil)
|
50
|
+
if key.nil?
|
51
|
+
@combinations
|
52
|
+
else
|
53
|
+
cache? ? key : @combinations[key]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
data/lib/rack/less/options.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Rack::Less
|
2
2
|
module Options
|
3
3
|
|
4
|
-
# Handles options
|
4
|
+
# Handles options for Rack::Less
|
5
5
|
# Available options:
|
6
6
|
# => root
|
7
7
|
# the app root. the reference point for the
|
@@ -14,12 +14,6 @@ module Rack::Less
|
|
14
14
|
# static files are served
|
15
15
|
# => hosted_at
|
16
16
|
# the public HTTP root path for stylesheets
|
17
|
-
# => cache
|
18
|
-
# whether to cache the compilation output to a
|
19
|
-
# corresponding file in the hosted_root
|
20
|
-
# => compress
|
21
|
-
# whether to remove extraneous whitespace from
|
22
|
-
# compilation output
|
23
17
|
|
24
18
|
# Note: the following code is heavily influenced by:
|
25
19
|
# => http://github.com/rtomayko/rack-cache/blob/master/lib/rack/cache/options.rb
|
@@ -35,8 +29,6 @@ module Rack::Less
|
|
35
29
|
option_name(:source) => 'app/stylesheets',
|
36
30
|
option_name(:public) => 'public',
|
37
31
|
option_name(:hosted_at) => '/stylesheets',
|
38
|
-
option_name(:cache) => false,
|
39
|
-
option_name(:compress) => false
|
40
32
|
}
|
41
33
|
end
|
42
34
|
|
@@ -51,21 +43,6 @@ module Rack::Less
|
|
51
43
|
end
|
52
44
|
end
|
53
45
|
|
54
|
-
# Rack::Less uses combinations to combine the output of many stylesheets
|
55
|
-
# and serve them as a single resource. Combinations are specified using
|
56
|
-
# a hash, where the key is the combined resource name and the value is an
|
57
|
-
# array of stylesheets to combine as that resource. For example:
|
58
|
-
# Rack::Less.combinations = {
|
59
|
-
# 'app' => ['one', 'two']
|
60
|
-
# }
|
61
|
-
@@combinations = {}
|
62
|
-
def combinations
|
63
|
-
@@combinations || {}
|
64
|
-
end
|
65
|
-
def combinations=(value={})
|
66
|
-
@@combinations = value
|
67
|
-
end
|
68
|
-
|
69
46
|
end
|
70
47
|
|
71
48
|
module InstanceMethods
|
data/lib/rack/less/request.rb
CHANGED
@@ -43,7 +43,7 @@ module Rack::Less
|
|
43
43
|
# The Rack::Less::Source that the request is for
|
44
44
|
def source
|
45
45
|
@source ||= begin
|
46
|
-
cache = if
|
46
|
+
cache = if Rack::Less.config.cache?
|
47
47
|
File.join(options(:root), options(:public), options(:hosted_at))
|
48
48
|
else
|
49
49
|
nil
|
@@ -51,7 +51,7 @@ module Rack::Less
|
|
51
51
|
source_opts = {
|
52
52
|
:folder => File.join(options(:root), options(:source)),
|
53
53
|
:cache => cache,
|
54
|
-
:compress =>
|
54
|
+
:compress => Rack::Less.config.compress?
|
55
55
|
}
|
56
56
|
Source.new(path_resource_name, source_opts)
|
57
57
|
end
|
data/lib/rack/less/source.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'less'
|
2
|
+
require 'rack/less'
|
2
3
|
|
3
4
|
module Rack::Less
|
4
5
|
|
@@ -27,6 +28,9 @@ module Rack::Less
|
|
27
28
|
def cache?
|
28
29
|
!@cache.nil?
|
29
30
|
end
|
31
|
+
def cache
|
32
|
+
@cache
|
33
|
+
end
|
30
34
|
|
31
35
|
# Use named css sources before using combination sources
|
32
36
|
def files
|
@@ -61,9 +65,9 @@ module Rack::Less
|
|
61
65
|
end
|
62
66
|
|
63
67
|
# Preferred, existing source files matching a corresponding
|
64
|
-
# Rack::Less::
|
68
|
+
# Rack::Less::Config combination directive, if any
|
65
69
|
def combination_sources
|
66
|
-
@combination_sources ||= preferred_sources(
|
70
|
+
@combination_sources ||= preferred_sources(Rack::Less.config.combinations[@css_name] || [])
|
67
71
|
end
|
68
72
|
|
69
73
|
private
|
data/lib/rack/less/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-less
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-09 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- README.rdoc
|
85
85
|
- Rakefile
|
86
86
|
- lib/rack/less/base.rb
|
87
|
+
- lib/rack/less/config.rb
|
87
88
|
- lib/rack/less/options.rb
|
88
89
|
- lib/rack/less/request.rb
|
89
90
|
- lib/rack/less/response.rb
|