less-rails 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG.md +13 -6
- data/Gemfile +6 -0
- data/Guardfile +7 -0
- data/README.md +34 -0
- data/Rakefile +14 -1
- data/less-rails.gemspec +4 -4
- data/lib/less/rails/helpers.rb +116 -0
- data/lib/less/rails/railtie.rb +8 -5
- data/lib/less/rails/template_handlers.rb +23 -16
- data/lib/less/rails/version.rb +1 -1
- data/lib/less/rails.rb +7 -0
- data/lib/less-rails.rb +1 -1
- data/test/cases/basics_spec.rb +16 -0
- data/test/cases/helpers_spec.rb +42 -0
- data/test/cases/railtie_spec.rb +40 -0
- data/test/dummy_app/app/assets/images/1x1.png +0 -0
- data/test/dummy_app/app/assets/images/rails.png +0 -0
- data/test/dummy_app/app/assets/stylesheets/basics.css.less +11 -0
- data/test/dummy_app/app/assets/stylesheets/helpers.css.less +19 -0
- data/test/dummy_app/init.rb +21 -0
- data/test/spec_helper.rb +50 -0
- metadata +63 -16
data/CHANGELOG.md
CHANGED
@@ -1,19 +1,26 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
-
2.0.
|
5
|
-
|
4
|
+
2.0.2 - 10/09/2011
|
5
|
+
------------------
|
6
|
+
* Extend LESS with Rails asset pipeline helpers.
|
7
|
+
* New testing support with MiniTest::Spec and dummy Rails::Application.
|
8
|
+
* New config.options hash passed down to the #to_css method.
|
9
|
+
|
10
|
+
|
11
|
+
2.0.1 - 09/28/2011
|
12
|
+
------------------
|
6
13
|
|
7
14
|
* Fix require of less/rails/railtie.rb. Thanks Benoit Bénézech (bbenezech).
|
8
15
|
|
9
16
|
|
10
|
-
2.0.0
|
11
|
-
|
17
|
+
2.0.0 - 09/25/2011
|
18
|
+
------------------
|
12
19
|
|
13
20
|
* Initial 2.0 release. Heavily inspired/copied code from sass-rails.
|
14
21
|
|
15
22
|
|
16
|
-
1.0.0
|
17
|
-
|
23
|
+
1.0.0 - 02/02/2010
|
24
|
+
------------------
|
18
25
|
|
19
26
|
* Original project at http://github.com/yeastymobs/less-rails
|
data/Gemfile
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
guard 'minitest' do
|
2
|
+
watch(%r|^lib/less/rails/(.*)\.rb|) { |m| "test/cases/#{m[1]}_spec.rb" }
|
3
|
+
# watch(%r|^lib/less/rails\.rb|) { "test/cases" }
|
4
|
+
# watch(%r|^test/dummy_app/.*|) { "test/cases" }
|
5
|
+
watch(%r|^test/spec_helper\.rb|) { "test/cases" }
|
6
|
+
watch(%r|^test/cases/(.*)_spec\.rb|)
|
7
|
+
end
|
data/README.md
CHANGED
@@ -17,9 +17,43 @@ This gem was made for other gems to properly hook into one place to provide path
|
|
17
17
|
```ruby
|
18
18
|
MyProject::Application.configure do
|
19
19
|
config.less.paths << "#{Rails.root}/lib/less/stylesheets"
|
20
|
+
config.less.compress = true
|
20
21
|
end
|
21
22
|
```
|
22
23
|
|
24
|
+
|
25
|
+
## Helpers
|
26
|
+
|
27
|
+
When referencing assets use the following helpers in LESS.
|
28
|
+
|
29
|
+
```css
|
30
|
+
asset-path(@relative-asset-path) /* Returns a string to the asset. */
|
31
|
+
asset-path("rails.png") /* Becomes: "/assets/rails.png" */
|
32
|
+
|
33
|
+
asset-url(@relative-asset-path) /* Returns url reference to the asset. */
|
34
|
+
asset-url("rails.png") /* Becomes: url(/assets/rails.png) */
|
35
|
+
```
|
36
|
+
|
37
|
+
As a convenience, for each of the following asset classes there are corresponding `-path` and `-url` helpers image, font, video, audio, javascript and stylesheet. The following examples only show the `-url` variants since you get the idea of the `-path` ones above.
|
38
|
+
|
39
|
+
```css
|
40
|
+
image-url("rails.png") /* Becomes: url(/assets/rails.png) */
|
41
|
+
font-url("rails.ttf") /* Becomes: url(/assets/rails.ttf) */
|
42
|
+
video-url("rails.ttf") /* Becomes: url(/videos/rails.mp4) */
|
43
|
+
audio-url("rails.ttf") /* Becomes: url(/audios/rails.mp3) */
|
44
|
+
javascript-url("rails.js") /* Becomes: url(/assets/rails.js) */
|
45
|
+
stylesheet-url("rails.css") /* Becomes: url(/assets/rails.css) */
|
46
|
+
```
|
47
|
+
|
48
|
+
Lastly, we provide a data url method for base64 encoding assets.
|
49
|
+
|
50
|
+
```css
|
51
|
+
asset-data-url("rails.png") /* Becomes: url(data:image/png;base64,iVBORw0K...) */
|
52
|
+
```
|
53
|
+
|
54
|
+
Please note that these helpers are only available server-side, and something like ERB templates should be used if client-side rendering is desired.
|
55
|
+
|
56
|
+
|
23
57
|
## License
|
24
58
|
|
25
59
|
Less::Rails is Copyright (c) 2011 Ken Collins, <ken@metaskills.net> and is distributed under the MIT license.
|
data/Rakefile
CHANGED
@@ -1 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs = ['lib','test']
|
8
|
+
t.test_files = Dir.glob("test/**/*_spec.rb").sort
|
9
|
+
t.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => [:test]
|
13
|
+
task :spec => [:test]
|
14
|
+
|
data/less-rails.gemspec
CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.add_runtime_dependency 'less', '~> 2.0.7'
|
18
|
-
s.add_runtime_dependency '
|
19
|
-
s.
|
20
|
-
|
21
|
-
|
18
|
+
s.add_runtime_dependency 'actionpack', '~> 3.1.1'
|
19
|
+
s.add_development_dependency 'minitest'
|
20
|
+
s.add_development_dependency 'guard-minitest'
|
21
|
+
s.add_development_dependency 'rails', '~> 3.1.1'
|
22
22
|
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module Less
|
2
|
+
|
3
|
+
def self.less
|
4
|
+
@less
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.register_rails_helper(name, &block)
|
8
|
+
tree = @loader.require('less/tree')
|
9
|
+
tree.functions[name] = lambda do |node|
|
10
|
+
tree[:Anonymous].new block.call(tree, node)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Rails
|
15
|
+
module Helpers
|
16
|
+
|
17
|
+
extend ActiveSupport::Concern
|
18
|
+
|
19
|
+
included do
|
20
|
+
Less.register_rails_helper('asset-path') { |tree, cxt| asset_path unquote(cxt.toCSS()) }
|
21
|
+
Less.register_rails_helper('asset-url') { |tree, cxt| asset_url unquote(cxt.toCSS()) }
|
22
|
+
Less.register_rails_helper('image-path') { |tree, cxt| image_path unquote(cxt.toCSS()) }
|
23
|
+
Less.register_rails_helper('image-url') { |tree, cxt| image_url unquote(cxt.toCSS()) }
|
24
|
+
Less.register_rails_helper('video-path') { |tree, cxt| video_path unquote(cxt.toCSS()) }
|
25
|
+
Less.register_rails_helper('video-url') { |tree, cxt| video_url unquote(cxt.toCSS()) }
|
26
|
+
Less.register_rails_helper('audio-path') { |tree, cxt| audio_path unquote(cxt.toCSS()) }
|
27
|
+
Less.register_rails_helper('audio-url') { |tree, cxt| audio_url unquote(cxt.toCSS()) }
|
28
|
+
Less.register_rails_helper('javascript-path') { |tree, cxt| javascript_path unquote(cxt.toCSS()) }
|
29
|
+
Less.register_rails_helper('javascript-url') { |tree, cxt| javascript_url unquote(cxt.toCSS()) }
|
30
|
+
Less.register_rails_helper('stylesheet-path') { |tree, cxt| stylesheet_path unquote(cxt.toCSS()) }
|
31
|
+
Less.register_rails_helper('stylesheet-url') { |tree, cxt| stylesheet_url unquote(cxt.toCSS()) }
|
32
|
+
Less.register_rails_helper('font-path') { |tree, cxt| asset_path unquote(cxt.toCSS()) }
|
33
|
+
Less.register_rails_helper('font-url') { |tree, cxt| asset_url unquote(cxt.toCSS()) }
|
34
|
+
Less.register_rails_helper('asset-data-url') { |tree, cxt| asset_data_url unquote(cxt.toCSS()) }
|
35
|
+
end
|
36
|
+
|
37
|
+
module ClassMethods
|
38
|
+
|
39
|
+
def asset_data_url(path)
|
40
|
+
"url(#{scope.asset_data_uri(path)})"
|
41
|
+
end
|
42
|
+
|
43
|
+
def asset_path(asset)
|
44
|
+
public_path(asset).inspect
|
45
|
+
end
|
46
|
+
|
47
|
+
def asset_url(asset)
|
48
|
+
"url(#{public_path(asset)})"
|
49
|
+
end
|
50
|
+
|
51
|
+
def image_path(img)
|
52
|
+
scope.image_path(img).inspect
|
53
|
+
end
|
54
|
+
|
55
|
+
def image_url(img)
|
56
|
+
"url(#{scope.image_path(img)})"
|
57
|
+
end
|
58
|
+
|
59
|
+
def video_path(video)
|
60
|
+
scope.video_path(video).inspect
|
61
|
+
end
|
62
|
+
|
63
|
+
def video_url(video)
|
64
|
+
"url(#{scope.video_path(video)})"
|
65
|
+
end
|
66
|
+
|
67
|
+
def audio_path(audio)
|
68
|
+
scope.audio_path(audio).inspect
|
69
|
+
end
|
70
|
+
|
71
|
+
def audio_url(audio)
|
72
|
+
"url(#{scope.audio_path(audio)})"
|
73
|
+
end
|
74
|
+
|
75
|
+
def javascript_path(javascript)
|
76
|
+
scope.javascript_path(javascript).inspect
|
77
|
+
end
|
78
|
+
|
79
|
+
def javascript_url(javascript)
|
80
|
+
"url(#{scope.javascript_path(javascript)})"
|
81
|
+
end
|
82
|
+
|
83
|
+
def stylesheet_path(stylesheet)
|
84
|
+
scope.stylesheet_path(stylesheet).inspect
|
85
|
+
end
|
86
|
+
|
87
|
+
def stylesheet_url(stylesheet)
|
88
|
+
"url(#{scope.stylesheet_path(stylesheet)})"
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def scope
|
95
|
+
Less.Parser['scope']
|
96
|
+
end
|
97
|
+
|
98
|
+
def public_path(asset)
|
99
|
+
scope.asset_paths.compute_public_path asset, ::Rails.application.config.assets.prefix
|
100
|
+
end
|
101
|
+
|
102
|
+
def context_asset_data_uri(path)
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
def unquote(str)
|
107
|
+
s = str.to_s.strip
|
108
|
+
s =~ /^['"](.*?)['"]$/ ? $1 : s
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
data/lib/less/rails/railtie.rb
CHANGED
@@ -7,19 +7,21 @@ module Less
|
|
7
7
|
end
|
8
8
|
|
9
9
|
config.less = ActiveSupport::OrderedOptions.new
|
10
|
-
|
11
10
|
config.less.paths = []
|
11
|
+
config.less.compress = false
|
12
12
|
|
13
13
|
config.before_initialize do |app|
|
14
|
-
unless app.config.assets && app.config.assets.enabled
|
15
|
-
raise "The less-rails plugin requires the asset pipeline to be enabled."
|
16
|
-
end
|
17
14
|
require 'less'
|
15
|
+
require 'less-rails'
|
18
16
|
Sprockets::Engines #force autoloading
|
19
17
|
Sprockets.register_engine '.less', Less::Rails::LessTemplate
|
20
18
|
end
|
21
19
|
|
22
|
-
initializer 'less-rails.
|
20
|
+
initializer 'less-rails.before.load_config_initializers', :before => 'load_config_initializers', :group => :all do |app|
|
21
|
+
raise 'The less-rails plugin requires the asset pipeline to be enabled.' unless app.config.assets.enabled
|
22
|
+
end
|
23
|
+
|
24
|
+
initializer 'less-rails.after.load_config_initializers', :after => 'load_config_initializers', :group => :all do |app|
|
23
25
|
app.assets.context_class.extend(LessContext)
|
24
26
|
app.assets.context_class.less_config = app.config.less
|
25
27
|
end
|
@@ -27,3 +29,4 @@ module Less
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
32
|
+
|
@@ -1,35 +1,42 @@
|
|
1
|
-
require 'tilt'
|
2
|
-
require 'sprockets'
|
3
|
-
|
4
1
|
module Less
|
5
|
-
module Rails
|
6
|
-
|
2
|
+
module Rails
|
7
3
|
class LessTemplate < Tilt::LessTemplate
|
8
4
|
|
5
|
+
include Helpers
|
6
|
+
|
7
|
+
TO_CSS_KEYS = [:compress, :optimization, :silent, :color]
|
8
|
+
|
9
9
|
def prepare
|
10
10
|
end
|
11
11
|
|
12
12
|
def evaluate(scope, locals, &block)
|
13
13
|
@output ||= begin
|
14
|
-
|
14
|
+
Less.Parser['scope'] = scope
|
15
|
+
parser = ::Less::Parser.new config_to_less_parser_options(scope)
|
15
16
|
engine = parser.parse(data)
|
16
|
-
engine.to_css
|
17
|
+
engine.to_css config_to_css_options(scope)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
protected
|
21
22
|
|
22
|
-
def
|
23
|
-
scope.environment.
|
24
|
-
end
|
25
|
-
|
26
|
-
def less_parser_options(scope)
|
27
|
-
less_options = less_options_from_rails(scope)
|
28
|
-
paths = less_options[:paths] + scope.environment.paths
|
23
|
+
def config_to_less_parser_options(scope)
|
24
|
+
paths = config_paths(scope) + scope.environment.paths
|
29
25
|
{:filename => eval_file, :line => line, :paths => paths}
|
30
26
|
end
|
31
27
|
|
32
|
-
|
33
|
-
|
28
|
+
def config_to_css_options(scope)
|
29
|
+
Hash[config_from_rails(scope).each.to_a].slice *TO_CSS_KEYS
|
30
|
+
end
|
31
|
+
|
32
|
+
def config_paths(scope)
|
33
|
+
config_from_rails(scope)[:paths]
|
34
|
+
end
|
35
|
+
|
36
|
+
def config_from_rails(scope)
|
37
|
+
scope.environment.context_class.less_config
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
34
41
|
end
|
35
42
|
end
|
data/lib/less/rails/version.rb
CHANGED
data/lib/less/rails.rb
CHANGED
@@ -3,6 +3,13 @@ module Less
|
|
3
3
|
end
|
4
4
|
end
|
5
5
|
|
6
|
+
require 'less'
|
7
|
+
require 'rails'
|
8
|
+
require 'tilt'
|
9
|
+
require 'sprockets'
|
10
|
+
require 'sprockets/railtie'
|
11
|
+
|
6
12
|
require 'less/rails/version'
|
13
|
+
require 'less/rails/helpers'
|
7
14
|
require 'less/rails/template_handlers'
|
8
15
|
require 'less/rails/railtie'
|
data/lib/less-rails.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
1
|
+
require 'less/rails'
|
2
2
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class BasicsSpec < Less::Rails::Spec
|
4
|
+
|
5
|
+
let(:basics) { dummy_asset('basics') }
|
6
|
+
|
7
|
+
it 'must render variables' do
|
8
|
+
basics.must_match %r{#test-variable\{color:#4d926f;\}}
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'must render mixins' do
|
12
|
+
basics.must_match %r{#test-mixin span\{border:1px solid black;\}}
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class HelpersSpec < Less::Rails::Spec
|
4
|
+
|
5
|
+
before { dummy_config.less.compress = false }
|
6
|
+
|
7
|
+
let(:helpers) { dummy_asset('helpers') }
|
8
|
+
|
9
|
+
it 'parse asset paths' do
|
10
|
+
line_for_helper('asset-path').must_equal 'asset-path: "/assets/rails.png";'
|
11
|
+
line_for_helper('asset-url').must_equal "asset-url: url(/assets/rails.png);"
|
12
|
+
line_for_helper('image-path').must_equal 'image-path: "/assets/rails.png";'
|
13
|
+
line_for_helper('image-url').must_equal "image-url: url(/assets/rails.png);"
|
14
|
+
line_for_helper('video-path').must_equal 'video-path: "/videos/rails.mp4";'
|
15
|
+
line_for_helper('video-url').must_equal "video-url: url(/videos/rails.mp4);"
|
16
|
+
line_for_helper('audio-path').must_equal 'audio-path: "/audios/rails.mp3";'
|
17
|
+
line_for_helper('audio-url').must_equal "audio-url: url(/audios/rails.mp3);"
|
18
|
+
line_for_helper('javascript-path').must_equal 'javascript-path: "/assets/rails.js";'
|
19
|
+
line_for_helper('javascript-url').must_equal "javascript-url: url(/assets/rails.js);"
|
20
|
+
line_for_helper('stylesheet-path').must_equal 'stylesheet-path: "/assets/rails.css";'
|
21
|
+
line_for_helper('stylesheet-url').must_equal "stylesheet-url: url(/assets/rails.css);"
|
22
|
+
line_for_helper('font-path').must_equal 'font-path: "/assets/rails.ttf";'
|
23
|
+
line_for_helper('font-url').must_equal "font-url: url(/assets/rails.ttf);"
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'parses data urls ' do
|
27
|
+
line = line_for_helper('asset-data-url')
|
28
|
+
asset_data_url_regexp = %r{asset-data-url: url\((.*?)\)}
|
29
|
+
line.must_match asset_data_url_regexp
|
30
|
+
asset_data_url_match = line.match(asset_data_url_regexp)[1]
|
31
|
+
asset_data_url_expected = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw%2FeHBhY2tldCBiZWdpbj0i77u%2FIiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8%2BIDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNS4xIE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCNzY5NDE1QkQ2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpCNzY5NDE1Q0Q2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiI%2BIDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkE3MzcyNTQ2RDY2QjExRTA5RTMzQTlDQTZFODJBQTFCIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkI3Njk0MTVBRDY2QzExRTA5RTMzQTlDQTZFODJBQTFCIi8%2BIDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY%2BIDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8%2B0HhJ9AAAABBJREFUeNpi%2BP%2F%2FPwNAgAEACPwC%2FtuiTRYAAAAASUVORK5CYII%3D"
|
32
|
+
asset_data_url_match.must_equal asset_data_url_expected
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def line_for_helper(name)
|
39
|
+
helpers.each_line.detect{ |line| line.include? name }.strip
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class RailtieSpec < Less::Rails::Spec
|
4
|
+
|
5
|
+
describe 'config' do
|
6
|
+
|
7
|
+
it 'must have a less ordered hash' do
|
8
|
+
dummy_config.less.must_be_instance_of ActiveSupport::OrderedOptions
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'must have an empty array for paths' do
|
12
|
+
dummy_config.less.paths.must_equal Array.new
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'must have an options hash passed down to the #to_css method' do
|
16
|
+
basic_compressed_match = /#test-variable\{color:#4d926f;\}/
|
17
|
+
dummy_config.less.compress = true
|
18
|
+
dummy_asset('basics').must_match basic_compressed_match
|
19
|
+
reset_caches
|
20
|
+
dummy_config.less.compress = false
|
21
|
+
dummy_asset('basics').wont_match basic_compressed_match
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'initialization' do
|
27
|
+
|
28
|
+
it 'must register our template engine' do
|
29
|
+
dummy_assets.engines['.less'].must_equal Less::Rails::LessTemplate
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'must extend the context class with our config' do
|
33
|
+
dummy_assets.context_class.must_respond_to :less_config
|
34
|
+
dummy_assets.context_class.less_config.must_equal dummy_config.less
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
.rails {
|
3
|
+
asset-path: asset-path("rails.png");
|
4
|
+
asset-url: asset-url("rails.png");
|
5
|
+
image-path: image-path("rails.png");
|
6
|
+
image-url: image-url("rails.png");
|
7
|
+
video-path: video-path("rails.mp4");
|
8
|
+
video-url: video-url("rails.mp4");
|
9
|
+
audio-path: audio-path("rails.mp3");
|
10
|
+
audio-url: audio-url("rails.mp3");
|
11
|
+
font-path: font-path("rails.ttf");
|
12
|
+
font-url: font-url("rails.ttf");
|
13
|
+
javascript-path: javascript-path("rails.js");
|
14
|
+
javascript-url: javascript-url("rails.js");
|
15
|
+
stylesheet-path: stylesheet-path("rails.css");
|
16
|
+
stylesheet-url: stylesheet-url("rails.css");
|
17
|
+
asset-data-url: asset-data-url("1x1.png");
|
18
|
+
}
|
19
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'sprockets/railtie'
|
2
|
+
require 'action_controller/railtie'
|
3
|
+
require 'action_view/railtie'
|
4
|
+
require 'action_view/base'
|
5
|
+
require 'action_controller/base'
|
6
|
+
|
7
|
+
module Dummy
|
8
|
+
class Application < ::Rails::Application
|
9
|
+
|
10
|
+
config.root = File.join __FILE__, '..'
|
11
|
+
config.active_support.deprecation = :stderr
|
12
|
+
config.cache_store = :memory_store
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
|
15
|
+
config.assets.enabled = true
|
16
|
+
config.assets.cache_store = config.cache_store
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Dummy::Application.initialize!
|
data/test/spec_helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.require
|
4
|
+
require 'less/rails'
|
5
|
+
require 'minitest/spec'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'dummy_app/init'
|
8
|
+
|
9
|
+
module Less
|
10
|
+
module Rails
|
11
|
+
class Spec < MiniTest::Spec
|
12
|
+
|
13
|
+
before do
|
14
|
+
reset_config_options
|
15
|
+
reset_caches
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def dummy_app
|
22
|
+
Dummy::Application
|
23
|
+
end
|
24
|
+
|
25
|
+
def dummy_config
|
26
|
+
dummy_app.config
|
27
|
+
end
|
28
|
+
|
29
|
+
def dummy_assets
|
30
|
+
dummy_app.assets
|
31
|
+
end
|
32
|
+
|
33
|
+
def dummy_asset(name)
|
34
|
+
dummy_assets[name].to_s.strip
|
35
|
+
end
|
36
|
+
|
37
|
+
def reset_config_options
|
38
|
+
dummy_config.less.paths = []
|
39
|
+
dummy_config.less.compress = true
|
40
|
+
end
|
41
|
+
|
42
|
+
def reset_caches
|
43
|
+
dummy_assets.version = SecureRandom.hex(32)
|
44
|
+
dummy_assets.cache.clear
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: less-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 2
|
10
|
+
version: 2.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ken Collins
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09
|
18
|
+
date: 2011-10-09 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -35,37 +35,65 @@ dependencies:
|
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: actionpack
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
45
|
+
hash: 1
|
46
46
|
segments:
|
47
47
|
- 3
|
48
48
|
- 1
|
49
|
-
-
|
50
|
-
version: 3.1.
|
49
|
+
- 1
|
50
|
+
version: 3.1.1
|
51
51
|
type: :runtime
|
52
52
|
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: minitest
|
55
55
|
prerelease: false
|
56
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
hash: 3
|
62
62
|
segments:
|
63
|
-
- 3
|
64
|
-
- 1
|
65
63
|
- 0
|
66
|
-
version:
|
67
|
-
type: :
|
64
|
+
version: "0"
|
65
|
+
type: :development
|
68
66
|
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: guard-minitest
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rails
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 1
|
90
|
+
segments:
|
91
|
+
- 3
|
92
|
+
- 1
|
93
|
+
- 1
|
94
|
+
version: 3.1.1
|
95
|
+
type: :development
|
96
|
+
version_requirements: *id005
|
69
97
|
description: The dynamic stylesheet language for the Rails asset pipeline.
|
70
98
|
email:
|
71
99
|
- ken@metaskills.net
|
@@ -79,15 +107,26 @@ files:
|
|
79
107
|
- .gitignore
|
80
108
|
- CHANGELOG.md
|
81
109
|
- Gemfile
|
110
|
+
- Guardfile
|
82
111
|
- MIT-LICENSE
|
83
112
|
- README.md
|
84
113
|
- Rakefile
|
85
114
|
- less-rails.gemspec
|
86
115
|
- lib/less-rails.rb
|
87
116
|
- lib/less/rails.rb
|
117
|
+
- lib/less/rails/helpers.rb
|
88
118
|
- lib/less/rails/railtie.rb
|
89
119
|
- lib/less/rails/template_handlers.rb
|
90
120
|
- lib/less/rails/version.rb
|
121
|
+
- test/cases/basics_spec.rb
|
122
|
+
- test/cases/helpers_spec.rb
|
123
|
+
- test/cases/railtie_spec.rb
|
124
|
+
- test/dummy_app/app/assets/images/1x1.png
|
125
|
+
- test/dummy_app/app/assets/images/rails.png
|
126
|
+
- test/dummy_app/app/assets/stylesheets/basics.css.less
|
127
|
+
- test/dummy_app/app/assets/stylesheets/helpers.css.less
|
128
|
+
- test/dummy_app/init.rb
|
129
|
+
- test/spec_helper.rb
|
91
130
|
has_rdoc: true
|
92
131
|
homepage: http://github.com/metaskills/less-rails
|
93
132
|
licenses: []
|
@@ -122,5 +161,13 @@ rubygems_version: 1.6.2
|
|
122
161
|
signing_key:
|
123
162
|
specification_version: 3
|
124
163
|
summary: The dynamic stylesheet language for the Rails asset pipeline.
|
125
|
-
test_files:
|
126
|
-
|
164
|
+
test_files:
|
165
|
+
- test/cases/basics_spec.rb
|
166
|
+
- test/cases/helpers_spec.rb
|
167
|
+
- test/cases/railtie_spec.rb
|
168
|
+
- test/dummy_app/app/assets/images/1x1.png
|
169
|
+
- test/dummy_app/app/assets/images/rails.png
|
170
|
+
- test/dummy_app/app/assets/stylesheets/basics.css.less
|
171
|
+
- test/dummy_app/app/assets/stylesheets/helpers.css.less
|
172
|
+
- test/dummy_app/init.rb
|
173
|
+
- test/spec_helper.rb
|