rack-less 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,28 +39,17 @@ Add this to your `config/environment.rb`:
39
39
  Add any configs in an initializer (optional - use as necessary):
40
40
 
41
41
  Rack::Less.configure do |config|
42
- config.cache = true
43
- # additional configs ...
42
+ # for example
43
+ config.cache = Rails.configuration.action_controller.perform_caching
44
+ if Rails.env.development?
45
+ config.cache_bust = true
46
+ end
44
47
  end
45
48
 
46
49
  You should now see `Rack::Less` listed in the middleware pipeline:
47
50
 
48
51
  rake middleware
49
52
 
50
- == Available Options
51
-
52
- * :*root* ["."]
53
- - The app root. The reference point for the source and public options.
54
-
55
- * :*source* ['app/stylesheets']
56
- - The path (relative to the root) where LESS source files are located
57
-
58
- * :*public* ['public']
59
- - The path where static files are located
60
-
61
- * :*hosted_at* ['/stylesheets']
62
- - The public HTTP path for hosted stylesheets.
63
-
64
53
  == Available Configurations
65
54
 
66
55
  * .*cache* [false]
@@ -75,15 +64,29 @@ You should now see `Rack::Less` listed in the middleware pipeline:
75
64
  - Directives for combining the output of many stylesheets and serving them as a single resource.
76
65
 
77
66
  * .*cache_bust* [nil]
78
- - Directives for timestamping (cache-busting) while using combinations
67
+ - Directives for timestamping (cache-busting) stylesheet references
79
68
  - :*false* - don't explicitly cache bust (no value added)
80
69
  - :*true* - use Time.now.to_i as the explicit value (will never cache)
81
70
  - :*nil* - change cache bust value if the file is modified (similar to Rails' stylesheet_link_tag)
82
71
  - :*<any other value>* - add the value as "foo.css?<value>"
83
72
 
84
- === Using in layouts
73
+ == Available Options
74
+
75
+ * :*root* ["."]
76
+ - The app root. The reference point for the source and public options.
77
+
78
+ * :*source* ['app/stylesheets']
79
+ - The path (relative to the root) where LESS source files are located
80
+
81
+ * :*public* ['public']
82
+ - The path where static files are located
83
+
84
+ * :*hosted_at* ['/stylesheets']
85
+ - The public HTTP path for hosted stylesheets.
86
+
87
+ == Using in layouts
85
88
 
86
- ==== Cache Busting
89
+ === Cache Busting
87
90
 
88
91
  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
92
 
@@ -92,7 +95,7 @@ To help provide this behavior, Rack::Less provides a helper for generating refer
92
95
  # equivalent to: stylesheet_link_tag 'reset'
93
96
  stylesheet_link_tag Rack::Less.stylesheet('reset')
94
97
 
95
- ==== Combinations
98
+ === Combinations
96
99
 
97
100
  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.
98
101
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
- require 'rake/testtask'
3
+ require 'simple_gem/testtasks'
4
4
 
5
5
  require 'lib/rack/less/version'
6
6
 
@@ -18,10 +18,12 @@ spec = Gem::Specification.new do |s|
18
18
  # s.executables = ['rack-less']
19
19
 
20
20
  s.add_development_dependency("shoulda", [">= 2.10.2"])
21
+ s.add_development_dependency("leftright", [">= 0.0.6"])
21
22
  s.add_development_dependency("sinatra", [">= 0.9.4"])
22
23
  s.add_development_dependency("rack-test", [">= 0.5.3"])
23
24
  s.add_development_dependency("webrat", [">= 0.6.0"])
24
25
  s.add_development_dependency("yui-compressor", [">=0.9.1"])
26
+ s.add_development_dependency("kelredd-simple-gem", [">= 0.7.0"])
25
27
 
26
28
  s.add_dependency("rack", [">= 0.4"])
27
29
  s.add_dependency("less", [">= 1.2.21"])
@@ -31,28 +33,7 @@ Rake::GemPackageTask.new(spec) do |pkg|
31
33
  pkg.gem_spec = spec
32
34
  end
33
35
 
34
- Rake::TestTask.new do |t|
35
- t.libs << 'test'
36
- t.test_files = FileList["test/**/*_test.rb"]
37
- t.verbose = true
38
- end
39
-
40
- begin
41
- require 'rcov/rcovtask'
42
-
43
- Rcov::RcovTask.new(:coverage) do |t|
44
- t.libs = ['test']
45
- t.test_files = FileList["test/**/*_test.rb"]
46
- t.verbose = true
47
- t.rcov_opts = ['--text-report', "-x #{Gem.path}", '-x /Library/Ruby', '-x /usr/lib/ruby']
48
- end
49
-
50
- task :default => :coverage
51
-
52
- rescue LoadError
53
- warn "\n**** Install rcov (sudo gem install relevance-rcov) to get coverage stats ****\n"
54
- task :default => :test
55
- end
36
+ SimpleGem::TestTasks.new
56
37
 
57
38
  desc 'Generate the gemspec to serve this gem'
58
39
  task :gemspec do
@@ -60,3 +41,5 @@ task :gemspec do
60
41
  File.open(file, 'w') {|f| f << spec.to_ruby }
61
42
  puts "Created gemspec: #{file}"
62
43
  end
44
+
45
+ task :default => :gem
@@ -33,16 +33,16 @@ module Rack::Less
33
33
  def call!(env)
34
34
  @default_options.each { |k,v| env[k] ||= v }
35
35
  @env = env
36
-
36
+
37
37
  if (@request = Request.new(@env.dup.freeze)).for_less?
38
38
  Response.new(@env.dup.freeze, @request.source.to_css).to_rack
39
39
  else
40
40
  @app.call(env)
41
41
  end
42
42
  end
43
-
43
+
44
44
  private
45
-
45
+
46
46
  def validate_options
47
47
  # ensure a root path is specified and does exists
48
48
  unless options.has_key?(option_name(:root)) and !options(:root).nil?
@@ -55,6 +55,6 @@ module Rack::Less
55
55
  raise(ArgumentError, "no :source option set")
56
56
  end
57
57
  end
58
-
58
+
59
59
  end
60
60
  end
@@ -12,7 +12,7 @@ module Rack::Less
12
12
 
13
13
  class Request < Rack::Request
14
14
  include Rack::Less::Options
15
-
15
+
16
16
  CSS_PATH_FORMATS = ['.css']
17
17
 
18
18
  # The HTTP request method. This is the standard implementation of this
@@ -22,21 +22,25 @@ module Rack::Less
22
22
  def request_method
23
23
  @env['REQUEST_METHOD']
24
24
  end
25
-
25
+
26
26
  def path_info
27
27
  @env['PATH_INFO']
28
28
  end
29
-
29
+
30
30
  def http_accept
31
31
  @env['HTTP_ACCEPT']
32
32
  end
33
-
33
+
34
+ def path_resource_format
35
+ File.extname(path_info)
36
+ end
37
+
34
38
  def path_resource_name
35
39
  File.basename(path_info, path_resource_format)
36
40
  end
37
-
38
- def path_resource_format
39
- File.extname(path_info)
41
+
42
+ def path_resource_source
43
+ File.join(File.dirname(path_info).gsub(/#{options(:hosted_at)}/, ''), path_resource_name).gsub(/^\//, '')
40
44
  end
41
45
 
42
46
  def cache
@@ -51,7 +55,7 @@ module Rack::Less
51
55
  :cache => Rack::Less.config.cache? ? cache : nil,
52
56
  :compress => Rack::Less.config.compress?
53
57
  }
54
- Source.new(path_resource_name, source_opts)
58
+ Source.new(path_resource_source, source_opts)
55
59
  end
56
60
  end
57
61
 
@@ -62,11 +66,11 @@ module Rack::Less
62
66
  end
63
67
 
64
68
  def hosted_at?
65
- File.basename(File.dirname(path_info)) == File.basename(options(:hosted_at))
69
+ path_info =~ /^#{options(:hosted_at)}\//
66
70
  end
67
-
71
+
68
72
  def exists?
69
- File.exists?(File.join(cache, "#{path_resource_name}#{path_resource_format}"))
73
+ File.exists?(File.join(cache, "#{path_resource_source}#{path_resource_format}"))
70
74
  end
71
75
 
72
76
  # Determine if the request is for existing LESS CSS file
@@ -81,6 +85,6 @@ module Rack::Less
81
85
  !exists? &&
82
86
  !source.files.empty?
83
87
  end
84
-
88
+
85
89
  end
86
90
  end
@@ -14,22 +14,22 @@ module Rack::Less
14
14
  # to compile and a path to the source files,
15
15
  # will returns corresponding compiled LESS CSS
16
16
  class Source
17
-
17
+
18
18
  # prefer source files with the .less extension
19
19
  # but also accept files with the .css extension
20
20
  PREFERRED_EXTENSIONS = [:less, :css]
21
-
21
+
22
22
  YUI_OPTS = {}
23
-
24
- attr_reader :css_name
25
-
26
- def initialize(css_name, options={})
27
- @css_name = css_name
23
+
24
+ attr_reader :path
25
+
26
+ def initialize(path, options={})
27
+ @path = path
28
28
  @compress = options[:compress]
29
29
  @cache = options[:cache]
30
30
  @folder = get_required_path(options, :folder)
31
31
  end
32
-
32
+
33
33
  def compress?
34
34
  !!@compress
35
35
  end
@@ -39,18 +39,18 @@ module Rack::Less
39
39
  def cache
40
40
  @cache
41
41
  end
42
-
42
+
43
43
  # Use named css sources before using combination sources
44
44
  def files
45
45
  @files ||= (css_sources.empty? ? combination_sources : css_sources)
46
46
  end
47
-
47
+
48
48
  def compiled
49
49
  @compiled ||= begin
50
50
  compiled_css = files.collect do |file_path|
51
51
  Less::Engine.new(File.new(file_path)).to_css
52
52
  end.join("\n")
53
-
53
+
54
54
  compiled_css = case @compress
55
55
  when :whitespace, true
56
56
  compiled_css.delete("\n")
@@ -64,58 +64,58 @@ module Rack::Less
64
64
  compiled_css
65
65
  end
66
66
 
67
- if cache? && !File.exists?(cf = File.join(@cache, "#{@css_name}.css"))
67
+ if cache? && !File.exists?(cf = File.join(@cache, "#{@path}.css"))
68
68
  FileUtils.mkdir_p(@cache)
69
69
  File.open(cf, "w") do |file|
70
70
  file.write(compiled_css)
71
71
  end
72
72
  end
73
-
73
+
74
74
  compiled_css
75
75
  end
76
76
  end
77
77
  alias_method :to_css, :compiled
78
78
  alias_method :css, :compiled
79
-
79
+
80
80
  protected
81
-
81
+
82
82
  # Preferred, existing source files matching the css name
83
83
  def css_sources
84
- @css_sources ||= preferred_sources([@css_name])
84
+ @css_sources ||= preferred_sources([@path])
85
85
  end
86
-
86
+
87
87
  # Preferred, existing source files matching a corresponding
88
88
  # Rack::Less::Config combination directive, if any
89
89
  def combination_sources
90
- @combination_sources ||= preferred_sources(Rack::Less.config.combinations[@css_name] || [])
90
+ @combination_sources ||= preferred_sources(Rack::Less.config.combinations[@path] || [])
91
91
  end
92
-
92
+
93
93
  private
94
-
95
- # Given a list of file names, return a list of
96
- # existing source files with the corresponding names
94
+
95
+ # Given a list of sources, return a list of
96
+ # existing source files with the corresponding source paths
97
97
  # honoring the preferred extension list
98
- def preferred_sources(file_names)
99
- file_names.collect do |name|
98
+ def preferred_sources(paths)
99
+ paths.collect do |source_path|
100
100
  PREFERRED_EXTENSIONS.inject(nil) do |source_file, extension|
101
101
  source_file || begin
102
- path = File.join(@folder, "#{name}.#{extension}")
102
+ path = File.join(@folder, "#{source_path}.#{extension}")
103
103
  File.exists?(path) ? path : nil
104
104
  end
105
105
  end
106
106
  end.compact
107
107
  end
108
-
108
+
109
109
  def get_required_path(options, path_key)
110
110
  unless options.has_key?(path_key)
111
111
  raise(ArgumentError, "no :#{path_key} option specified")
112
112
  end
113
113
  unless File.exists?(options[path_key])
114
- raise(ArgumentError, "the :#{path_key} ('#{options[path_key]}') does not exist")
114
+ raise(ArgumentError, "the :#{path_key} ('#{options[path_key]}') does not exist")
115
115
  end
116
116
  options[path_key]
117
117
  end
118
-
118
+
119
119
  end
120
-
120
+
121
121
  end
@@ -2,7 +2,7 @@ module RackLess
2
2
  module Version
3
3
 
4
4
  MAJOR = 1
5
- MINOR = 4
5
+ MINOR = 5
6
6
  TINY = 0
7
7
 
8
8
  def self.to_s # :nodoc:
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-less
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 1.4.0
10
+ version: 1.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-08 00:00:00 -05:00
18
+ date: 2010-09-25 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -35,9 +35,25 @@ dependencies:
35
35
  type: :development
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: sinatra
38
+ name: leftright
39
39
  prerelease: false
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 19
46
+ segments:
47
+ - 0
48
+ - 0
49
+ - 6
50
+ version: 0.0.6
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: sinatra
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
41
57
  none: false
42
58
  requirements:
43
59
  - - ">="
@@ -49,11 +65,11 @@ dependencies:
49
65
  - 4
50
66
  version: 0.9.4
51
67
  type: :development
52
- version_requirements: *id002
68
+ version_requirements: *id003
53
69
  - !ruby/object:Gem::Dependency
54
70
  name: rack-test
55
71
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
72
+ requirement: &id004 !ruby/object:Gem::Requirement
57
73
  none: false
58
74
  requirements:
59
75
  - - ">="
@@ -65,11 +81,11 @@ dependencies:
65
81
  - 3
66
82
  version: 0.5.3
67
83
  type: :development
68
- version_requirements: *id003
84
+ version_requirements: *id004
69
85
  - !ruby/object:Gem::Dependency
70
86
  name: webrat
71
87
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
88
+ requirement: &id005 !ruby/object:Gem::Requirement
73
89
  none: false
74
90
  requirements:
75
91
  - - ">="
@@ -81,11 +97,11 @@ dependencies:
81
97
  - 0
82
98
  version: 0.6.0
83
99
  type: :development
84
- version_requirements: *id004
100
+ version_requirements: *id005
85
101
  - !ruby/object:Gem::Dependency
86
102
  name: yui-compressor
87
103
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
104
+ requirement: &id006 !ruby/object:Gem::Requirement
89
105
  none: false
90
106
  requirements:
91
107
  - - ">="
@@ -97,11 +113,27 @@ dependencies:
97
113
  - 1
98
114
  version: 0.9.1
99
115
  type: :development
100
- version_requirements: *id005
116
+ version_requirements: *id006
117
+ - !ruby/object:Gem::Dependency
118
+ name: kelredd-simple-gem
119
+ prerelease: false
120
+ requirement: &id007 !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ - 7
129
+ - 0
130
+ version: 0.7.0
131
+ type: :development
132
+ version_requirements: *id007
101
133
  - !ruby/object:Gem::Dependency
102
134
  name: rack
103
135
  prerelease: false
104
- requirement: &id006 !ruby/object:Gem::Requirement
136
+ requirement: &id008 !ruby/object:Gem::Requirement
105
137
  none: false
106
138
  requirements:
107
139
  - - ">="
@@ -112,11 +144,11 @@ dependencies:
112
144
  - 4
113
145
  version: "0.4"
114
146
  type: :runtime
115
- version_requirements: *id006
147
+ version_requirements: *id008
116
148
  - !ruby/object:Gem::Dependency
117
149
  name: less
118
150
  prerelease: false
119
- requirement: &id007 !ruby/object:Gem::Requirement
151
+ requirement: &id009 !ruby/object:Gem::Requirement
120
152
  none: false
121
153
  requirements:
122
154
  - - ">="
@@ -128,7 +160,7 @@ dependencies:
128
160
  - 21
129
161
  version: 1.2.21
130
162
  type: :runtime
131
- version_requirements: *id007
163
+ version_requirements: *id009
132
164
  description:
133
165
  email: kelly@kelredd.com
134
166
  executables: []