haml-edge 3.1.73 → 3.1.74
Sign up to get free protection for your applications and to get access to all the features.
- data/EDGE_GEM_VERSION +1 -1
- data/VERSION +1 -1
- data/lib/haml/exec.rb +7 -7
- data/lib/haml/util.rb +37 -0
- data/lib/sass/cache_store.rb +213 -0
- data/lib/sass/callbacks.rb +14 -0
- data/lib/sass/engine.rb +98 -15
- data/lib/sass/error.rb +4 -1
- data/lib/sass/importers/base.rb +138 -0
- data/lib/sass/importers/filesystem.rb +121 -0
- data/lib/sass/importers.rb +22 -0
- data/lib/sass/plugin/compiler.rb +351 -0
- data/lib/sass/plugin/configuration.rb +114 -212
- data/lib/sass/plugin/merb.rb +24 -13
- data/lib/sass/plugin/rails.rb +16 -7
- data/lib/sass/plugin/staleness_checker.rb +55 -33
- data/lib/sass/plugin.rb +25 -173
- data/lib/sass/script/node.rb +3 -3
- data/lib/sass/selector/simple.rb +1 -1
- data/lib/sass/tree/import_node.rb +44 -22
- data/lib/sass/tree/node.rb +17 -2
- data/lib/sass.rb +43 -0
- data/test/haml/util_test.rb +32 -0
- data/test/sass/cache_test.rb +67 -0
- data/test/sass/engine_test.rb +47 -16
- data/test/sass/importer_test.rb +82 -0
- data/test/sass/plugin_test.rb +21 -15
- data/test/sass/test_helper.rb +5 -0
- metadata +12 -3
- data/lib/sass/files.rb +0 -160
data/test/sass/engine_test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
require File.dirname(__FILE__) + '/../test_helper'
|
4
|
+
require File.dirname(__FILE__) + '/test_helper'
|
4
5
|
require 'sass/engine'
|
5
6
|
require 'stringio'
|
6
7
|
|
@@ -11,6 +12,7 @@ module Sass::Script::Functions::UserFunctions
|
|
11
12
|
end
|
12
13
|
|
13
14
|
class SassEngineTest < Test::Unit::TestCase
|
15
|
+
FAKE_FILE_NAME = __FILE__.gsub(/rb$/,"sass")
|
14
16
|
# A map of erroneous Sass documents to the error messages they should produce.
|
15
17
|
# The error messages may be arrays;
|
16
18
|
# if so, the second element should be the line number that should be reported for the error.
|
@@ -61,9 +63,7 @@ MSG
|
|
61
63
|
"$a: b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.",
|
62
64
|
"@import foo.sass" => <<MSG,
|
63
65
|
File to import not found or unreadable: foo.sass.
|
64
|
-
Load
|
65
|
-
#{File.dirname(__FILE__)}
|
66
|
-
.
|
66
|
+
Load path: .
|
67
67
|
MSG
|
68
68
|
"@import templates/basic\n foo" => "Illegal nesting: Nothing may be nested beneath import directives.",
|
69
69
|
"foo\n @import templates/basic" => "Import directives may only be used at the root of a document.",
|
@@ -144,6 +144,33 @@ MSG
|
|
144
144
|
renders_correctly "nested", { :style => :nested }
|
145
145
|
renders_correctly "compressed", { :style => :compressed }
|
146
146
|
end
|
147
|
+
|
148
|
+
def test_compile
|
149
|
+
assert_equal "div { hello: world; }\n", Sass.compile("$who: world\ndiv\n hello: $who", :syntax => :sass, :style => :compact)
|
150
|
+
assert_equal "div { hello: world; }\n", Sass.compile("$who: world; div { hello: $who }", :style => :compact)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_compile_file
|
154
|
+
FileUtils.mkdir_p(absolutize("tmp"))
|
155
|
+
open(absolutize("tmp/test_compile_file.sass"), "w") {|f| f.write("$who: world\ndiv\n hello: $who")}
|
156
|
+
open(absolutize("tmp/test_compile_file.scss"), "w") {|f| f.write("$who: world; div { hello: $who }")}
|
157
|
+
assert_equal "div { hello: world; }\n", Sass.compile_file(absolutize("tmp/test_compile_file.sass"), :style => :compact)
|
158
|
+
assert_equal "div { hello: world; }\n", Sass.compile_file(absolutize("tmp/test_compile_file.scss"), :style => :compact)
|
159
|
+
ensure
|
160
|
+
FileUtils.rm_rf(absolutize("tmp"))
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_compile_file_to_css_file
|
164
|
+
FileUtils.mkdir_p(absolutize("tmp"))
|
165
|
+
open(absolutize("tmp/test_compile_file.sass"), "w") {|f| f.write("$who: world\ndiv\n hello: $who")}
|
166
|
+
open(absolutize("tmp/test_compile_file.scss"), "w") {|f| f.write("$who: world; div { hello: $who }")}
|
167
|
+
Sass.compile_file(absolutize("tmp/test_compile_file.sass"), absolutize("tmp/test_compile_file_sass.css"), :style => :compact)
|
168
|
+
Sass.compile_file(absolutize("tmp/test_compile_file.scss"), absolutize("tmp/test_compile_file_scss.css"), :style => :compact)
|
169
|
+
assert_equal "div { hello: world; }\n", File.read(absolutize("tmp/test_compile_file_sass.css"))
|
170
|
+
assert_equal "div { hello: world; }\n", File.read(absolutize("tmp/test_compile_file_scss.css"))
|
171
|
+
ensure
|
172
|
+
FileUtils.rm_rf(absolutize("tmp"))
|
173
|
+
end
|
147
174
|
|
148
175
|
def test_flexible_tabulation
|
149
176
|
assert_equal("p {\n a: b; }\n p q {\n c: d; }\n",
|
@@ -156,14 +183,14 @@ MSG
|
|
156
183
|
define_method("test_exception (#{key.inspect})") do
|
157
184
|
line = 10
|
158
185
|
begin
|
159
|
-
silence_warnings {Sass::Engine.new(key, :filename =>
|
186
|
+
silence_warnings {Sass::Engine.new(key, :filename => FAKE_FILE_NAME, :line => line).render}
|
160
187
|
rescue Sass::SyntaxError => err
|
161
188
|
value = [value] unless value.is_a?(Array)
|
162
189
|
|
163
190
|
assert_equal(value.first.rstrip, err.message, "Line: #{key}")
|
164
|
-
assert_equal(
|
191
|
+
assert_equal(FAKE_FILE_NAME, err.sass_filename)
|
165
192
|
assert_equal((value[1] || key.split("\n").length) + line - 1, err.sass_line, "Line: #{key}")
|
166
|
-
assert_match(/#{Regexp.escape(
|
193
|
+
assert_match(/#{Regexp.escape(FAKE_FILE_NAME)}:[0-9]+/, err.backtrace[0], "Line: #{key}")
|
167
194
|
else
|
168
195
|
assert(false, "Exception not raised for\n#{key}")
|
169
196
|
end
|
@@ -196,9 +223,9 @@ rule
|
|
196
223
|
:broken
|
197
224
|
SASS
|
198
225
|
begin
|
199
|
-
Sass::Engine.new(to_render, :filename =>
|
226
|
+
Sass::Engine.new(to_render, :filename => FAKE_FILE_NAME, :line => (__LINE__-7)).render
|
200
227
|
rescue Sass::SyntaxError => err
|
201
|
-
assert_equal(
|
228
|
+
assert_equal(FAKE_FILE_NAME, err.sass_filename)
|
202
229
|
assert_equal((__LINE__-6), err.sass_line)
|
203
230
|
else
|
204
231
|
assert(false, "Exception not raised for '#{to_render}'!")
|
@@ -500,17 +527,17 @@ CSS
|
|
500
527
|
end
|
501
528
|
|
502
529
|
def test_sass_import
|
503
|
-
|
530
|
+
sassc_file = sassc_path("importee")
|
531
|
+
assert !File.exists?(sassc_file)
|
504
532
|
renders_correctly "import", { :style => :compact, :load_paths => [File.dirname(__FILE__) + "/templates"] }
|
505
|
-
assert File.exists?(
|
533
|
+
assert File.exists?(sassc_file)
|
506
534
|
end
|
507
535
|
|
508
536
|
def test_nonexistent_extensionless_import
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
WARN
|
537
|
+
assert_raise_message(Sass::SyntaxError, <<ERR.rstrip) do
|
538
|
+
File to import not found or unreadable: nonexistent.
|
539
|
+
Load path: .
|
540
|
+
ERR
|
514
541
|
assert_equal("@import url(nonexistent.css);\n", render("@import nonexistent"))
|
515
542
|
end
|
516
543
|
end
|
@@ -2204,6 +2231,7 @@ SASS
|
|
2204
2231
|
sass_file = load_file(name, "sass")
|
2205
2232
|
css_file = load_file(name, "css")
|
2206
2233
|
options[:filename] ||= filename(name, "sass")
|
2234
|
+
options[:syntax] ||= :sass
|
2207
2235
|
options[:css_filename] ||= filename(name, "css")
|
2208
2236
|
css_result = Sass::Engine.new(sass_file, options).render
|
2209
2237
|
assert_equal css_file, css_result
|
@@ -2221,7 +2249,10 @@ SASS
|
|
2221
2249
|
|
2222
2250
|
def sassc_path(template)
|
2223
2251
|
sassc_path = File.join(File.dirname(__FILE__) + "/templates/#{template}.sass")
|
2224
|
-
Sass::
|
2252
|
+
engine = Sass::Engine.new("", :filename => sassc_path,
|
2253
|
+
:importer => Sass::Importers::Filesystem.new("."))
|
2254
|
+
key = engine.send(:sassc_key)
|
2255
|
+
File.join(engine.options[:cache_location], key)
|
2225
2256
|
end
|
2226
2257
|
end
|
2227
2258
|
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
require File.dirname(__FILE__) + '/test_helper'
|
4
|
+
|
5
|
+
class ImporterTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
class FruitImporter < Sass::Importers::Base
|
8
|
+
def find(name, context = nil)
|
9
|
+
if name =~ %r{fruits/(\w+)(\.s[ac]ss)?}
|
10
|
+
fruit = $1
|
11
|
+
color = case $1
|
12
|
+
when "apple"
|
13
|
+
"red"
|
14
|
+
when "orange"
|
15
|
+
"orange"
|
16
|
+
else
|
17
|
+
"blue"
|
18
|
+
end
|
19
|
+
contents = %Q{
|
20
|
+
$#{fruit}-color: #{color} !default;
|
21
|
+
@mixin #{fruit} {
|
22
|
+
color: $#{fruit}-color;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
Sass::Engine.new(contents, :filename => name, :syntax => :scss, :importer => self)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def key(name, context)
|
30
|
+
[self.class.name, name]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# This class proves that you can override the extension scheme for importers
|
35
|
+
class ReversedExtImporter < Sass::Importers::Filesystem
|
36
|
+
def extensions
|
37
|
+
{"sscs" => :scss, "ssas" => :sass}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_can_resolve_generated_imports
|
42
|
+
scss_file = %Q{
|
43
|
+
$pear-color: green;
|
44
|
+
@import "fruits/apple"; @import "fruits/orange"; @import "fruits/pear";
|
45
|
+
.apple { @include apple; }
|
46
|
+
.orange { @include orange; }
|
47
|
+
.pear { @include pear; }
|
48
|
+
}
|
49
|
+
css_file = <<CSS
|
50
|
+
.apple { color: red; }
|
51
|
+
|
52
|
+
.orange { color: orange; }
|
53
|
+
|
54
|
+
.pear { color: green; }
|
55
|
+
CSS
|
56
|
+
options = {:style => :compact, :load_paths => [FruitImporter.new], :syntax => :scss}
|
57
|
+
assert_equal css_file, Sass::Engine.new(scss_file, options).render
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_extension_overrides
|
61
|
+
FileUtils.mkdir_p(absolutize("tmp"))
|
62
|
+
open(absolutize("tmp/foo.ssas"), "w") {|f| f.write(".foo\n reversed: true\n")}
|
63
|
+
open(absolutize("tmp/bar.sscs"), "w") {|f| f.write(".bar {reversed: true}\n")}
|
64
|
+
scss_file = %Q{
|
65
|
+
@import "foo", "bar";
|
66
|
+
@import "foo.ssas", "bar.sscs";
|
67
|
+
}
|
68
|
+
css_file = <<CSS
|
69
|
+
.foo { reversed: true; }
|
70
|
+
|
71
|
+
.bar { reversed: true; }
|
72
|
+
|
73
|
+
.foo { reversed: true; }
|
74
|
+
|
75
|
+
.bar { reversed: true; }
|
76
|
+
CSS
|
77
|
+
options = {:style => :compact, :load_paths => [ReversedExtImporter.new(absolutize("tmp"))], :syntax => :scss}
|
78
|
+
assert_equal css_file, Sass::Engine.new(scss_file, options).render
|
79
|
+
ensure
|
80
|
+
FileUtils.rm_rf(absolutize("tmp"))
|
81
|
+
end
|
82
|
+
end
|
data/test/sass/plugin_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
require File.dirname(__FILE__) + '/test_helper'
|
3
4
|
require 'sass/plugin'
|
4
5
|
require 'fileutils'
|
5
6
|
|
@@ -10,9 +11,11 @@ class SassPluginTest < Test::Unit::TestCase
|
|
10
11
|
options
|
11
12
|
}
|
12
13
|
|
14
|
+
@@cache_store = Sass::InMemoryCacheStore.new
|
15
|
+
|
13
16
|
def setup
|
14
|
-
FileUtils.
|
15
|
-
FileUtils.
|
17
|
+
FileUtils.mkdir_p tempfile_loc
|
18
|
+
FileUtils.mkdir_p tempfile_loc(nil,"more_")
|
16
19
|
set_plugin_opts
|
17
20
|
update_all_stylesheets!
|
18
21
|
reset_mtimes
|
@@ -20,7 +23,7 @@ class SassPluginTest < Test::Unit::TestCase
|
|
20
23
|
|
21
24
|
def teardown
|
22
25
|
clean_up_sassc
|
23
|
-
|
26
|
+
Sass::Plugin.reset!
|
24
27
|
FileUtils.rm_r tempfile_loc
|
25
28
|
FileUtils.rm_r tempfile_loc(nil,"more_")
|
26
29
|
end
|
@@ -250,7 +253,7 @@ CSS
|
|
250
253
|
|
251
254
|
def test_cached_dependencies_update
|
252
255
|
FileUtils.mv(template_loc("basic"), template_loc("basic", "more_"))
|
253
|
-
set_plugin_opts :load_paths => [
|
256
|
+
set_plugin_opts :load_paths => [template_loc(nil, "more_")]
|
254
257
|
|
255
258
|
touch 'basic', 'more_'
|
256
259
|
assert_needs_update "import"
|
@@ -260,6 +263,15 @@ CSS
|
|
260
263
|
FileUtils.mv(template_loc("basic", "more_"), template_loc("basic"))
|
261
264
|
end
|
262
265
|
|
266
|
+
def test_cached_relative_import
|
267
|
+
old_always_update = Sass::Plugin.options[:always_update]
|
268
|
+
Sass::Plugin.options[:always_update] = true
|
269
|
+
update_all_stylesheets!
|
270
|
+
assert_renders_correctly('subdir/subdir')
|
271
|
+
ensure
|
272
|
+
Sass::Plugin.options[:always_update] = old_always_update
|
273
|
+
end
|
274
|
+
|
263
275
|
private
|
264
276
|
|
265
277
|
def assert_renders_correctly(*arguments)
|
@@ -342,10 +354,6 @@ CSS
|
|
342
354
|
assert_no_callback(*args.pop) {assert_no_callbacks(*args)}
|
343
355
|
end
|
344
356
|
|
345
|
-
def clear_callbacks
|
346
|
-
Sass::Plugin.instance_variable_set('@_sass_callbacks', {})
|
347
|
-
end
|
348
|
-
|
349
357
|
def update_all_stylesheets!
|
350
358
|
Haml::Util.silence_haml_warnings do
|
351
359
|
Sass::Plugin.update_stylesheets
|
@@ -398,19 +406,17 @@ CSS
|
|
398
406
|
end
|
399
407
|
end
|
400
408
|
|
401
|
-
def absolutize(file)
|
402
|
-
"#{File.dirname(__FILE__)}/#{file}"
|
403
|
-
end
|
404
|
-
|
405
409
|
def set_plugin_opts(overrides = {})
|
406
|
-
Sass::Plugin.options
|
410
|
+
Sass::Plugin.options.merge!(
|
407
411
|
:template_location => template_loc,
|
408
412
|
:css_location => tempfile_loc,
|
409
413
|
:style => :compact,
|
410
|
-
:load_paths => [result_loc],
|
411
414
|
:always_update => true,
|
412
415
|
:never_update => false,
|
413
|
-
|
416
|
+
:full_exception => true,
|
417
|
+
:cache_store => @@cache_store
|
418
|
+
)
|
419
|
+
Sass::Plugin.options.merge!(overrides)
|
414
420
|
end
|
415
421
|
end
|
416
422
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml-edge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.74
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Weizenbaum
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2010-09-
|
14
|
+
date: 2010-09-13 00:00:00 -04:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -77,7 +77,6 @@ files:
|
|
77
77
|
- lib/sass/engine.rb
|
78
78
|
- lib/sass/environment.rb
|
79
79
|
- lib/sass/error.rb
|
80
|
-
- lib/sass/files.rb
|
81
80
|
- lib/sass/less.rb
|
82
81
|
- lib/sass/plugin.rb
|
83
82
|
- lib/sass/plugin/configuration.rb
|
@@ -86,6 +85,7 @@ files:
|
|
86
85
|
- lib/sass/plugin/rack.rb
|
87
86
|
- lib/sass/plugin/rails.rb
|
88
87
|
- lib/sass/plugin/staleness_checker.rb
|
88
|
+
- lib/sass/plugin/compiler.rb
|
89
89
|
- lib/sass/repl.rb
|
90
90
|
- lib/sass/script.rb
|
91
91
|
- lib/sass/script/bool.rb
|
@@ -135,6 +135,10 @@ files:
|
|
135
135
|
- lib/sass/tree/variable_node.rb
|
136
136
|
- lib/sass/tree/warn_node.rb
|
137
137
|
- lib/sass/tree/while_node.rb
|
138
|
+
- lib/sass/cache_store.rb
|
139
|
+
- lib/sass/importers.rb
|
140
|
+
- lib/sass/importers/base.rb
|
141
|
+
- lib/sass/importers/filesystem.rb
|
138
142
|
- vendor/fssm/LICENSE
|
139
143
|
- vendor/fssm/README.markdown
|
140
144
|
- vendor/fssm/Rakefile
|
@@ -316,6 +320,9 @@ files:
|
|
316
320
|
- test/sass/templates/units.sass
|
317
321
|
- test/sass/templates/warn.sass
|
318
322
|
- test/sass/templates/warn_imported.sass
|
323
|
+
- test/sass/cache_test.rb
|
324
|
+
- test/sass/importer_test.rb
|
325
|
+
- test/sass/test_helper.rb
|
319
326
|
- test/test_helper.rb
|
320
327
|
- extra/haml-mode.el
|
321
328
|
- extra/sass-mode.el
|
@@ -380,3 +387,5 @@ test_files:
|
|
380
387
|
- test/sass/scss/css_test.rb
|
381
388
|
- test/sass/scss/rx_test.rb
|
382
389
|
- test/sass/scss/scss_test.rb
|
390
|
+
- test/sass/cache_test.rb
|
391
|
+
- test/sass/importer_test.rb
|
data/lib/sass/files.rb
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
require 'digest/sha1'
|
2
|
-
require 'pathname'
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
module Sass
|
6
|
-
# This module contains various bits of functionality
|
7
|
-
# related to finding and caching Sass files.
|
8
|
-
module Files
|
9
|
-
extend self
|
10
|
-
|
11
|
-
# Returns the {Sass::Tree} for the given file,
|
12
|
-
# reading it from the Sass cache if possible.
|
13
|
-
#
|
14
|
-
# @param filename [String] The path to the Sass or SCSS file
|
15
|
-
# @param options [{Symbol => Object}] The options hash.
|
16
|
-
# Only the {file:SASS_REFERENCE.md#cache-option `:cache_location`} option is used
|
17
|
-
# @raise [Sass::SyntaxError] if there's an error in the document.
|
18
|
-
# The caller has responsibility for setting backtrace information, if necessary
|
19
|
-
def tree_for(filename, options)
|
20
|
-
default_options = Sass::Engine::DEFAULT_OPTIONS.dup
|
21
|
-
default_options.delete(:syntax)
|
22
|
-
options = default_options.merge!(options)
|
23
|
-
text = File.read(filename)
|
24
|
-
|
25
|
-
if options[:cache] || options[:read_cache]
|
26
|
-
compiled_filename = sassc_filename(filename, options)
|
27
|
-
sha = Digest::SHA1.hexdigest(text)
|
28
|
-
|
29
|
-
if root = try_to_read_sassc(filename, compiled_filename, sha)
|
30
|
-
root.options = options.merge(:filename => filename)
|
31
|
-
return root
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
options = options.merge(:filename => filename)
|
36
|
-
if filename =~ /\.scss$/
|
37
|
-
options = {:syntax => :scss}.merge(options)
|
38
|
-
elsif filename =~ /\.sass$/
|
39
|
-
options = {:syntax => :sass}.merge(options)
|
40
|
-
end
|
41
|
-
|
42
|
-
engine = Sass::Engine.new(text, options)
|
43
|
-
|
44
|
-
root = engine.to_tree
|
45
|
-
try_to_write_sassc(root, compiled_filename, sha, options) if options[:cache]
|
46
|
-
root
|
47
|
-
end
|
48
|
-
|
49
|
-
# Find the full filename of a Sass, SCSS, or CSS file to import.
|
50
|
-
# This follows Sass's import rules:
|
51
|
-
# if the filename given ends in `".sass"`, `".scss"`, or `".css"`,
|
52
|
-
# it will try to find that type of file;
|
53
|
-
# otherwise, it will try to find the corresponding Sass/SCSS file
|
54
|
-
# and fall back on CSS if it's not available.
|
55
|
-
#
|
56
|
-
# Any Sass/SCSS filename returned will correspond to
|
57
|
-
# an actual file of the corresponding type on the filesystem.
|
58
|
-
# CSS filenames, however, may not;
|
59
|
-
# they're expected to be put through directly to the stylesheet
|
60
|
-
# as CSS `@import` statements.
|
61
|
-
#
|
62
|
-
# @param filename [String] The filename to search for
|
63
|
-
# @param load_paths [Array<String>] The set of filesystem paths
|
64
|
-
# to search for Sass/SCSS files.
|
65
|
-
# @return [String] The filename of the imported file.
|
66
|
-
# This is an absolute path if the file is a `".sass"` or `".scss"` file.
|
67
|
-
# @raise [Sass::SyntaxError] if `filename` ends in `".sass"` or `".scss"`
|
68
|
-
# and no corresponding Sass/SCSS file could be found.
|
69
|
-
def find_file_to_import(filename, load_paths)
|
70
|
-
was_sass = was_scss = false
|
71
|
-
original_filename = filename
|
72
|
-
|
73
|
-
if [".sass", ".scss"].include?(filename[-5..-1])
|
74
|
-
was_sass = filename[-5..-1] == ".sass"
|
75
|
-
was_scss = filename[-5..-1] == ".scss"
|
76
|
-
filename = filename[0...-5]
|
77
|
-
elsif filename[-4..-1] == ".css"
|
78
|
-
return filename
|
79
|
-
end
|
80
|
-
|
81
|
-
new_filename = nil
|
82
|
-
load_paths = load_paths.uniq
|
83
|
-
load_paths.each do |load_path|
|
84
|
-
new_filename ||= find_full_path("#{filename}.sass", load_path) unless was_scss
|
85
|
-
new_filename ||= find_full_path("#{filename}.scss", load_path) unless was_sass
|
86
|
-
end
|
87
|
-
|
88
|
-
return new_filename if new_filename
|
89
|
-
unless was_sass || was_scss
|
90
|
-
Haml::Util.haml_warn <<END
|
91
|
-
WARNING: Neither #{filename}.sass nor .scss found. Using #{filename}.css instead.
|
92
|
-
This behavior is deprecated and will be removed in a future version.
|
93
|
-
If you really need #{filename}.css, import it explicitly.
|
94
|
-
END
|
95
|
-
return filename + '.css'
|
96
|
-
end
|
97
|
-
|
98
|
-
message = "File to import not found or unreadable: #{original_filename}.\n"
|
99
|
-
if load_paths.size == 1
|
100
|
-
message << "Load path: #{load_paths.first}"
|
101
|
-
else
|
102
|
-
message << "Load paths:\n " << load_paths.join("\n ")
|
103
|
-
end
|
104
|
-
|
105
|
-
raise SyntaxError.new(message)
|
106
|
-
end
|
107
|
-
|
108
|
-
private
|
109
|
-
|
110
|
-
def sassc_filename(filename, options)
|
111
|
-
File.join(options[:cache_location],
|
112
|
-
Digest::SHA1.hexdigest(File.dirname(File.expand_path(filename))),
|
113
|
-
File.basename(filename) + 'c')
|
114
|
-
end
|
115
|
-
|
116
|
-
def try_to_read_sassc(filename, compiled_filename, sha)
|
117
|
-
return unless File.readable?(compiled_filename)
|
118
|
-
|
119
|
-
File.open(compiled_filename, "rb") do |f|
|
120
|
-
return unless f.readline("\n").strip == Sass::VERSION
|
121
|
-
return unless f.readline("\n").strip == sha
|
122
|
-
return Marshal.load(f.read)
|
123
|
-
end
|
124
|
-
rescue EOFError, TypeError, ArgumentError => e
|
125
|
-
Haml::Util.haml_warn "Warning. Error encountered while reading cache #{compiled_filename}: #{e}"
|
126
|
-
end
|
127
|
-
|
128
|
-
def try_to_write_sassc(root, compiled_filename, sha, options)
|
129
|
-
return unless File.writable?(File.dirname(options[:cache_location]))
|
130
|
-
return if File.exists?(options[:cache_location]) && !File.writable?(options[:cache_location])
|
131
|
-
return if File.exists?(File.dirname(compiled_filename)) && !File.writable?(File.dirname(compiled_filename))
|
132
|
-
return if File.exists?(compiled_filename) && !File.writable?(compiled_filename)
|
133
|
-
FileUtils.mkdir_p(File.dirname(compiled_filename))
|
134
|
-
File.open(compiled_filename, "wb") do |f|
|
135
|
-
f.write(Sass::VERSION)
|
136
|
-
f.write("\n")
|
137
|
-
f.write(sha)
|
138
|
-
f.write("\n")
|
139
|
-
f.write(Marshal.dump(root))
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def find_full_path(filename, load_path)
|
144
|
-
partial_name = File.join(File.dirname(filename), "_#{File.basename(filename)}")
|
145
|
-
|
146
|
-
if Pathname.new(filename).absolute?
|
147
|
-
[partial_name, filename].each do |name|
|
148
|
-
return name if File.readable?(name)
|
149
|
-
end
|
150
|
-
return nil
|
151
|
-
end
|
152
|
-
|
153
|
-
[partial_name, filename].each do |name|
|
154
|
-
full_path = File.join(load_path, name)
|
155
|
-
return full_path if File.readable?(full_path)
|
156
|
-
end
|
157
|
-
nil
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|