Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1001 from nanoc/less-fiber
Run less filter on main fiber
- Loading branch information
Showing
5 changed files
with
105 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,106 @@ | ||
describe Nanoc::Filters::Less, site: true, stdio: true do | ||
before do | ||
File.write('content/a.less', '@import "b.less";') | ||
File.write('content/b.less', 'p { color: red; }') | ||
# These tests are high-level in order to interact well with the compiler. This is important for | ||
# this :less filter, because of the way it handles fibers. | ||
|
||
before do | ||
File.open('Rules', 'w') do |io| | ||
io.write "compile '/a.less' do\n" | ||
io.write " filter :less\n" | ||
io.write " write '/a.css'\n" | ||
io.write "end\n" | ||
io.write "\n" | ||
io.write "compile '/b.less' do\n" | ||
io.write "compile '/**/*.less' do\n" | ||
io.write " filter :less\n" | ||
io.write " write item.identifier.without_ext + '.css'\n" | ||
io.write "end\n" | ||
end | ||
end | ||
|
||
it 'compiles a.less' do | ||
skip 'flaky test' | ||
context 'one file' do | ||
let(:content_a) { 'p { color: red; }' } | ||
|
||
before do | ||
File.write('content/a.less', content_a) | ||
end | ||
|
||
it 'compiles a.less' do | ||
Nanoc::CLI.run(%w(compile)) | ||
expect(File.read('output/a.css')).to match(/^p\s*\{\s*color:\s*red;?\s*\}/) | ||
end | ||
|
||
context 'with compression' do | ||
let(:content_a) { '.foo { bar: a; } .bar { foo: b; }' } | ||
|
||
before do | ||
File.open('Rules', 'w') do |io| | ||
io.write "compile '/*.less' do\n" | ||
io.write " filter :less, compress: true\n" | ||
io.write " write item.identifier.without_ext + '.css'\n" | ||
io.write "end\n" | ||
end | ||
end | ||
|
||
it 'compiles and compresses a.less' do | ||
Nanoc::CLI.run(%w(compile)) | ||
expect(File.read('output/a.css')).to match(/^\.foo\{bar:a\}\n?\.bar\{foo:b\}/) | ||
end | ||
end | ||
end | ||
|
||
context 'two files' do | ||
let(:content_a) { '@import "b.less";' } | ||
let(:content_b) { 'p { color: red; }' } | ||
|
||
before do | ||
File.write('content/a.less', content_a) | ||
File.write('content/b.less', content_b) | ||
end | ||
|
||
it 'compiles a.less' do | ||
Nanoc::CLI.run(%w(compile)) | ||
expect(File.read('output/a.css')).to match(/^p\s*\{\s*color:\s*red;?\s*\}/) | ||
end | ||
|
||
it 'recompiles a.less if b.less has changed' do | ||
Nanoc::CLI.run(%w(compile)) | ||
|
||
File.write('content/b.less', 'p { color: blue; }') | ||
|
||
Nanoc::CLI.run(%w(compile)) | ||
expect(File.read('output/a.css')).to match(/^p\s*\{\s*color:\s*blue;?\s*\}/) | ||
end | ||
end | ||
|
||
context 'paths relative to site directory' do | ||
let(:content_a) { '@import "content/foo/bar/imported_file.less";' } | ||
let(:content_b) { 'p { color: red; }' } | ||
|
||
Nanoc::CLI.run(%w(compile)) | ||
expect(Dir['output/*']).to eql(['output/a.css']) | ||
expect(File.read('output/a.css')).to match(/^p\s*\{\s*color:\s*red;?\s*\}/) | ||
before do | ||
FileUtils.mkdir_p('content/foo/bar') | ||
|
||
File.write('content/a.less', content_a) | ||
File.write('content/foo/bar/imported_file.less', content_b) | ||
end | ||
|
||
it 'compiles a.less' do | ||
Nanoc::CLI.run(%w(compile)) | ||
expect(File.read('output/a.css')).to match(/^p\s*\{\s*color:\s*red;?\s*\}/) | ||
end | ||
|
||
it 'recompiles a.less if b.less has changed' | ||
end | ||
|
||
it 'recompiles a.less if b.less has changed' do | ||
skip 'flaky test' | ||
context 'paths relative to current file' do | ||
let(:content_a) { '@import "bar/imported_file.less";' } | ||
let(:content_b) { 'p { color: red; }' } | ||
|
||
before do | ||
FileUtils.mkdir_p('content/foo/bar') | ||
|
||
Nanoc::CLI.run(%w(compile)) | ||
File.write('content/foo/a.less', content_a) | ||
File.write('content/foo/bar/imported_file.less', content_b) | ||
end | ||
|
||
File.write('content/b.less', 'p { color: blue; }') | ||
it 'compiles a.less' do | ||
Nanoc::CLI.run(%w(compile)) | ||
expect(File.read('output/foo/a.css')).to match(/^p\s*\{\s*color:\s*red;?\s*\}/) | ||
end | ||
|
||
Nanoc::CLI.run(%w(compile)) | ||
expect(Dir['output/*']).to eql(['output/a.css']) | ||
expect(File.read('output/a.css')).to match(/^p\s*\{\s*color:\s*blue;?\s*\}/) | ||
it 'recompiles a.less if b.less has changed' | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.