less-rails 3.0.0 → 4.0.0.rc1
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.
- checksums.yaml +5 -5
- data/.travis.yml +15 -5
- data/Appraisals +10 -5
- data/CHANGELOG.md +9 -0
- data/README.md +2 -2
- data/gemfiles/rails40.gemfile +1 -1
- data/gemfiles/rails41.gemfile +1 -1
- data/gemfiles/rails42.gemfile +1 -1
- data/gemfiles/rails50.gemfile +1 -1
- data/gemfiles/rails51.gemfile +1 -1
- data/gemfiles/sprockets2.gemfile +11 -0
- data/less-rails.gemspec +2 -4
- data/lib/less/rails.rb +1 -2
- data/lib/less/rails/helpers.rb +26 -26
- data/lib/less/rails/import_processor.rb +34 -17
- data/lib/less/rails/less_transformer.rb +64 -0
- data/lib/less/rails/railtie.rb +4 -4
- data/lib/less/rails/version.rb +1 -1
- data/test/cases/basics_spec.rb +29 -11
- data/test/cases/railtie_spec.rb +2 -4
- data/test/dummy_app/app/assets/stylesheets/basics.css.less +1 -1
- data/test/dummy_app/app/assets/stylesheets/frameworks/bootstrap/mixins.less +1 -1
- data/test/spec_helper.rb +57 -28
- metadata +11 -44
- data/lib/less/rails/template_handlers.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f7462e71d3003a08493070bdf07ae17173f1fcc4f6c63b34d5485cd677ac435e
|
4
|
+
data.tar.gz: 8166ded508b910756336c5870bd08e8ae5bab723f6b0ec5d203d2f8719a48790
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9e0f1df16be8a892a67e3737e034a8bf9af9dc49cf70ab476b4ebe8ae10fd451d7afd7b282b546926cc0efc6e70d8599ba24634c7b519a6a0e2654d3e5ff4e4
|
7
|
+
data.tar.gz: 81165f7e7baf698ba2dc1c1059358e63f08d762cd905a11226d0e4b607c516ed18333633737115aaa43c76f75b2f8aa2e18abb4eaf26deb5a2b43a3c153eb729
|
data/.travis.yml
CHANGED
@@ -5,13 +5,15 @@ rvm:
|
|
5
5
|
- 1.9.3-p551
|
6
6
|
- 2.0.0-p648
|
7
7
|
- 2.1.10
|
8
|
-
- 2.2.
|
9
|
-
- 2.3.
|
10
|
-
- 2.4.
|
8
|
+
- 2.2.9
|
9
|
+
- 2.3.6
|
10
|
+
- 2.4.3
|
11
|
+
- 2.5.0
|
11
12
|
- jruby-9.1.9.0
|
12
13
|
before_install:
|
13
14
|
- gem install bundler
|
14
15
|
gemfile:
|
16
|
+
- gemfiles/sprockets2.gemfile
|
15
17
|
- gemfiles/rails40.gemfile
|
16
18
|
- gemfiles/rails41.gemfile
|
17
19
|
- gemfiles/rails42.gemfile
|
@@ -31,7 +33,15 @@ matrix:
|
|
31
33
|
gemfile: gemfiles/rails50.gemfile
|
32
34
|
- rvm: 2.1.10
|
33
35
|
gemfile: gemfiles/rails51.gemfile
|
34
|
-
- rvm: 2.4.
|
36
|
+
- rvm: 2.4.3
|
37
|
+
gemfile: gemfiles/sprockets2.gemfile
|
38
|
+
- rvm: 2.4.3
|
35
39
|
gemfile: gemfiles/rails40.gemfile
|
36
|
-
- rvm: 2.4.
|
40
|
+
- rvm: 2.4.3
|
41
|
+
gemfile: gemfiles/rails41.gemfile
|
42
|
+
- rvm: 2.5.0
|
43
|
+
gemfile: gemfiles/sprockets2.gemfile
|
44
|
+
- rvm: 2.5.0
|
45
|
+
gemfile: gemfiles/rails40.gemfile
|
46
|
+
- rvm: 2.5.0
|
37
47
|
gemfile: gemfiles/rails41.gemfile
|
data/Appraisals
CHANGED
@@ -1,19 +1,24 @@
|
|
1
|
+
appraise 'sprockets2' do
|
2
|
+
gem 'rails', '~> 4.0.0'
|
3
|
+
gem 'sprockets', '~> 2.0'
|
4
|
+
end
|
5
|
+
|
1
6
|
appraise 'rails40' do
|
2
|
-
gem 'rails', '~> 4.0.
|
7
|
+
gem 'rails', '~> 4.0.0'
|
3
8
|
end
|
4
9
|
|
5
10
|
appraise 'rails41' do
|
6
|
-
gem 'rails', '~> 4.1.
|
11
|
+
gem 'rails', '~> 4.1.0'
|
7
12
|
end
|
8
13
|
|
9
14
|
appraise 'rails42' do
|
10
|
-
gem 'rails', '~> 4.2.
|
15
|
+
gem 'rails', '~> 4.2.0'
|
11
16
|
end
|
12
17
|
|
13
18
|
appraise 'rails50' do
|
14
|
-
gem 'rails', '~> 5.0.
|
19
|
+
gem 'rails', '~> 5.0.0'
|
15
20
|
end
|
16
21
|
|
17
22
|
appraise 'rails51' do
|
18
|
-
gem 'rails', '~> 5.1.
|
23
|
+
gem 'rails', '~> 5.1.0'
|
19
24
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
### 4.0.0 - 2018-08-24
|
4
|
+
|
5
|
+
* The import scanner now takes into account multiple [import options](http://lesscss.org/features/#import-atrules-feature-import-options).
|
6
|
+
* Removed Tilt and Grease as dependencies.
|
7
|
+
* **Breaking Change**: If you are requiring your less files using the extension, e.g:
|
8
|
+
`*= require semantic_ui/definitions/modules/accordion.less`
|
9
|
+
you need to remove the extension like so:
|
10
|
+
`*= require semantic_ui/definitions/modules/accordion`
|
11
|
+
|
3
12
|
### 3.0.0 - 2017-10-02
|
4
13
|
|
5
14
|
* Solve deprecation warning via Grease adapter!
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ This gem provides integration for Rails projects using the Less stylesheet langu
|
|
10
10
|
Just bundle up less-rails in your Gemfile. This will pull in less as a runtime dependency too.
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
gem 'less-rails', '~>
|
13
|
+
gem 'less-rails', '~> 4.0.0'
|
14
14
|
```
|
15
15
|
|
16
16
|
But be warned, less.rb relies on a JavaScript runtime gem too. Just like ExecJS, it will look for a gem that is appropriate to your system. Typically, this means you will need one of the following.
|
@@ -125,7 +125,7 @@ We also have a generator for rails scaffold CSS. Just like the Sass gem, we simp
|
|
125
125
|
|
126
126
|
## Contributing
|
127
127
|
|
128
|
-
This gem is fully tested from Rails 4.0 to Rails 5.1. We run our tests on [Travis CI](http://travis-ci.org/metaskills/less-rails) in both Ruby 1.9, 2.
|
128
|
+
This gem is fully tested from Rails 4.0 to Rails 5.1. We run our tests on [Travis CI](http://travis-ci.org/metaskills/less-rails) in both Ruby 1.9, 2.x, and JRuby 9000. If you detect a problem, open up a github issue or fork the repo and help out. After you fork or clone the repository, the following commands will get you up and running on the test suite.
|
129
129
|
|
130
130
|
```shell
|
131
131
|
$ bundle
|
data/gemfiles/rails40.gemfile
CHANGED
@@ -5,6 +5,6 @@ source "https://rubygems.org"
|
|
5
5
|
gem "therubyracer", "~> 0.12.0", require: nil, platforms: :ruby
|
6
6
|
gem "therubyrhino", "~> 2.0.2", require: nil, platforms: :jruby
|
7
7
|
gem "mime-types", "~> 2.6.2", platforms: [:ruby_19, :jruby]
|
8
|
-
gem "rails", "~> 4.0.
|
8
|
+
gem "rails", "~> 4.0.0"
|
9
9
|
|
10
10
|
gemspec path: "../"
|
data/gemfiles/rails41.gemfile
CHANGED
@@ -5,6 +5,6 @@ source "https://rubygems.org"
|
|
5
5
|
gem "therubyracer", "~> 0.12.0", require: nil, platforms: :ruby
|
6
6
|
gem "therubyrhino", "~> 2.0.2", require: nil, platforms: :jruby
|
7
7
|
gem "mime-types", "~> 2.6.2", platforms: [:ruby_19, :jruby]
|
8
|
-
gem "rails", "~> 4.1.
|
8
|
+
gem "rails", "~> 4.1.0"
|
9
9
|
|
10
10
|
gemspec path: "../"
|
data/gemfiles/rails42.gemfile
CHANGED
@@ -5,6 +5,6 @@ source "https://rubygems.org"
|
|
5
5
|
gem "therubyracer", "~> 0.12.0", require: nil, platforms: :ruby
|
6
6
|
gem "therubyrhino", "~> 2.0.2", require: nil, platforms: :jruby
|
7
7
|
gem "mime-types", "~> 2.6.2", platforms: [:ruby_19, :jruby]
|
8
|
-
gem "rails", "~> 4.2.
|
8
|
+
gem "rails", "~> 4.2.0"
|
9
9
|
|
10
10
|
gemspec path: "../"
|
data/gemfiles/rails50.gemfile
CHANGED
@@ -5,6 +5,6 @@ source "https://rubygems.org"
|
|
5
5
|
gem "therubyracer", "~> 0.12.0", require: nil, platforms: :ruby
|
6
6
|
gem "therubyrhino", "~> 2.0.2", require: nil, platforms: :jruby
|
7
7
|
gem "mime-types", "~> 2.6.2", platforms: [:ruby_19, :jruby]
|
8
|
-
gem "rails", "~> 5.0.
|
8
|
+
gem "rails", "~> 5.0.0"
|
9
9
|
|
10
10
|
gemspec path: "../"
|
data/gemfiles/rails51.gemfile
CHANGED
@@ -5,6 +5,6 @@ source "https://rubygems.org"
|
|
5
5
|
gem "therubyracer", "~> 0.12.0", require: nil, platforms: :ruby
|
6
6
|
gem "therubyrhino", "~> 2.0.2", require: nil, platforms: :jruby
|
7
7
|
gem "mime-types", "~> 2.6.2", platforms: [:ruby_19, :jruby]
|
8
|
-
gem "rails", "~> 5.1.
|
8
|
+
gem "rails", "~> 5.1.0"
|
9
9
|
|
10
10
|
gemspec path: "../"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "therubyracer", "~> 0.12.0", require: nil, platforms: :ruby
|
6
|
+
gem "therubyrhino", "~> 2.0.2", require: nil, platforms: :jruby
|
7
|
+
gem "mime-types", "~> 2.6.2", platforms: [:ruby_19, :jruby]
|
8
|
+
gem "rails", "~> 4.0.0"
|
9
|
+
gem "sprockets", "~> 2.0"
|
10
|
+
|
11
|
+
gemspec path: "../"
|
data/less-rails.gemspec
CHANGED
@@ -16,10 +16,8 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
gem.require_paths = ["lib"]
|
18
18
|
gem.add_runtime_dependency 'less', '~> 2.6.0'
|
19
|
-
gem.add_runtime_dependency 'actionpack', '>= 4
|
20
|
-
gem.add_runtime_dependency '
|
21
|
-
gem.add_runtime_dependency 'grease'
|
22
|
-
gem.add_runtime_dependency 'sprockets', '> 2', '< 4'
|
19
|
+
gem.add_runtime_dependency 'actionpack', '>= 4'
|
20
|
+
gem.add_runtime_dependency 'sprockets', '>= 2'
|
23
21
|
gem.add_development_dependency 'appraisal'
|
24
22
|
gem.add_development_dependency 'minitest'
|
25
23
|
gem.add_development_dependency 'guard'
|
data/lib/less/rails.rb
CHANGED
@@ -5,7 +5,6 @@ end
|
|
5
5
|
|
6
6
|
require 'less'
|
7
7
|
require 'rails'
|
8
|
-
require 'tilt'
|
9
8
|
require 'sprockets'
|
10
9
|
begin
|
11
10
|
require 'sprockets/railtie'
|
@@ -15,6 +14,6 @@ end
|
|
15
14
|
|
16
15
|
require 'less/rails/version'
|
17
16
|
require 'less/rails/helpers'
|
18
|
-
require 'less/rails/
|
17
|
+
require 'less/rails/less_transformer'
|
19
18
|
require 'less/rails/import_processor'
|
20
19
|
require 'less/rails/railtie'
|
data/lib/less/rails/helpers.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Less
|
2
|
-
|
2
|
+
|
3
3
|
def self.less
|
4
4
|
@less
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def self.register_rails_helper(name, &block)
|
8
8
|
tree = @loader.require('less/tree')
|
9
9
|
tree.functions[name] = lambda do |*args|
|
@@ -12,12 +12,12 @@ module Less
|
|
12
12
|
tree[:Anonymous].new block.call(tree, args.last)
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
module Rails
|
17
17
|
module Helpers
|
18
|
-
|
18
|
+
|
19
19
|
extend ActiveSupport::Concern
|
20
|
-
|
20
|
+
|
21
21
|
included do
|
22
22
|
Less.register_rails_helper('asset-path') { |tree, cxt| asset_path unquote(cxt.toCSS()) }
|
23
23
|
Less.register_rails_helper('asset-url') { |tree, cxt| asset_url unquote(cxt.toCSS()) }
|
@@ -35,21 +35,21 @@ module Less
|
|
35
35
|
Less.register_rails_helper('font-url') { |tree, cxt| font_url unquote(cxt.toCSS()) }
|
36
36
|
Less.register_rails_helper('asset-data-url') { |tree, cxt| asset_data_url unquote(cxt.toCSS()) }
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
module ClassMethods
|
40
|
-
|
40
|
+
|
41
41
|
def asset_data_url(path)
|
42
42
|
"url(#{scope.asset_data_uri(path)})"
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def asset_path(asset)
|
46
46
|
public_path(asset).inspect
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def asset_url(asset)
|
50
50
|
"url(#{public_path(asset)})"
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def image_path(img)
|
54
54
|
scope.image_path(img).inspect
|
55
55
|
end
|
@@ -61,31 +61,31 @@ module Less
|
|
61
61
|
def video_path(video)
|
62
62
|
scope.video_path(video).inspect
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def video_url(video)
|
66
66
|
"url(#{scope.video_path(video)})"
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def audio_path(audio)
|
70
70
|
scope.audio_path(audio).inspect
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def audio_url(audio)
|
74
74
|
"url(#{scope.audio_path(audio)})"
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def javascript_path(javascript)
|
78
78
|
scope.javascript_path(javascript).inspect
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
def javascript_url(javascript)
|
82
82
|
"url(#{scope.javascript_path(javascript)})"
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
def stylesheet_path(stylesheet)
|
86
86
|
scope.stylesheet_path(stylesheet).inspect
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
def stylesheet_url(stylesheet)
|
90
90
|
"url(#{scope.stylesheet_path(stylesheet)})"
|
91
91
|
end
|
@@ -97,7 +97,7 @@ module Less
|
|
97
97
|
asset_path(font)
|
98
98
|
end
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
def font_url(font)
|
102
102
|
if scope.respond_to?(:font_path)
|
103
103
|
"url(#{scope.font_path(font)})"
|
@@ -105,13 +105,13 @@ module Less
|
|
105
105
|
asset_url(font)
|
106
106
|
end
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
private
|
110
|
-
|
110
|
+
|
111
111
|
def scope
|
112
112
|
Less.Parser['scope']
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
def public_path(asset)
|
116
116
|
if scope.respond_to?(:asset_paths)
|
117
117
|
scope.asset_paths.compute_public_path asset, ::Rails.application.config.assets.prefix
|
@@ -119,18 +119,18 @@ module Less
|
|
119
119
|
scope.path_to_asset(asset)
|
120
120
|
end
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
def context_asset_data_uri(path)
|
124
|
-
|
124
|
+
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
def unquote(str)
|
128
128
|
s = str.to_s.strip
|
129
129
|
s =~ /^['"](.*?)['"]$/ ? $1 : s
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
@@ -1,32 +1,49 @@
|
|
1
|
-
module Less
|
2
|
-
module Rails
|
3
|
-
class ImportProcessor
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Less
|
2
|
+
module Rails
|
3
|
+
class ImportProcessor
|
4
|
+
|
5
|
+
# http://lesscss.org/features/#import-options
|
6
|
+
IMPORT_SCANNER = /@import\s*(?:\([a-z, ]+\))*\s*['"]([^'"]+)['"]\s*;/.freeze
|
7
|
+
|
8
|
+
PATHNAME_FINDER = Proc.new do |scope, path|
|
7
9
|
begin
|
8
10
|
scope.resolve(path)
|
9
11
|
rescue Sprockets::FileNotFound
|
10
12
|
nil
|
11
13
|
end
|
12
|
-
}
|
13
|
-
|
14
|
-
def prepare
|
15
14
|
end
|
16
|
-
|
17
|
-
def
|
18
|
-
|
19
|
-
|
15
|
+
|
16
|
+
def initialize(filename, &block)
|
17
|
+
@filename = filename
|
18
|
+
@source = block.call
|
19
|
+
end
|
20
|
+
|
21
|
+
def render(scope, locals)
|
22
|
+
self.class.evaluate(@filename, @source, scope)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.evaluate(filename, source, scope)
|
26
|
+
depend_on scope, source
|
27
|
+
source
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.call(input)
|
31
|
+
filename = input[:filename]
|
32
|
+
source = input[:data]
|
33
|
+
scope = input[:environment].context_class.new(input)
|
34
|
+
|
35
|
+
result = evaluate(filename, source, scope)
|
36
|
+
scope.metadata.merge(data: result)
|
20
37
|
end
|
21
38
|
|
22
|
-
def depend_on(scope,
|
23
|
-
import_paths =
|
39
|
+
def self.depend_on(scope, source, base=File.dirname(scope.logical_path))
|
40
|
+
import_paths = source.scan(IMPORT_SCANNER).flatten.compact.uniq
|
24
41
|
import_paths.each do |path|
|
25
|
-
pathname = PATHNAME_FINDER.call(scope,path) || PATHNAME_FINDER.call(scope, File.join(base, path))
|
42
|
+
pathname = PATHNAME_FINDER.call(scope, path) || PATHNAME_FINDER.call(scope, File.join(base, path))
|
26
43
|
scope.depend_on(pathname) if pathname && pathname.to_s.ends_with?('.less')
|
27
44
|
depend_on scope, File.read(pathname), File.dirname(path) if pathname
|
28
45
|
end
|
29
|
-
|
46
|
+
source
|
30
47
|
end
|
31
48
|
|
32
49
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Less
|
2
|
+
module Rails
|
3
|
+
class LessTransformer
|
4
|
+
include Helpers
|
5
|
+
|
6
|
+
TO_CSS_KEYS = [:compress, :optimization, :silent, :color]
|
7
|
+
|
8
|
+
def initialize(filename, &block)
|
9
|
+
@filename = filename
|
10
|
+
@source = block.call
|
11
|
+
end
|
12
|
+
|
13
|
+
def render(scope, locals)
|
14
|
+
self.class.evaluate(@filename, @source, scope)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.evaluate(filename, source, scope)
|
18
|
+
Less.Parser['scope'] = scope
|
19
|
+
parser = ::Less::Parser.new config_to_less_parser_options(filename, scope)
|
20
|
+
engine = parser.parse(source)
|
21
|
+
engine.to_css config_to_css_options(scope)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.call(input)
|
25
|
+
filename = input[:filename]
|
26
|
+
source = input[:data]
|
27
|
+
scope = input[:environment].context_class.new(input)
|
28
|
+
|
29
|
+
result = evaluate(filename, source, scope)
|
30
|
+
scope.metadata.merge(data: result)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.default_mime_type
|
34
|
+
'text/css'
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def self.config_to_less_parser_options(filename, scope)
|
40
|
+
paths = config_paths(scope) + scope.environment.paths
|
41
|
+
local_path = scope.pathname.dirname
|
42
|
+
paths += [local_path] unless paths.include? local_path
|
43
|
+
{:filename => filename, :paths => paths, :dumpLineNumbers => config_from_rails(scope).line_numbers}.merge(config_raw(scope))
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.config_to_css_options(scope)
|
47
|
+
Hash[config_from_rails(scope).each.to_a].slice *TO_CSS_KEYS
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.config_paths(scope)
|
51
|
+
config_from_rails(scope)[:paths]
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.config_raw(scope)
|
55
|
+
config_from_rails(scope)[:raw]
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.config_from_rails(scope)
|
59
|
+
scope.environment.context_class.less_config
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/less/rails/railtie.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'less'
|
2
|
-
require 'grease'
|
3
2
|
require 'sprockets/railtie'
|
4
3
|
|
5
4
|
module Less
|
@@ -14,20 +13,21 @@ module Less
|
|
14
13
|
config.before_initialize do |app|
|
15
14
|
sprockets_env = app.assets || Sprockets
|
16
15
|
if sprockets_env.respond_to?(:register_engine)
|
17
|
-
args = ['.less',
|
16
|
+
args = ['.less', LessTransformer]
|
18
17
|
args << { mime_type: 'text/less', silence_deprecation: true } if Sprockets::VERSION.start_with?("3")
|
19
18
|
sprockets_env.register_engine(*args)
|
20
19
|
end
|
21
20
|
|
22
21
|
if sprockets_env.respond_to?(:register_transformer)
|
23
22
|
sprockets_env.register_mime_type 'text/less', extensions: ['.less', '.less.erb', '.less.css'], charset: :css
|
24
|
-
sprockets_env.
|
23
|
+
sprockets_env.register_preprocessor 'text/less', Sprockets::DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
|
24
|
+
sprockets_env.register_transformer 'text/less', 'text/css', LessTransformer
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
initializer 'less-rails.before.load_config_initializers', :before => :load_config_initializers, :group => :all do |app|
|
29
29
|
sprockets_env = app.assets || Sprockets
|
30
|
-
sprockets_env.register_preprocessor 'text/css',
|
30
|
+
sprockets_env.register_preprocessor 'text/css', ImportProcessor
|
31
31
|
|
32
32
|
config.assets.configure do |env|
|
33
33
|
env.context_class.class_eval do
|
data/lib/less/rails/version.rb
CHANGED
data/test/cases/basics_spec.rb
CHANGED
@@ -1,36 +1,54 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class BasicsSpec < Less::Rails::Spec
|
4
|
-
|
4
|
+
|
5
5
|
it 'must render variables' do
|
6
6
|
basics.must_match %r{#test-variable\{color:#4d926f\}}
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it 'must render mixins' do
|
10
10
|
basics.must_match %r{#test-mixin span\{border:1px solid black\}}
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it 'must be able to use vendored less files' do
|
14
14
|
basics.must_match %r{#test-vendored\{border-radius:10px\}}
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
describe 'less import dependency hooks' do
|
18
|
-
|
18
|
+
|
19
19
|
it 'must update when imported file changes' do
|
20
20
|
basics.must_match %r{#test-radiused\{border-radius:5px\}}, 'default is 5px'
|
21
21
|
safely_edit(:mixins) do |data, asset|
|
22
|
-
data.gsub! '5px', '
|
22
|
+
data.gsub! '5px', '8px'
|
23
23
|
File.open(asset.pathname,'w') { |f| f.write(data) }
|
24
|
-
basics.must_match %r{#test-radiused\{border-radius:
|
24
|
+
basics.must_match %r{#test-radiused\{border-radius:8px\}}, 'mixins.less should be a sprockets context dependency'
|
25
|
+
|
26
|
+
data.gsub! '8px', '15px'
|
27
|
+
File.open(asset.pathname,'w') { |f| f.write(data) }
|
28
|
+
|
29
|
+
# Force a recompile
|
30
|
+
# https://github.com/rails/sprockets/blob/master/test/shared_sass_tests.rb#L164
|
31
|
+
mtime = Time.now + 1
|
32
|
+
File.utime(mtime, mtime, asset.pathname)
|
33
|
+
|
34
|
+
basics.must_match %r{#test-radiused\{border-radius:15px\}}, 'mixins.less should be a sprockets context dependency'
|
25
35
|
end
|
26
36
|
end
|
27
|
-
|
37
|
+
|
28
38
|
it 'must update when an imported file of another imported file changes' do
|
29
39
|
basics.must_match %r{#test-variable-colored\{color:#424242\}}, 'default is #424242'
|
30
40
|
safely_edit(:variables) do |data, asset|
|
31
41
|
data.gsub! '424242', '666666'
|
32
42
|
File.open(asset.pathname,'w') { |f| f.write(data) }
|
33
43
|
basics.must_match %r{#test-variable-colored\{color:#666\}}, 'variables.less should be a sprockets context dependency'
|
44
|
+
|
45
|
+
data.gsub! '666666', '888888'
|
46
|
+
File.open(asset.pathname,'w') { |f| f.write(data) }
|
47
|
+
|
48
|
+
mtime = Time.now + 1
|
49
|
+
File.utime(mtime, mtime, asset.pathname)
|
50
|
+
|
51
|
+
basics.must_match %r{#test-variable-colored\{color:#888\}}, 'variables.less should be a sprockets context dependency'
|
34
52
|
end
|
35
53
|
end
|
36
54
|
|
@@ -61,15 +79,15 @@ class BasicsSpec < Less::Rails::Spec
|
|
61
79
|
end
|
62
80
|
|
63
81
|
protected
|
64
|
-
|
82
|
+
|
65
83
|
def basics
|
66
84
|
dummy_asset 'basics'
|
67
85
|
end
|
68
|
-
|
86
|
+
|
69
87
|
def mixins_asset
|
70
88
|
dummy_assets['frameworks/bootstrap/mixins.less']
|
71
89
|
end
|
72
|
-
|
90
|
+
|
73
91
|
def variables_asset
|
74
92
|
dummy_assets['frameworks/bootstrap/variables.less']
|
75
93
|
end
|
data/test/cases/railtie_spec.rb
CHANGED
@@ -31,7 +31,7 @@ class RailtieSpec < Less::Rails::Spec
|
|
31
31
|
describe 'initialization' do
|
32
32
|
|
33
33
|
it 'must register our template engine' do
|
34
|
-
dummy_assets.engines['.less'].
|
34
|
+
dummy_assets.engines['.less'].must_equal Less::Rails::LessTransformer
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'must extend the context class with our config' do
|
@@ -40,9 +40,7 @@ class RailtieSpec < Less::Rails::Spec
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'must register our import pre processor' do
|
43
|
-
dummy_assets.preprocessors['text/css'].
|
44
|
-
preprocessor.is_a? Grease::Adapter
|
45
|
-
end.must_equal true
|
43
|
+
dummy_assets.preprocessors['text/css'].must_include Less::Rails::ImportProcessor
|
46
44
|
end
|
47
45
|
|
48
46
|
it 'must include the asset pipelines stylesheet paths to less paths' do
|
@@ -8,7 +8,7 @@
|
|
8
8
|
#test-mixin span { .bordered; }
|
9
9
|
|
10
10
|
// Frameworks
|
11
|
-
@import "frameworks/bootstrap/mixins";
|
11
|
+
@import (multiple) "frameworks/bootstrap/mixins";
|
12
12
|
#test-radiused { .radiused; }
|
13
13
|
#test-variable-colored { .variableColored; }
|
14
14
|
#test-variable-relative-path-colored { .variableRelativePathColored; }
|
data/test/spec_helper.rb
CHANGED
@@ -8,11 +8,11 @@ require 'fileutils'
|
|
8
8
|
module Less
|
9
9
|
module Rails
|
10
10
|
class Spec < MiniTest::Spec
|
11
|
-
|
11
|
+
|
12
12
|
include FileUtils
|
13
|
-
|
13
|
+
|
14
14
|
class << self
|
15
|
-
|
15
|
+
|
16
16
|
def dummy_app
|
17
17
|
Dummy::Application
|
18
18
|
end
|
@@ -20,35 +20,35 @@ module Less
|
|
20
20
|
def dummy_tmp
|
21
21
|
"#{dummy_app.root}/tmp"
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
before do
|
27
27
|
prepare_cache_dir
|
28
28
|
reset_config_options
|
29
29
|
reset_caches
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
protected
|
33
|
-
|
33
|
+
|
34
34
|
delegate :dummy_app, :dummy_tmp, :to => :'self.class'
|
35
35
|
|
36
36
|
def dummy_config
|
37
37
|
dummy_app.config
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def dummy_assets
|
41
41
|
dummy_app.assets
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def dummy_asset(name)
|
45
45
|
dummy_assets[name].to_s.strip
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def reset_config_options
|
49
49
|
dummy_config.less.compress = true
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def reset_caches
|
53
53
|
version = SecureRandom.hex(32)
|
54
54
|
dummy_config.assets.version = version
|
@@ -56,57 +56,59 @@ module Less
|
|
56
56
|
cache = dummy_assets.cache
|
57
57
|
cache.respond_to?(:clear) ? cache.clear : rm_rf("#{dummy_tmp}/cache/assets")
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def prepare_cache_dir
|
61
61
|
mkdir_p "#{dummy_tmp}/cache/assets"
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
# Heavily inspired by Rails::Generators::TestCase.
|
67
67
|
class GeneratorSpec < Spec
|
68
|
-
|
68
|
+
|
69
69
|
class_attribute :destination_root, :current_path, :generator_class, :default_arguments
|
70
70
|
delegate :destination_root, :current_path, :generator_class, :default_arguments, :to => :'self.class'
|
71
|
-
|
71
|
+
|
72
72
|
self.current_path = File.expand_path(Dir.pwd)
|
73
73
|
self.default_arguments = []
|
74
74
|
self.destination_root = "#{dummy_tmp}/destination_root"
|
75
|
-
|
75
|
+
|
76
76
|
before { ensure_current_path ; prepare_destination ; no_color! ; setup_generator_class }
|
77
77
|
after { remove_destination ; ensure_current_path }
|
78
|
-
|
78
|
+
|
79
79
|
protected
|
80
|
-
|
80
|
+
|
81
81
|
def no_color!
|
82
82
|
Thor::Base.shell = Thor::Shell::Basic
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
def ensure_current_path
|
86
86
|
cd current_path
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
def prepare_destination
|
90
90
|
remove_destination
|
91
91
|
mkdir_p destination_root
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
def remove_destination
|
95
95
|
rm_rf destination_root
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def setup_generator_class
|
99
99
|
self.class.generator_class = Less::Generators.const_get(self.class.name.sub(/Spec$/, ''))
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def run_generator(args=default_arguments, config={})
|
103
|
-
|
103
|
+
spec_helper_silence_stdout do
|
104
|
+
generator_class.start(args, config.reverse_merge(:destination_root => destination_root))
|
105
|
+
end
|
104
106
|
end
|
105
107
|
|
106
108
|
def generator(args=default_arguments, options={}, config={})
|
107
109
|
@generator ||= generator_class.new(args, options, config.reverse_merge(:destination_root => destination_root))
|
108
110
|
end
|
109
|
-
|
111
|
+
|
110
112
|
def assert_file(relative, *contents)
|
111
113
|
absolute = File.expand_path(relative, destination_root)
|
112
114
|
assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not"
|
@@ -122,9 +124,36 @@ module Less
|
|
122
124
|
end
|
123
125
|
end
|
124
126
|
alias :assert_directory :assert_file
|
125
|
-
|
127
|
+
|
128
|
+
# Silence +STDOUT+ temporarily.
|
129
|
+
#
|
130
|
+
# &block:: Block of code to call while +STDOUT+ is disabled.
|
131
|
+
#
|
132
|
+
def spec_helper_silence_stdout(&block)
|
133
|
+
spec_helper_silence_stream($stdout, &block)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Back-end to #spec_helper_silence_stdout; silences arbitrary streams.
|
137
|
+
#
|
138
|
+
# +stream+:: The output stream to silence, e.g. <tt>$stdout</tt>
|
139
|
+
# &block:: Block of code to call while output stream is disabled.
|
140
|
+
#
|
141
|
+
def spec_helper_silence_stream(stream, &block)
|
142
|
+
begin
|
143
|
+
old_stream = stream.dup
|
144
|
+
stream.reopen(File::NULL)
|
145
|
+
stream.sync = true
|
146
|
+
|
147
|
+
yield
|
148
|
+
|
149
|
+
ensure
|
150
|
+
stream.reopen(old_stream)
|
151
|
+
old_stream.close
|
152
|
+
|
153
|
+
end
|
154
|
+
end
|
126
155
|
end
|
127
|
-
|
156
|
+
|
128
157
|
end
|
129
158
|
end
|
130
159
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: less-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Collins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: less
|
@@ -30,62 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '4
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '4.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: tilt
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: grease
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
33
|
+
version: '4'
|
62
34
|
type: :runtime
|
63
35
|
prerelease: false
|
64
36
|
version_requirements: !ruby/object:Gem::Requirement
|
65
37
|
requirements:
|
66
38
|
- - ">="
|
67
39
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
40
|
+
version: '4'
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
42
|
name: sprockets
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
72
44
|
requirements:
|
73
|
-
- - "
|
45
|
+
- - ">="
|
74
46
|
- !ruby/object:Gem::Version
|
75
47
|
version: '2'
|
76
|
-
- - "<"
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: '4'
|
79
48
|
type: :runtime
|
80
49
|
prerelease: false
|
81
50
|
version_requirements: !ruby/object:Gem::Requirement
|
82
51
|
requirements:
|
83
|
-
- - "
|
52
|
+
- - ">="
|
84
53
|
- !ruby/object:Gem::Version
|
85
54
|
version: '2'
|
86
|
-
- - "<"
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '4'
|
89
55
|
- !ruby/object:Gem::Dependency
|
90
56
|
name: appraisal
|
91
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,13 +145,14 @@ files:
|
|
179
145
|
- gemfiles/rails42.gemfile
|
180
146
|
- gemfiles/rails50.gemfile
|
181
147
|
- gemfiles/rails51.gemfile
|
148
|
+
- gemfiles/sprockets2.gemfile
|
182
149
|
- less-rails.gemspec
|
183
150
|
- lib/less-rails.rb
|
184
151
|
- lib/less/rails.rb
|
185
152
|
- lib/less/rails/helpers.rb
|
186
153
|
- lib/less/rails/import_processor.rb
|
154
|
+
- lib/less/rails/less_transformer.rb
|
187
155
|
- lib/less/rails/railtie.rb
|
188
|
-
- lib/less/rails/template_handlers.rb
|
189
156
|
- lib/less/rails/version.rb
|
190
157
|
- lib/rails/generators/less/assets/assets_generator.rb
|
191
158
|
- lib/rails/generators/less/assets/templates/stylesheet.css.less
|
@@ -222,12 +189,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
222
189
|
version: '0'
|
223
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
191
|
requirements:
|
225
|
-
- - "
|
192
|
+
- - ">"
|
226
193
|
- !ruby/object:Gem::Version
|
227
|
-
version:
|
194
|
+
version: 1.3.1
|
228
195
|
requirements: []
|
229
196
|
rubyforge_project:
|
230
|
-
rubygems_version: 2.
|
197
|
+
rubygems_version: 2.7.6
|
231
198
|
signing_key:
|
232
199
|
specification_version: 4
|
233
200
|
summary: The dynamic stylesheet language for the Rails asset pipeline.
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module Less
|
2
|
-
module Rails
|
3
|
-
class LessTemplate < Tilt::LessTemplate
|
4
|
-
|
5
|
-
self.default_mime_type = 'text/css'
|
6
|
-
|
7
|
-
include Helpers
|
8
|
-
|
9
|
-
TO_CSS_KEYS = [:compress, :optimization, :silent, :color]
|
10
|
-
|
11
|
-
def prepare
|
12
|
-
end
|
13
|
-
|
14
|
-
def evaluate(scope, locals, &block)
|
15
|
-
@output ||= begin
|
16
|
-
Less.Parser['scope'] = scope
|
17
|
-
parser = ::Less::Parser.new config_to_less_parser_options(scope)
|
18
|
-
engine = parser.parse(data)
|
19
|
-
engine.to_css config_to_css_options(scope)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
protected
|
24
|
-
|
25
|
-
def config_to_less_parser_options(scope)
|
26
|
-
paths = config_paths(scope) + scope.environment.paths
|
27
|
-
local_path = scope.pathname.dirname
|
28
|
-
paths += [local_path] unless paths.include? local_path
|
29
|
-
{:filename => eval_file, :line => line, :paths => paths, :dumpLineNumbers => config_from_rails(scope).line_numbers}.merge(config_raw(scope))
|
30
|
-
end
|
31
|
-
|
32
|
-
def config_to_css_options(scope)
|
33
|
-
Hash[config_from_rails(scope).each.to_a].slice *TO_CSS_KEYS
|
34
|
-
end
|
35
|
-
|
36
|
-
def config_paths(scope)
|
37
|
-
config_from_rails(scope)[:paths]
|
38
|
-
end
|
39
|
-
|
40
|
-
def config_raw(scope)
|
41
|
-
config_from_rails(scope)[:raw]
|
42
|
-
end
|
43
|
-
|
44
|
-
def config_from_rails(scope)
|
45
|
-
scope.environment.context_class.less_config
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|