sass 3.1.0.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +11 -0
- data/CONTRIBUTING +3 -0
- data/EDGE_GEM_VERSION +1 -0
- data/MIT-LICENSE +20 -0
- data/README.md +201 -0
- data/REVISION +1 -0
- data/Rakefile +353 -0
- data/VERSION +1 -0
- data/VERSION_NAME +1 -0
- data/bin/css2sass +13 -0
- data/bin/sass +8 -0
- data/bin/sass-convert +7 -0
- data/extra/update_watch.rb +13 -0
- data/init.rb +18 -0
- data/lib/sass.rb +71 -0
- data/lib/sass/cache_store.rb +208 -0
- data/lib/sass/callbacks.rb +66 -0
- data/lib/sass/css.rb +294 -0
- data/lib/sass/engine.rb +792 -0
- data/lib/sass/environment.rb +143 -0
- data/lib/sass/error.rb +201 -0
- data/lib/sass/exec.rb +619 -0
- data/lib/sass/importers.rb +22 -0
- data/lib/sass/importers/base.rb +138 -0
- data/lib/sass/importers/filesystem.rb +121 -0
- data/lib/sass/less.rb +363 -0
- data/lib/sass/plugin.rb +126 -0
- data/lib/sass/plugin/compiler.rb +346 -0
- data/lib/sass/plugin/configuration.rb +123 -0
- data/lib/sass/plugin/generic.rb +15 -0
- data/lib/sass/plugin/merb.rb +48 -0
- data/lib/sass/plugin/rack.rb +47 -0
- data/lib/sass/plugin/rails.rb +41 -0
- data/lib/sass/plugin/staleness_checker.rb +145 -0
- data/lib/sass/railtie.rb +8 -0
- data/lib/sass/repl.rb +58 -0
- data/lib/sass/root.rb +7 -0
- data/lib/sass/script.rb +63 -0
- data/lib/sass/script/bool.rb +18 -0
- data/lib/sass/script/color.rb +490 -0
- data/lib/sass/script/css_lexer.rb +29 -0
- data/lib/sass/script/css_parser.rb +31 -0
- data/lib/sass/script/funcall.rb +78 -0
- data/lib/sass/script/functions.rb +852 -0
- data/lib/sass/script/interpolation.rb +70 -0
- data/lib/sass/script/lexer.rb +337 -0
- data/lib/sass/script/literal.rb +236 -0
- data/lib/sass/script/node.rb +101 -0
- data/lib/sass/script/number.rb +420 -0
- data/lib/sass/script/operation.rb +92 -0
- data/lib/sass/script/parser.rb +392 -0
- data/lib/sass/script/string.rb +67 -0
- data/lib/sass/script/string_interpolation.rb +93 -0
- data/lib/sass/script/unary_operation.rb +57 -0
- data/lib/sass/script/variable.rb +48 -0
- data/lib/sass/scss.rb +17 -0
- data/lib/sass/scss/css_parser.rb +51 -0
- data/lib/sass/scss/parser.rb +838 -0
- data/lib/sass/scss/rx.rb +126 -0
- data/lib/sass/scss/sass_parser.rb +11 -0
- data/lib/sass/scss/script_lexer.rb +15 -0
- data/lib/sass/scss/script_parser.rb +25 -0
- data/lib/sass/scss/static_parser.rb +40 -0
- data/lib/sass/selector.rb +361 -0
- data/lib/sass/selector/abstract_sequence.rb +62 -0
- data/lib/sass/selector/comma_sequence.rb +82 -0
- data/lib/sass/selector/sequence.rb +236 -0
- data/lib/sass/selector/simple.rb +113 -0
- data/lib/sass/selector/simple_sequence.rb +135 -0
- data/lib/sass/shared.rb +78 -0
- data/lib/sass/tree/comment_node.rb +128 -0
- data/lib/sass/tree/debug_node.rb +36 -0
- data/lib/sass/tree/directive_node.rb +75 -0
- data/lib/sass/tree/extend_node.rb +65 -0
- data/lib/sass/tree/for_node.rb +67 -0
- data/lib/sass/tree/if_node.rb +81 -0
- data/lib/sass/tree/import_node.rb +124 -0
- data/lib/sass/tree/mixin_def_node.rb +60 -0
- data/lib/sass/tree/mixin_node.rb +123 -0
- data/lib/sass/tree/node.rb +490 -0
- data/lib/sass/tree/prop_node.rb +220 -0
- data/lib/sass/tree/root_node.rb +125 -0
- data/lib/sass/tree/rule_node.rb +273 -0
- data/lib/sass/tree/variable_node.rb +39 -0
- data/lib/sass/tree/warn_node.rb +42 -0
- data/lib/sass/tree/while_node.rb +48 -0
- data/lib/sass/util.rb +687 -0
- data/lib/sass/util/subset_map.rb +101 -0
- data/lib/sass/version.rb +109 -0
- data/rails/init.rb +1 -0
- data/test/sass/cache_test.rb +74 -0
- data/test/sass/callbacks_test.rb +61 -0
- data/test/sass/conversion_test.rb +1210 -0
- data/test/sass/css2sass_test.rb +364 -0
- data/test/sass/data/hsl-rgb.txt +319 -0
- data/test/sass/engine_test.rb +2273 -0
- data/test/sass/extend_test.rb +1348 -0
- data/test/sass/functions_test.rb +565 -0
- data/test/sass/importer_test.rb +104 -0
- data/test/sass/less_conversion_test.rb +632 -0
- data/test/sass/mock_importer.rb +49 -0
- data/test/sass/more_results/more1.css +9 -0
- data/test/sass/more_results/more1_with_line_comments.css +26 -0
- data/test/sass/more_results/more_import.css +29 -0
- data/test/sass/more_templates/_more_partial.sass +2 -0
- data/test/sass/more_templates/more1.sass +23 -0
- data/test/sass/more_templates/more_import.sass +11 -0
- data/test/sass/plugin_test.rb +430 -0
- data/test/sass/results/alt.css +4 -0
- data/test/sass/results/basic.css +9 -0
- data/test/sass/results/compact.css +5 -0
- data/test/sass/results/complex.css +86 -0
- data/test/sass/results/compressed.css +1 -0
- data/test/sass/results/expanded.css +19 -0
- data/test/sass/results/import.css +31 -0
- data/test/sass/results/line_numbers.css +49 -0
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/results/nested.css +22 -0
- data/test/sass/results/options.css +1 -0
- data/test/sass/results/parent_ref.css +13 -0
- data/test/sass/results/script.css +16 -0
- data/test/sass/results/scss_import.css +31 -0
- data/test/sass/results/scss_importee.css +2 -0
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
- data/test/sass/results/subdir/subdir.css +3 -0
- data/test/sass/results/units.css +11 -0
- data/test/sass/results/warn.css +0 -0
- data/test/sass/results/warn_imported.css +0 -0
- data/test/sass/script_conversion_test.rb +254 -0
- data/test/sass/script_test.rb +459 -0
- data/test/sass/scss/css_test.rb +897 -0
- data/test/sass/scss/rx_test.rb +156 -0
- data/test/sass/scss/scss_test.rb +1088 -0
- data/test/sass/scss/test_helper.rb +37 -0
- data/test/sass/templates/_partial.sass +2 -0
- data/test/sass/templates/alt.sass +16 -0
- data/test/sass/templates/basic.sass +23 -0
- data/test/sass/templates/bork1.sass +2 -0
- data/test/sass/templates/bork2.sass +2 -0
- data/test/sass/templates/bork3.sass +2 -0
- data/test/sass/templates/bork4.sass +2 -0
- data/test/sass/templates/compact.sass +17 -0
- data/test/sass/templates/complex.sass +305 -0
- data/test/sass/templates/compressed.sass +15 -0
- data/test/sass/templates/expanded.sass +17 -0
- data/test/sass/templates/import.sass +12 -0
- data/test/sass/templates/importee.less +2 -0
- data/test/sass/templates/importee.sass +19 -0
- data/test/sass/templates/line_numbers.sass +13 -0
- data/test/sass/templates/mixin_bork.sass +5 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/sass/templates/nested.sass +25 -0
- data/test/sass/templates/nested_bork1.sass +2 -0
- data/test/sass/templates/nested_bork2.sass +2 -0
- data/test/sass/templates/nested_bork3.sass +2 -0
- data/test/sass/templates/nested_bork4.sass +2 -0
- data/test/sass/templates/nested_mixin_bork.sass +6 -0
- data/test/sass/templates/options.sass +2 -0
- data/test/sass/templates/parent_ref.sass +25 -0
- data/test/sass/templates/script.sass +101 -0
- data/test/sass/templates/scss_import.scss +11 -0
- data/test/sass/templates/scss_importee.scss +1 -0
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
- data/test/sass/templates/subdir/subdir.sass +6 -0
- data/test/sass/templates/units.sass +11 -0
- data/test/sass/templates/warn.sass +3 -0
- data/test/sass/templates/warn_imported.sass +4 -0
- data/test/sass/test_helper.rb +8 -0
- data/test/sass/util/subset_map_test.rb +91 -0
- data/test/sass/util_test.rb +275 -0
- data/test/test_helper.rb +64 -0
- data/vendor/fssm/LICENSE +20 -0
- data/vendor/fssm/README.markdown +55 -0
- data/vendor/fssm/Rakefile +59 -0
- data/vendor/fssm/VERSION.yml +5 -0
- data/vendor/fssm/example.rb +9 -0
- data/vendor/fssm/fssm.gemspec +77 -0
- data/vendor/fssm/lib/fssm.rb +33 -0
- data/vendor/fssm/lib/fssm/backends/fsevents.rb +36 -0
- data/vendor/fssm/lib/fssm/backends/inotify.rb +26 -0
- data/vendor/fssm/lib/fssm/backends/polling.rb +25 -0
- data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +131 -0
- data/vendor/fssm/lib/fssm/monitor.rb +26 -0
- data/vendor/fssm/lib/fssm/path.rb +91 -0
- data/vendor/fssm/lib/fssm/pathname.rb +502 -0
- data/vendor/fssm/lib/fssm/state/directory.rb +57 -0
- data/vendor/fssm/lib/fssm/state/file.rb +24 -0
- data/vendor/fssm/lib/fssm/support.rb +63 -0
- data/vendor/fssm/lib/fssm/tree.rb +176 -0
- data/vendor/fssm/profile/prof-cache.rb +40 -0
- data/vendor/fssm/profile/prof-fssm-pathname.html +1231 -0
- data/vendor/fssm/profile/prof-pathname.rb +68 -0
- data/vendor/fssm/profile/prof-plain-pathname.html +988 -0
- data/vendor/fssm/profile/prof.html +2379 -0
- data/vendor/fssm/spec/path_spec.rb +75 -0
- data/vendor/fssm/spec/root/duck/quack.txt +0 -0
- data/vendor/fssm/spec/root/file.css +0 -0
- data/vendor/fssm/spec/root/file.rb +0 -0
- data/vendor/fssm/spec/root/file.yml +0 -0
- data/vendor/fssm/spec/root/moo/cow.txt +0 -0
- data/vendor/fssm/spec/spec_helper.rb +14 -0
- metadata +297 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
module Util
|
5
|
+
# A map from sets to values.
|
6
|
+
# A value is \{#\[]= set} by providing a set (the "set-set") and a value,
|
7
|
+
# which is then recorded as corresponding to that set.
|
8
|
+
# Values are \{#\[] accessed} by providing a set (the "get-set")
|
9
|
+
# and returning all values that correspond to set-sets
|
10
|
+
# that are subsets of the get-set.
|
11
|
+
#
|
12
|
+
# SubsetMap preserves the order of values as they're inserted.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# ssm = SubsetMap.new
|
16
|
+
# ssm[Set[1, 2]] = "Foo"
|
17
|
+
# ssm[Set[2, 3]] = "Bar"
|
18
|
+
# ssm[Set[1, 2, 3]] = "Baz"
|
19
|
+
#
|
20
|
+
# ssm[Set[1, 2, 3]] #=> ["Foo", "Bar", "Baz"]
|
21
|
+
class SubsetMap
|
22
|
+
# Creates a new, empty SubsetMap.
|
23
|
+
def initialize
|
24
|
+
@hash = {}
|
25
|
+
@vals = []
|
26
|
+
end
|
27
|
+
|
28
|
+
# Whether or not this SubsetMap has any key-value pairs.
|
29
|
+
#
|
30
|
+
# @return [Boolean]
|
31
|
+
def empty?
|
32
|
+
@hash.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
# Associates a value with a set.
|
36
|
+
# When `set` or any of its supersets is accessed,
|
37
|
+
# `value` will be among the values returned.
|
38
|
+
#
|
39
|
+
# Note that if the same `set` is passed to this method multiple times,
|
40
|
+
# all given `value`s will be associated with that `set`.
|
41
|
+
#
|
42
|
+
# This runs in `O(n)` time, where `n` is the size of `set`.
|
43
|
+
#
|
44
|
+
# @param set [#to_set] The set to use as the map key. May not be empty.
|
45
|
+
# @param value [Object] The value to associate with `set`.
|
46
|
+
# @raise [ArgumentError] If `set` is empty.
|
47
|
+
def []=(set, value)
|
48
|
+
raise ArgumentError.new("SubsetMap keys may not be empty.") if set.empty?
|
49
|
+
|
50
|
+
index = @vals.size
|
51
|
+
@vals << value
|
52
|
+
set.each do |k|
|
53
|
+
@hash[k] ||= []
|
54
|
+
@hash[k] << [set, set.to_set, index]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns all values associated with subsets of `set`.
|
59
|
+
#
|
60
|
+
# In the worst case, this runs in `O(m*max(n, log m))` time,
|
61
|
+
# where `n` is the size of `set`
|
62
|
+
# and `m` is the number of assocations in the map.
|
63
|
+
# However, unless many keys in the map overlap with `set`,
|
64
|
+
# `m` will typically be much smaller.
|
65
|
+
#
|
66
|
+
# @param set [Set] The set to use as the map key.
|
67
|
+
# @return [Array<(Object, #to_set)>] An array of pairs,
|
68
|
+
# where the first value is the value associated with a subset of `set`,
|
69
|
+
# and the second value is that subset of `set`
|
70
|
+
# (or whatever `#to_set` object was used to set the value)
|
71
|
+
# This array is in insertion order.
|
72
|
+
# @see #[]
|
73
|
+
def get(set)
|
74
|
+
res = set.map do |k|
|
75
|
+
next unless subsets = @hash[k]
|
76
|
+
subsets.map do |subenum, subset, index|
|
77
|
+
next unless subset.subset?(set)
|
78
|
+
[index, subenum]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
res = Sass::Util.flatten(res, 1)
|
82
|
+
res.compact!
|
83
|
+
res.uniq!
|
84
|
+
res.sort!
|
85
|
+
res.map! {|i, s| [@vals[i], s]}
|
86
|
+
return res
|
87
|
+
end
|
88
|
+
|
89
|
+
# Same as \{#get}, but doesn't return the subsets of the argument
|
90
|
+
# for which values were found.
|
91
|
+
#
|
92
|
+
# @param set [Set] The set to use as the map key.
|
93
|
+
# @return [Array] The array of all values
|
94
|
+
# associated with subsets of `set`, in insertion order.
|
95
|
+
# @see #get
|
96
|
+
def [](set)
|
97
|
+
get(set).map {|v, _| v}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/sass/version.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'sass/util'
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
# Handles Sass version-reporting.
|
5
|
+
# Sass not only reports the standard three version numbers,
|
6
|
+
# but its Git revision hash as well,
|
7
|
+
# if it was installed from Git.
|
8
|
+
module Version
|
9
|
+
include Sass::Util
|
10
|
+
|
11
|
+
# Returns a hash representing the version of Sass.
|
12
|
+
# The `:major`, `:minor`, and `:teeny` keys have their respective numbers as Fixnums.
|
13
|
+
# The `:name` key has the name of the version.
|
14
|
+
# The `:string` key contains a human-readable string representation of the version.
|
15
|
+
# The `:number` key is the major, minor, and teeny keys separated by periods.
|
16
|
+
# If Sass is checked out from Git, the `:rev` key will have the revision hash.
|
17
|
+
# For example:
|
18
|
+
#
|
19
|
+
# {
|
20
|
+
# :string => "2.1.0.9616393",
|
21
|
+
# :rev => "9616393b8924ef36639c7e82aa88a51a24d16949",
|
22
|
+
# :number => "2.1.0",
|
23
|
+
# :major => 2, :minor => 1, :teeny => 0
|
24
|
+
# }
|
25
|
+
#
|
26
|
+
# If a prerelease version of Sass is being used,
|
27
|
+
# the `:string` and `:number` fields will reflect the full version
|
28
|
+
# (e.g. `"2.2.beta.1"`), and the `:teeny` field will be `-1`.
|
29
|
+
# A `:prerelease` key will contain the name of the prerelease (e.g. `"beta"`),
|
30
|
+
# and a `:prerelease_number` key will contain the rerelease number.
|
31
|
+
# For example:
|
32
|
+
#
|
33
|
+
# {
|
34
|
+
# :string => "3.0.beta.1",
|
35
|
+
# :number => "3.0.beta.1",
|
36
|
+
# :major => 3, :minor => 0, :teeny => -1,
|
37
|
+
# :prerelease => "beta",
|
38
|
+
# :prerelease_number => 1
|
39
|
+
# }
|
40
|
+
#
|
41
|
+
# @return [{Symbol => String/Fixnum}] The version hash
|
42
|
+
def version
|
43
|
+
return @@version if defined?(@@version)
|
44
|
+
|
45
|
+
numbers = File.read(scope('VERSION')).strip.split('.').
|
46
|
+
map {|n| n =~ /^[0-9]+$/ ? n.to_i : n}
|
47
|
+
name = File.read(scope('VERSION_NAME')).strip
|
48
|
+
@@version = {
|
49
|
+
:major => numbers[0],
|
50
|
+
:minor => numbers[1],
|
51
|
+
:teeny => numbers[2],
|
52
|
+
:name => name
|
53
|
+
}
|
54
|
+
|
55
|
+
if numbers[3].is_a?(String)
|
56
|
+
@@version[:teeny] = -1
|
57
|
+
@@version[:prerelease] = numbers[3]
|
58
|
+
@@version[:prerelease_number] = numbers[4]
|
59
|
+
end
|
60
|
+
|
61
|
+
@@version[:number] = numbers.join('.')
|
62
|
+
@@version[:string] = @@version[:number].dup
|
63
|
+
|
64
|
+
if rev = revision_number
|
65
|
+
@@version[:rev] = rev
|
66
|
+
unless rev[0] == ?(
|
67
|
+
@@version[:string] << "." << rev[0...7]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
@@version[:string] << " (#{name})"
|
72
|
+
@@version
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def revision_number
|
78
|
+
if File.exists?(scope('REVISION'))
|
79
|
+
rev = File.read(scope('REVISION')).strip
|
80
|
+
return rev unless rev =~ /^([a-f0-9]+|\(.*\))$/ || rev == '(unknown)'
|
81
|
+
end
|
82
|
+
|
83
|
+
return unless File.exists?(scope('.git/HEAD'))
|
84
|
+
rev = File.read(scope('.git/HEAD')).strip
|
85
|
+
return rev unless rev =~ /^ref: (.*)$/
|
86
|
+
|
87
|
+
ref_name = $1
|
88
|
+
ref_file = scope(".git/#{ref_name}")
|
89
|
+
info_file = scope(".git/info/refs")
|
90
|
+
return File.read(ref_file).strip if File.exists?(ref_file)
|
91
|
+
return unless File.exists?(info_file)
|
92
|
+
File.open(info_file) do |f|
|
93
|
+
f.each do |l|
|
94
|
+
sha, ref = l.strip.split("\t", 2)
|
95
|
+
next unless ref == ref_name
|
96
|
+
return sha
|
97
|
+
end
|
98
|
+
end
|
99
|
+
return nil
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
extend Sass::Version
|
104
|
+
|
105
|
+
# A string representing the version of Sass.
|
106
|
+
# A more fine-grained representation is available from Sass.version.
|
107
|
+
# @api public
|
108
|
+
VERSION = version[:string] unless defined?(Sass::VERSION)
|
109
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Kernel.load File.join(File.dirname(__FILE__), '..', 'init.rb')
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
require 'sass/engine'
|
4
|
+
|
5
|
+
class CacheTest < Test::Unit::TestCase
|
6
|
+
@@cache_dir = "tmp/file_cache"
|
7
|
+
|
8
|
+
def setup
|
9
|
+
FileUtils.mkdir_p @@cache_dir
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
FileUtils.rm_rf @@cache_dir
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_file_cache_writes_a_file
|
17
|
+
file_store = Sass::FileCacheStore.new(@@cache_dir)
|
18
|
+
file_store.store("asdf/foo.scssc", "fakesha1", root_node)
|
19
|
+
assert File.exists?("#{@@cache_dir}/asdf/foo.scssc")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_file_cache_reads_a_file
|
23
|
+
file_store = Sass::FileCacheStore.new(@@cache_dir)
|
24
|
+
assert !File.exists?("#{@@cache_dir}/asdf/foo.scssc")
|
25
|
+
file_store.store("asdf/foo.scssc", "fakesha1", root_node)
|
26
|
+
assert File.exists?("#{@@cache_dir}/asdf/foo.scssc")
|
27
|
+
assert_kind_of Sass::Tree::RootNode, file_store.retrieve("asdf/foo.scssc", "fakesha1")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_file_cache_miss_returns_nil
|
31
|
+
file_store = Sass::FileCacheStore.new(@@cache_dir)
|
32
|
+
assert !File.exists?("#{@@cache_dir}/asdf/foo.scssc")
|
33
|
+
assert_nil file_store.retrieve("asdf/foo.scssc", "fakesha1")
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_sha_change_invalidates_cache_and_cleans_up
|
37
|
+
file_store = Sass::FileCacheStore.new(@@cache_dir)
|
38
|
+
assert !File.exists?("#{@@cache_dir}/asdf/foo.scssc")
|
39
|
+
file_store.store("asdf/foo.scssc", "fakesha1", root_node)
|
40
|
+
assert File.exists?("#{@@cache_dir}/asdf/foo.scssc")
|
41
|
+
assert_nil file_store.retrieve("asdf/foo.scssc", "differentsha1")
|
42
|
+
assert !File.exists?("#{@@cache_dir}/asdf/foo.scssc")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_version_change_invalidates_cache_and_cleans_up
|
46
|
+
file_store = Sass::FileCacheStore.new(@@cache_dir)
|
47
|
+
assert !File.exists?("#{@@cache_dir}/asdf/foo.scssc")
|
48
|
+
file_store.store("asdf/foo.scssc", "fakesha1", root_node)
|
49
|
+
assert File.exists?("#{@@cache_dir}/asdf/foo.scssc")
|
50
|
+
real_version = Sass::VERSION
|
51
|
+
begin
|
52
|
+
Sass::VERSION.replace("a different version")
|
53
|
+
assert_nil file_store.retrieve("asdf/foo.scssc", "fakesha1")
|
54
|
+
assert !File.exists?("#{@@cache_dir}/asdf/foo.scssc")
|
55
|
+
ensure
|
56
|
+
Sass::VERSION.replace(real_version)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_arbitrary_objects_can_go_into_cache
|
61
|
+
cache = Sass::InMemoryCacheStore.new
|
62
|
+
an_object = {:foo => :bar}
|
63
|
+
cache.store("an_object", "", an_object)
|
64
|
+
assert_equal an_object, cache.retrieve("an_object", "")
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def root_node
|
69
|
+
Sass::Engine.new(<<-SCSS, :syntax => :scss).to_tree
|
70
|
+
@mixin color($c) { color: $c}
|
71
|
+
div { @include color(red); }
|
72
|
+
SCSS
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
require 'sass/callbacks'
|
4
|
+
|
5
|
+
class CallerBack
|
6
|
+
extend Sass::Callbacks
|
7
|
+
define_callback :foo
|
8
|
+
define_callback :bar
|
9
|
+
|
10
|
+
def do_foo
|
11
|
+
run_foo
|
12
|
+
end
|
13
|
+
|
14
|
+
def do_bar
|
15
|
+
run_bar 12
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassLevelCallerBack
|
20
|
+
extend Sass::Callbacks
|
21
|
+
define_callback :foo
|
22
|
+
extend self
|
23
|
+
|
24
|
+
def do_foo
|
25
|
+
run_foo
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class SassCallbacksTest < Test::Unit::TestCase
|
30
|
+
def test_simple_callback
|
31
|
+
cb = CallerBack.new
|
32
|
+
there = false
|
33
|
+
cb.on_foo {there = true}
|
34
|
+
cb.do_foo
|
35
|
+
assert there, "Expected callback to be called."
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_multiple_callbacks
|
39
|
+
cb = CallerBack.new
|
40
|
+
str = ""
|
41
|
+
cb.on_foo {str += "first"}
|
42
|
+
cb.on_foo {str += " second"}
|
43
|
+
cb.do_foo
|
44
|
+
assert_equal "first second", str
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_callback_with_arg
|
48
|
+
cb = CallerBack.new
|
49
|
+
val = nil
|
50
|
+
cb.on_bar {|a| val = a}
|
51
|
+
cb.do_bar
|
52
|
+
assert_equal 12, val
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_class_level_callback
|
56
|
+
there = false
|
57
|
+
ClassLevelCallerBack.on_foo {there = true}
|
58
|
+
ClassLevelCallerBack.do_foo
|
59
|
+
assert there, "Expected callback to be called."
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,1210 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
|
4
|
+
class ConversionTest < Test::Unit::TestCase
|
5
|
+
def test_basic
|
6
|
+
assert_renders <<SASS, <<SCSS
|
7
|
+
foo bar
|
8
|
+
baz: bang
|
9
|
+
bip: bop
|
10
|
+
SASS
|
11
|
+
foo bar {
|
12
|
+
baz: bang;
|
13
|
+
bip: bop; }
|
14
|
+
SCSS
|
15
|
+
assert_renders <<SASS, <<SCSS, :old => true
|
16
|
+
foo bar
|
17
|
+
:baz bang
|
18
|
+
:bip bop
|
19
|
+
SASS
|
20
|
+
foo bar {
|
21
|
+
baz: bang;
|
22
|
+
bip: bop; }
|
23
|
+
SCSS
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_empty_selector
|
27
|
+
assert_renders "foo bar", "foo bar {}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_empty_directive
|
31
|
+
assert_scss_to_sass "@media screen", "@media screen {}"
|
32
|
+
assert_scss_to_scss "@media screen {}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_empty_control_directive
|
36
|
+
assert_renders "@if false", "@if false {}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_nesting
|
40
|
+
assert_renders <<SASS, <<SCSS
|
41
|
+
foo bar
|
42
|
+
baz bang
|
43
|
+
baz: bang
|
44
|
+
bip: bop
|
45
|
+
blat: boo
|
46
|
+
SASS
|
47
|
+
foo bar {
|
48
|
+
baz bang {
|
49
|
+
baz: bang;
|
50
|
+
bip: bop; }
|
51
|
+
blat: boo; }
|
52
|
+
SCSS
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_nesting_with_parent_ref
|
56
|
+
assert_renders <<SASS, <<SCSS
|
57
|
+
foo bar
|
58
|
+
&:hover
|
59
|
+
baz: bang
|
60
|
+
SASS
|
61
|
+
foo bar {
|
62
|
+
&:hover {
|
63
|
+
baz: bang; } }
|
64
|
+
SCSS
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_selector_interpolation
|
68
|
+
assert_renders <<SASS, <<SCSS
|
69
|
+
foo \#{$bar + "baz"}.bip
|
70
|
+
baz: bang
|
71
|
+
SASS
|
72
|
+
foo \#{$bar + "baz"}.bip {
|
73
|
+
baz: bang; }
|
74
|
+
SCSS
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_multiline_selector_with_commas
|
78
|
+
assert_renders <<SASS, <<SCSS
|
79
|
+
foo bar,
|
80
|
+
baz bang
|
81
|
+
baz: bang
|
82
|
+
SASS
|
83
|
+
foo bar,
|
84
|
+
baz bang {
|
85
|
+
baz: bang; }
|
86
|
+
SCSS
|
87
|
+
|
88
|
+
assert_renders <<SASS, <<SCSS
|
89
|
+
blat
|
90
|
+
foo bar,
|
91
|
+
baz bang
|
92
|
+
baz: bang
|
93
|
+
SASS
|
94
|
+
blat {
|
95
|
+
foo bar,
|
96
|
+
baz bang {
|
97
|
+
baz: bang; } }
|
98
|
+
SCSS
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_multiline_selector_without_commas
|
102
|
+
assert_scss_to_sass <<SASS, <<SCSS
|
103
|
+
foo bar baz bang
|
104
|
+
baz: bang
|
105
|
+
SASS
|
106
|
+
foo bar
|
107
|
+
baz bang {
|
108
|
+
baz: bang; }
|
109
|
+
SCSS
|
110
|
+
|
111
|
+
assert_scss_to_scss <<SCSS
|
112
|
+
foo bar
|
113
|
+
baz bang {
|
114
|
+
baz: bang; }
|
115
|
+
SCSS
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_escaped_selector
|
119
|
+
assert_renders <<SASS, <<SCSS
|
120
|
+
foo bar
|
121
|
+
\\:hover
|
122
|
+
baz: bang
|
123
|
+
SASS
|
124
|
+
foo bar {
|
125
|
+
:hover {
|
126
|
+
baz: bang; } }
|
127
|
+
SCSS
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_property_name_interpolation
|
131
|
+
assert_renders <<SASS, <<SCSS
|
132
|
+
foo bar
|
133
|
+
baz\#{$bang}bip\#{$bop}: 12
|
134
|
+
SASS
|
135
|
+
foo bar {
|
136
|
+
baz\#{$bang}bip\#{$bop}: 12; }
|
137
|
+
SCSS
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_property_name_interpolation
|
141
|
+
assert_renders <<SASS, <<SCSS
|
142
|
+
foo bar
|
143
|
+
baz\#{$bang}bip\#{$bop}: 12
|
144
|
+
SASS
|
145
|
+
foo bar {
|
146
|
+
baz\#{$bang}bip\#{$bop}: 12; }
|
147
|
+
SCSS
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_property_value_interpolation
|
151
|
+
assert_renders <<SASS, <<SCSS
|
152
|
+
foo bar
|
153
|
+
baz: 12 \#{$bang} bip \#{"bop"} blat
|
154
|
+
SASS
|
155
|
+
foo bar {
|
156
|
+
baz: 12 \#{$bang} bip \#{"bop"} blat; }
|
157
|
+
SCSS
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_dynamic_properties
|
161
|
+
assert_renders <<SASS, <<SCSS
|
162
|
+
foo bar
|
163
|
+
baz: 12 $bang "bip"
|
164
|
+
SASS
|
165
|
+
foo bar {
|
166
|
+
baz: 12 $bang "bip"; }
|
167
|
+
SCSS
|
168
|
+
|
169
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
170
|
+
foo bar {
|
171
|
+
baz: 12 $bang bip; }
|
172
|
+
SCSS
|
173
|
+
foo bar
|
174
|
+
baz= 12 $bang "bip"
|
175
|
+
SASS
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_dynamic_properties_with_old
|
179
|
+
assert_renders <<SASS, <<SCSS, :old => true
|
180
|
+
foo bar
|
181
|
+
:baz 12 $bang "bip"
|
182
|
+
SASS
|
183
|
+
foo bar {
|
184
|
+
baz: 12 $bang "bip"; }
|
185
|
+
SCSS
|
186
|
+
|
187
|
+
assert_sass_to_scss <<SCSS, <<SASS, :old => true
|
188
|
+
foo bar {
|
189
|
+
baz: 12 $bang bip; }
|
190
|
+
SCSS
|
191
|
+
foo bar
|
192
|
+
:baz= 12 $bang "bip"
|
193
|
+
SASS
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_multiline_properties
|
197
|
+
assert_scss_to_sass <<SASS, <<SCSS
|
198
|
+
foo bar
|
199
|
+
baz: bip bam boon
|
200
|
+
SASS
|
201
|
+
foo bar {
|
202
|
+
baz:
|
203
|
+
bip
|
204
|
+
bam
|
205
|
+
boon; }
|
206
|
+
SCSS
|
207
|
+
|
208
|
+
assert_scss_to_scss <<OUT, <<IN
|
209
|
+
foo bar {
|
210
|
+
baz: bip bam boon; }
|
211
|
+
OUT
|
212
|
+
foo bar {
|
213
|
+
baz:
|
214
|
+
bip
|
215
|
+
bam
|
216
|
+
boon; }
|
217
|
+
IN
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_multiline_dynamic_properties
|
221
|
+
assert_scss_to_sass <<SASS, <<SCSS
|
222
|
+
foo bar
|
223
|
+
baz: $bip "bam" 12px
|
224
|
+
SASS
|
225
|
+
foo bar {
|
226
|
+
baz:
|
227
|
+
$bip
|
228
|
+
"bam"
|
229
|
+
12px; }
|
230
|
+
SCSS
|
231
|
+
|
232
|
+
assert_scss_to_scss <<OUT, <<IN
|
233
|
+
foo bar {
|
234
|
+
baz: $bip "bam" 12px; }
|
235
|
+
OUT
|
236
|
+
foo bar {
|
237
|
+
baz:
|
238
|
+
$bip
|
239
|
+
"bam"
|
240
|
+
12px; }
|
241
|
+
IN
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_silent_comments
|
245
|
+
assert_renders <<SASS, <<SCSS
|
246
|
+
// foo
|
247
|
+
|
248
|
+
// bar
|
249
|
+
|
250
|
+
// baz
|
251
|
+
|
252
|
+
foo bar
|
253
|
+
a: b
|
254
|
+
SASS
|
255
|
+
// foo
|
256
|
+
|
257
|
+
// bar
|
258
|
+
|
259
|
+
// baz
|
260
|
+
|
261
|
+
foo bar {
|
262
|
+
a: b; }
|
263
|
+
SCSS
|
264
|
+
|
265
|
+
assert_renders <<SASS, <<SCSS
|
266
|
+
// foo
|
267
|
+
// bar
|
268
|
+
// baz
|
269
|
+
// bang
|
270
|
+
|
271
|
+
foo bar
|
272
|
+
a: b
|
273
|
+
SASS
|
274
|
+
// foo
|
275
|
+
// bar
|
276
|
+
// baz
|
277
|
+
// bang
|
278
|
+
|
279
|
+
foo bar {
|
280
|
+
a: b; }
|
281
|
+
SCSS
|
282
|
+
|
283
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
284
|
+
// foo
|
285
|
+
// bar
|
286
|
+
// baz
|
287
|
+
// bang
|
288
|
+
|
289
|
+
foo bar {
|
290
|
+
a: b; }
|
291
|
+
SCSS
|
292
|
+
// foo
|
293
|
+
// bar
|
294
|
+
// baz
|
295
|
+
// bang
|
296
|
+
|
297
|
+
foo bar
|
298
|
+
a: b
|
299
|
+
SASS
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_nested_silent_comments
|
303
|
+
assert_renders <<SASS, <<SCSS
|
304
|
+
foo
|
305
|
+
bar: baz
|
306
|
+
// bip bop
|
307
|
+
// beep boop
|
308
|
+
bang: bizz
|
309
|
+
// bubble bubble
|
310
|
+
// toil trouble
|
311
|
+
SASS
|
312
|
+
foo {
|
313
|
+
bar: baz;
|
314
|
+
// bip bop
|
315
|
+
// beep boop
|
316
|
+
bang: bizz;
|
317
|
+
// bubble bubble
|
318
|
+
// toil trouble
|
319
|
+
}
|
320
|
+
SCSS
|
321
|
+
|
322
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
323
|
+
foo {
|
324
|
+
bar: baz;
|
325
|
+
// bip bop
|
326
|
+
// beep boop
|
327
|
+
// bap blimp
|
328
|
+
bang: bizz;
|
329
|
+
// bubble bubble
|
330
|
+
// toil trouble
|
331
|
+
// gorp
|
332
|
+
}
|
333
|
+
SCSS
|
334
|
+
foo
|
335
|
+
bar: baz
|
336
|
+
// bip bop
|
337
|
+
beep boop
|
338
|
+
bap blimp
|
339
|
+
bang: bizz
|
340
|
+
// bubble bubble
|
341
|
+
toil trouble
|
342
|
+
gorp
|
343
|
+
SASS
|
344
|
+
end
|
345
|
+
|
346
|
+
def test_loud_comments
|
347
|
+
assert_renders <<SASS, <<SCSS
|
348
|
+
/* foo
|
349
|
+
|
350
|
+
/* bar
|
351
|
+
|
352
|
+
/* baz
|
353
|
+
|
354
|
+
foo bar
|
355
|
+
a: b
|
356
|
+
SASS
|
357
|
+
/* foo */
|
358
|
+
|
359
|
+
/* bar */
|
360
|
+
|
361
|
+
/* baz */
|
362
|
+
|
363
|
+
foo bar {
|
364
|
+
a: b; }
|
365
|
+
SCSS
|
366
|
+
|
367
|
+
assert_scss_to_sass <<SASS, <<SCSS
|
368
|
+
/* foo
|
369
|
+
* bar
|
370
|
+
* baz
|
371
|
+
* bang
|
372
|
+
|
373
|
+
foo bar
|
374
|
+
a: b
|
375
|
+
SASS
|
376
|
+
/* foo
|
377
|
+
bar
|
378
|
+
baz
|
379
|
+
bang */
|
380
|
+
|
381
|
+
foo bar {
|
382
|
+
a: b; }
|
383
|
+
SCSS
|
384
|
+
|
385
|
+
assert_scss_to_scss <<SCSS
|
386
|
+
/* foo
|
387
|
+
bar
|
388
|
+
baz
|
389
|
+
bang */
|
390
|
+
|
391
|
+
foo bar {
|
392
|
+
a: b; }
|
393
|
+
SCSS
|
394
|
+
|
395
|
+
assert_renders <<SASS, <<SCSS
|
396
|
+
/* foo
|
397
|
+
* bar
|
398
|
+
* baz
|
399
|
+
* bang
|
400
|
+
|
401
|
+
foo bar
|
402
|
+
a: b
|
403
|
+
SASS
|
404
|
+
/* foo
|
405
|
+
* bar
|
406
|
+
* baz
|
407
|
+
* bang */
|
408
|
+
|
409
|
+
foo bar {
|
410
|
+
a: b; }
|
411
|
+
SCSS
|
412
|
+
end
|
413
|
+
|
414
|
+
def test_nested_loud_comments
|
415
|
+
assert_renders <<SASS, <<SCSS
|
416
|
+
foo
|
417
|
+
bar: baz
|
418
|
+
/* bip bop
|
419
|
+
* beep boop
|
420
|
+
bang: bizz
|
421
|
+
/* bubble bubble
|
422
|
+
* toil trouble
|
423
|
+
SASS
|
424
|
+
foo {
|
425
|
+
bar: baz;
|
426
|
+
/* bip bop
|
427
|
+
* beep boop */
|
428
|
+
bang: bizz;
|
429
|
+
/* bubble bubble
|
430
|
+
* toil trouble */ }
|
431
|
+
SCSS
|
432
|
+
|
433
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
434
|
+
foo {
|
435
|
+
bar: baz;
|
436
|
+
/* bip bop
|
437
|
+
* beep boop
|
438
|
+
* bap blimp */
|
439
|
+
bang: bizz;
|
440
|
+
/* bubble bubble
|
441
|
+
* toil trouble
|
442
|
+
* gorp */ }
|
443
|
+
SCSS
|
444
|
+
foo
|
445
|
+
bar: baz
|
446
|
+
/* bip bop
|
447
|
+
beep boop
|
448
|
+
bap blimp
|
449
|
+
bang: bizz
|
450
|
+
/* bubble bubble
|
451
|
+
toil trouble
|
452
|
+
gorp
|
453
|
+
SASS
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_loud_comments_with_weird_indentation
|
457
|
+
assert_scss_to_sass <<SASS, <<SCSS
|
458
|
+
foo
|
459
|
+
/* foo
|
460
|
+
* bar
|
461
|
+
* baz
|
462
|
+
a: b
|
463
|
+
SASS
|
464
|
+
foo {
|
465
|
+
/* foo
|
466
|
+
bar
|
467
|
+
baz */
|
468
|
+
a: b; }
|
469
|
+
SCSS
|
470
|
+
|
471
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
472
|
+
foo {
|
473
|
+
/* foo
|
474
|
+
* bar
|
475
|
+
* baz */
|
476
|
+
a: b; }
|
477
|
+
SCSS
|
478
|
+
foo
|
479
|
+
/* foo
|
480
|
+
bar
|
481
|
+
baz
|
482
|
+
a: b
|
483
|
+
SASS
|
484
|
+
end
|
485
|
+
|
486
|
+
def test_immediately_preceding_comments
|
487
|
+
assert_renders <<SASS, <<SCSS
|
488
|
+
/* Foo
|
489
|
+
* Bar
|
490
|
+
* Baz
|
491
|
+
.foo#bar
|
492
|
+
a: b
|
493
|
+
SASS
|
494
|
+
/* Foo
|
495
|
+
* Bar
|
496
|
+
* Baz */
|
497
|
+
.foo#bar {
|
498
|
+
a: b; }
|
499
|
+
SCSS
|
500
|
+
|
501
|
+
assert_renders <<SASS, <<SCSS
|
502
|
+
// Foo
|
503
|
+
// Bar
|
504
|
+
// Baz
|
505
|
+
=foo
|
506
|
+
a: b
|
507
|
+
SASS
|
508
|
+
// Foo
|
509
|
+
// Bar
|
510
|
+
// Baz
|
511
|
+
@mixin foo {
|
512
|
+
a: b; }
|
513
|
+
SCSS
|
514
|
+
end
|
515
|
+
|
516
|
+
def test_debug
|
517
|
+
assert_renders <<SASS, <<SCSS
|
518
|
+
foo
|
519
|
+
@debug 12px
|
520
|
+
bar: baz
|
521
|
+
SASS
|
522
|
+
foo {
|
523
|
+
@debug 12px;
|
524
|
+
bar: baz; }
|
525
|
+
SCSS
|
526
|
+
end
|
527
|
+
|
528
|
+
def test_directive_without_children
|
529
|
+
assert_renders <<SASS, <<SCSS
|
530
|
+
foo
|
531
|
+
@foo #bar "baz"
|
532
|
+
bar: baz
|
533
|
+
SASS
|
534
|
+
foo {
|
535
|
+
@foo #bar "baz";
|
536
|
+
bar: baz; }
|
537
|
+
SCSS
|
538
|
+
end
|
539
|
+
|
540
|
+
def test_directive_with_prop_children
|
541
|
+
assert_renders <<SASS, <<SCSS
|
542
|
+
foo
|
543
|
+
@foo #bar "baz"
|
544
|
+
a: b
|
545
|
+
c: d
|
546
|
+
|
547
|
+
bar: baz
|
548
|
+
SASS
|
549
|
+
foo {
|
550
|
+
@foo #bar "baz" {
|
551
|
+
a: b;
|
552
|
+
c: d; }
|
553
|
+
|
554
|
+
bar: baz; }
|
555
|
+
SCSS
|
556
|
+
end
|
557
|
+
|
558
|
+
def test_directive_with_rule_children
|
559
|
+
assert_renders <<SASS, <<SCSS
|
560
|
+
foo
|
561
|
+
@foo #bar "baz"
|
562
|
+
#blat
|
563
|
+
a: b
|
564
|
+
.bang
|
565
|
+
c: d
|
566
|
+
e: f
|
567
|
+
|
568
|
+
bar: baz
|
569
|
+
SASS
|
570
|
+
foo {
|
571
|
+
@foo #bar "baz" {
|
572
|
+
#blat {
|
573
|
+
a: b; }
|
574
|
+
.bang {
|
575
|
+
c: d;
|
576
|
+
e: f; } }
|
577
|
+
|
578
|
+
bar: baz; }
|
579
|
+
SCSS
|
580
|
+
end
|
581
|
+
|
582
|
+
def test_directive_with_rule_and_prop_children
|
583
|
+
assert_renders <<SASS, <<SCSS
|
584
|
+
foo
|
585
|
+
@foo #bar "baz"
|
586
|
+
g: h
|
587
|
+
#blat
|
588
|
+
a: b
|
589
|
+
.bang
|
590
|
+
c: d
|
591
|
+
e: f
|
592
|
+
i: j
|
593
|
+
|
594
|
+
bar: baz
|
595
|
+
SASS
|
596
|
+
foo {
|
597
|
+
@foo #bar "baz" {
|
598
|
+
g: h;
|
599
|
+
#blat {
|
600
|
+
a: b; }
|
601
|
+
.bang {
|
602
|
+
c: d;
|
603
|
+
e: f; }
|
604
|
+
i: j; }
|
605
|
+
|
606
|
+
bar: baz; }
|
607
|
+
SCSS
|
608
|
+
end
|
609
|
+
|
610
|
+
def test_for
|
611
|
+
assert_renders <<SASS, <<SCSS
|
612
|
+
foo
|
613
|
+
@for $a from $b to $c
|
614
|
+
a: b
|
615
|
+
@for $c from 1 to 16
|
616
|
+
d: e
|
617
|
+
f: g
|
618
|
+
SASS
|
619
|
+
foo {
|
620
|
+
@for $a from $b to $c {
|
621
|
+
a: b; }
|
622
|
+
@for $c from 1 to 16 {
|
623
|
+
d: e;
|
624
|
+
f: g; } }
|
625
|
+
SCSS
|
626
|
+
end
|
627
|
+
|
628
|
+
def test_while
|
629
|
+
assert_renders <<SASS, <<SCSS
|
630
|
+
foo
|
631
|
+
@while flaz($a + $b)
|
632
|
+
a: b
|
633
|
+
@while 1
|
634
|
+
d: e
|
635
|
+
f: g
|
636
|
+
SASS
|
637
|
+
foo {
|
638
|
+
@while flaz($a + $b) {
|
639
|
+
a: b; }
|
640
|
+
@while 1 {
|
641
|
+
d: e;
|
642
|
+
f: g; } }
|
643
|
+
SCSS
|
644
|
+
end
|
645
|
+
|
646
|
+
def test_if
|
647
|
+
assert_renders <<SASS, <<SCSS
|
648
|
+
foo
|
649
|
+
@if $foo or $bar
|
650
|
+
a: b
|
651
|
+
@if $baz
|
652
|
+
d: e
|
653
|
+
@else if $bang
|
654
|
+
f: g
|
655
|
+
@else
|
656
|
+
h: i
|
657
|
+
SASS
|
658
|
+
foo {
|
659
|
+
@if $foo or $bar {
|
660
|
+
a: b; }
|
661
|
+
@if $baz {
|
662
|
+
d: e; }
|
663
|
+
@else if $bang {
|
664
|
+
f: g; }
|
665
|
+
@else {
|
666
|
+
h: i; } }
|
667
|
+
SCSS
|
668
|
+
end
|
669
|
+
|
670
|
+
def test_import
|
671
|
+
assert_renders <<SASS, <<SCSS
|
672
|
+
@import foo
|
673
|
+
|
674
|
+
@import url(bar.css)
|
675
|
+
|
676
|
+
foo
|
677
|
+
bar: baz
|
678
|
+
SASS
|
679
|
+
@import "foo";
|
680
|
+
|
681
|
+
@import url(bar.css);
|
682
|
+
|
683
|
+
foo {
|
684
|
+
bar: baz; }
|
685
|
+
SCSS
|
686
|
+
|
687
|
+
assert_renders <<SASS, <<SCSS
|
688
|
+
@import foo.css
|
689
|
+
|
690
|
+
@import url(bar.css)
|
691
|
+
|
692
|
+
foo
|
693
|
+
bar: baz
|
694
|
+
SASS
|
695
|
+
@import "foo.css";
|
696
|
+
|
697
|
+
@import url(bar.css);
|
698
|
+
|
699
|
+
foo {
|
700
|
+
bar: baz; }
|
701
|
+
SCSS
|
702
|
+
end
|
703
|
+
|
704
|
+
def test_import_as_directive_in_sass
|
705
|
+
assert_equal "@import foo.css\n", to_sass('@import "foo.css"')
|
706
|
+
end
|
707
|
+
|
708
|
+
def test_import_as_directive_in_scss
|
709
|
+
assert_renders <<SASS, <<SCSS
|
710
|
+
@import "foo.css" print
|
711
|
+
SASS
|
712
|
+
@import "foo.css" print;
|
713
|
+
SCSS
|
714
|
+
|
715
|
+
assert_renders <<SASS, <<SCSS
|
716
|
+
@import url(foo.css) screen, print
|
717
|
+
SASS
|
718
|
+
@import url(foo.css) screen, print;
|
719
|
+
SCSS
|
720
|
+
end
|
721
|
+
|
722
|
+
def test_adjacent_imports
|
723
|
+
assert_renders <<SASS, <<SCSS
|
724
|
+
@import foo.sass
|
725
|
+
@import bar.scss
|
726
|
+
@import baz
|
727
|
+
SASS
|
728
|
+
@import "foo.sass";
|
729
|
+
@import "bar.scss";
|
730
|
+
@import "baz";
|
731
|
+
SCSS
|
732
|
+
end
|
733
|
+
|
734
|
+
def test_non_adjacent_imports
|
735
|
+
assert_renders <<SASS, <<SCSS
|
736
|
+
@import foo.sass
|
737
|
+
|
738
|
+
@import bar.scss
|
739
|
+
|
740
|
+
@import baz
|
741
|
+
SASS
|
742
|
+
@import "foo.sass";
|
743
|
+
|
744
|
+
@import "bar.scss";
|
745
|
+
|
746
|
+
@import "baz";
|
747
|
+
SCSS
|
748
|
+
end
|
749
|
+
|
750
|
+
def test_extend
|
751
|
+
assert_renders <<SASS, <<SCSS
|
752
|
+
.foo
|
753
|
+
@extend .bar
|
754
|
+
@extend .baz:bang
|
755
|
+
SASS
|
756
|
+
.foo {
|
757
|
+
@extend .bar;
|
758
|
+
@extend .baz:bang; }
|
759
|
+
SCSS
|
760
|
+
end
|
761
|
+
|
762
|
+
def test_argless_mixin_definition
|
763
|
+
assert_renders <<SASS, <<SCSS
|
764
|
+
=foo-bar
|
765
|
+
baz
|
766
|
+
a: b
|
767
|
+
SASS
|
768
|
+
@mixin foo-bar {
|
769
|
+
baz {
|
770
|
+
a: b; } }
|
771
|
+
SCSS
|
772
|
+
|
773
|
+
assert_scss_to_sass <<SASS, <<SCSS
|
774
|
+
=foo-bar
|
775
|
+
baz
|
776
|
+
a: b
|
777
|
+
SASS
|
778
|
+
@mixin foo-bar() {
|
779
|
+
baz {
|
780
|
+
a: b; } }
|
781
|
+
SCSS
|
782
|
+
|
783
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
784
|
+
@mixin foo-bar {
|
785
|
+
baz {
|
786
|
+
a: b; } }
|
787
|
+
SCSS
|
788
|
+
=foo-bar()
|
789
|
+
baz
|
790
|
+
a: b
|
791
|
+
SASS
|
792
|
+
end
|
793
|
+
|
794
|
+
def test_mixin_definition_without_defaults
|
795
|
+
assert_renders <<SASS, <<SCSS
|
796
|
+
=foo-bar($baz, $bang)
|
797
|
+
baz
|
798
|
+
a: $baz $bang
|
799
|
+
SASS
|
800
|
+
@mixin foo-bar($baz, $bang) {
|
801
|
+
baz {
|
802
|
+
a: $baz $bang; } }
|
803
|
+
SCSS
|
804
|
+
end
|
805
|
+
|
806
|
+
def test_mixin_definition_with_defaults
|
807
|
+
assert_renders <<SASS, <<SCSS
|
808
|
+
=foo-bar($baz, $bang: 12px)
|
809
|
+
baz
|
810
|
+
a: $baz $bang
|
811
|
+
SASS
|
812
|
+
@mixin foo-bar($baz, $bang: 12px) {
|
813
|
+
baz {
|
814
|
+
a: $baz $bang; } }
|
815
|
+
SCSS
|
816
|
+
|
817
|
+
assert_scss_to_sass <<SASS, <<SCSS
|
818
|
+
=foo-bar($baz, $bang: foo)
|
819
|
+
baz
|
820
|
+
a: $baz $bang
|
821
|
+
SASS
|
822
|
+
@mixin foo-bar($baz, $bang = "foo") {
|
823
|
+
baz {
|
824
|
+
a: $baz $bang; } }
|
825
|
+
SCSS
|
826
|
+
|
827
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
828
|
+
@mixin foo-bar($baz, $bang: foo) {
|
829
|
+
baz {
|
830
|
+
a: $baz $bang; } }
|
831
|
+
SCSS
|
832
|
+
=foo-bar($baz, $bang = "foo")
|
833
|
+
baz
|
834
|
+
a: $baz $bang
|
835
|
+
SASS
|
836
|
+
end
|
837
|
+
|
838
|
+
def test_argless_mixin_include
|
839
|
+
assert_renders <<SASS, <<SCSS
|
840
|
+
foo
|
841
|
+
+foo-bar
|
842
|
+
a: blip
|
843
|
+
SASS
|
844
|
+
foo {
|
845
|
+
@include foo-bar;
|
846
|
+
a: blip; }
|
847
|
+
SCSS
|
848
|
+
end
|
849
|
+
|
850
|
+
def test_mixin_include
|
851
|
+
assert_renders <<SASS, <<SCSS
|
852
|
+
foo
|
853
|
+
+foo-bar(12px, "blaz")
|
854
|
+
a: blip
|
855
|
+
SASS
|
856
|
+
foo {
|
857
|
+
@include foo-bar(12px, "blaz");
|
858
|
+
a: blip; }
|
859
|
+
SCSS
|
860
|
+
end
|
861
|
+
|
862
|
+
def test_variable_definition
|
863
|
+
assert_renders <<SASS, <<SCSS
|
864
|
+
$var1: 12px + 15px
|
865
|
+
|
866
|
+
foo
|
867
|
+
$var2: flaz(#abcdef)
|
868
|
+
val: $var1 $var2
|
869
|
+
SASS
|
870
|
+
$var1: 12px + 15px;
|
871
|
+
|
872
|
+
foo {
|
873
|
+
$var2: flaz(#abcdef);
|
874
|
+
val: $var1 $var2; }
|
875
|
+
SCSS
|
876
|
+
|
877
|
+
assert_sass_to_scss '$var: 12px $bar baz;', '$var = 12px $bar "baz"'
|
878
|
+
end
|
879
|
+
|
880
|
+
def test_guarded_variable_definition
|
881
|
+
assert_renders <<SASS, <<SCSS
|
882
|
+
$var1: 12px + 15px !default
|
883
|
+
|
884
|
+
foo
|
885
|
+
$var2: flaz(#abcdef) !default
|
886
|
+
val: $var1 $var2
|
887
|
+
SASS
|
888
|
+
$var1: 12px + 15px !default;
|
889
|
+
|
890
|
+
foo {
|
891
|
+
$var2: flaz(#abcdef) !default;
|
892
|
+
val: $var1 $var2; }
|
893
|
+
SCSS
|
894
|
+
|
895
|
+
assert_sass_to_scss '$var: 12px $bar baz !default;', '$var ||= 12px $bar "baz"'
|
896
|
+
end
|
897
|
+
|
898
|
+
def test_multiple_variable_definitions
|
899
|
+
assert_renders <<SASS, <<SCSS
|
900
|
+
$var1: foo
|
901
|
+
$var2: bar
|
902
|
+
$var3: baz
|
903
|
+
|
904
|
+
$var4: bip
|
905
|
+
$var5: bap
|
906
|
+
SASS
|
907
|
+
$var1: foo;
|
908
|
+
$var2: bar;
|
909
|
+
$var3: baz;
|
910
|
+
|
911
|
+
$var4: bip;
|
912
|
+
$var5: bap;
|
913
|
+
SCSS
|
914
|
+
end
|
915
|
+
|
916
|
+
def test_division_asserted_with_parens
|
917
|
+
assert_renders <<SASS, <<SCSS
|
918
|
+
foo
|
919
|
+
a: (1px / 2px)
|
920
|
+
SASS
|
921
|
+
foo {
|
922
|
+
a: (1px / 2px); }
|
923
|
+
SCSS
|
924
|
+
end
|
925
|
+
|
926
|
+
def test_division_not_asserted_when_unnecessary
|
927
|
+
assert_renders <<SASS, <<SCSS
|
928
|
+
$var: 1px / 2px
|
929
|
+
|
930
|
+
foo
|
931
|
+
a: $var
|
932
|
+
SASS
|
933
|
+
$var: 1px / 2px;
|
934
|
+
|
935
|
+
foo {
|
936
|
+
a: $var; }
|
937
|
+
SCSS
|
938
|
+
|
939
|
+
assert_renders <<SASS, <<SCSS
|
940
|
+
$var: 1px
|
941
|
+
|
942
|
+
foo
|
943
|
+
a: $var / 2px
|
944
|
+
SASS
|
945
|
+
$var: 1px;
|
946
|
+
|
947
|
+
foo {
|
948
|
+
a: $var / 2px; }
|
949
|
+
SCSS
|
950
|
+
|
951
|
+
assert_renders <<SASS, <<SCSS
|
952
|
+
foo
|
953
|
+
a: 1 + 1px / 2px
|
954
|
+
SASS
|
955
|
+
foo {
|
956
|
+
a: 1 + 1px / 2px; }
|
957
|
+
SCSS
|
958
|
+
end
|
959
|
+
|
960
|
+
def test_literal_slash
|
961
|
+
assert_renders <<SASS, <<SCSS
|
962
|
+
foo
|
963
|
+
a: 1px / 2px
|
964
|
+
SASS
|
965
|
+
foo {
|
966
|
+
a: 1px / 2px; }
|
967
|
+
SCSS
|
968
|
+
end
|
969
|
+
|
970
|
+
# Hacks
|
971
|
+
|
972
|
+
def test_declaration_hacks
|
973
|
+
assert_renders <<SASS, <<SCSS
|
974
|
+
foo
|
975
|
+
_name: val
|
976
|
+
*name: val
|
977
|
+
#name: val
|
978
|
+
.name: val
|
979
|
+
name/**/: val
|
980
|
+
name/*\\**/: val
|
981
|
+
name: val
|
982
|
+
SASS
|
983
|
+
foo {
|
984
|
+
_name: val;
|
985
|
+
*name: val;
|
986
|
+
#name: val;
|
987
|
+
.name: val;
|
988
|
+
name/**/: val;
|
989
|
+
name/*\\**/: val;
|
990
|
+
name: val; }
|
991
|
+
SCSS
|
992
|
+
end
|
993
|
+
|
994
|
+
def test_old_declaration_hacks
|
995
|
+
assert_renders <<SASS, <<SCSS, :old => true
|
996
|
+
foo
|
997
|
+
:_name val
|
998
|
+
:*name val
|
999
|
+
:#name val
|
1000
|
+
:.name val
|
1001
|
+
:name val
|
1002
|
+
SASS
|
1003
|
+
foo {
|
1004
|
+
_name: val;
|
1005
|
+
*name: val;
|
1006
|
+
#name: val;
|
1007
|
+
.name: val;
|
1008
|
+
name: val; }
|
1009
|
+
SCSS
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
def test_selector_hacks
|
1013
|
+
assert_selector_renders = lambda do |s|
|
1014
|
+
assert_renders <<SASS, <<SCSS
|
1015
|
+
#{s}
|
1016
|
+
a: b
|
1017
|
+
SASS
|
1018
|
+
#{s} {
|
1019
|
+
a: b; }
|
1020
|
+
SCSS
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
assert_selector_renders['> E']
|
1024
|
+
assert_selector_renders['+ E']
|
1025
|
+
assert_selector_renders['~ E']
|
1026
|
+
assert_selector_renders['> > E']
|
1027
|
+
|
1028
|
+
assert_selector_renders['E*']
|
1029
|
+
assert_selector_renders['E*.foo']
|
1030
|
+
assert_selector_renders['E*:hover']
|
1031
|
+
end
|
1032
|
+
|
1033
|
+
def test_disallowed_colon_hack
|
1034
|
+
assert_raise_message(Sass::SyntaxError, 'The ":name: val" hack is not allowed in the Sass indented syntax') do
|
1035
|
+
to_sass("foo {:name: val;}", :syntax => :scss)
|
1036
|
+
end
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
# Sass 3 Deprecation conversions
|
1040
|
+
|
1041
|
+
def test_simple_quoted_strings_unquoted_with_equals
|
1042
|
+
assert_sass_to_scss '$var: 1px foo + bar baz;', '!var = 1px "foo" + "bar" baz'
|
1043
|
+
assert_sass_to_scss '$var: -foo-bar;', '!var = "-foo-bar"'
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
def test_complex_quoted_strings_explicitly_unquoted_with_equals
|
1047
|
+
assert_sass_to_scss '$var: 1px unquote("foo + bar") baz;', '!var = 1px "foo + bar" baz'
|
1048
|
+
assert_sass_to_scss "$var: unquote('foo\"bar');", '!var = "foo\"bar"'
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
def test_division_asserted_with_equals
|
1052
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
1053
|
+
foo {
|
1054
|
+
a: (1px / 2px); }
|
1055
|
+
SCSS
|
1056
|
+
foo
|
1057
|
+
a = 1px / 2px
|
1058
|
+
SASS
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
def test_division_not_asserted_with_equals_when_unnecessary
|
1062
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
1063
|
+
$var: 1px / 2px;
|
1064
|
+
|
1065
|
+
foo {
|
1066
|
+
a: $var; }
|
1067
|
+
SCSS
|
1068
|
+
!var = 1px / 2px
|
1069
|
+
|
1070
|
+
foo
|
1071
|
+
a = !var
|
1072
|
+
SASS
|
1073
|
+
|
1074
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
1075
|
+
$var: 1px;
|
1076
|
+
|
1077
|
+
foo {
|
1078
|
+
a: $var / 2px; }
|
1079
|
+
SCSS
|
1080
|
+
!var = 1px
|
1081
|
+
|
1082
|
+
foo
|
1083
|
+
a = !var / 2px
|
1084
|
+
SASS
|
1085
|
+
|
1086
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
1087
|
+
foo {
|
1088
|
+
a: 1 + 1px / 2px; }
|
1089
|
+
SCSS
|
1090
|
+
foo
|
1091
|
+
a = 1 + 1px / 2px
|
1092
|
+
SASS
|
1093
|
+
end
|
1094
|
+
|
1095
|
+
def test_nested_properties
|
1096
|
+
assert_renders <<SASS, <<SCSS
|
1097
|
+
div
|
1098
|
+
before: before
|
1099
|
+
background:
|
1100
|
+
color: blue
|
1101
|
+
repeat: no-repeat
|
1102
|
+
after: after
|
1103
|
+
SASS
|
1104
|
+
div {
|
1105
|
+
before: before;
|
1106
|
+
background: {
|
1107
|
+
color: blue;
|
1108
|
+
repeat: no-repeat; };
|
1109
|
+
after: after; }
|
1110
|
+
|
1111
|
+
SCSS
|
1112
|
+
end
|
1113
|
+
|
1114
|
+
def test_dasherize
|
1115
|
+
assert_sass_to_scss(<<SCSS, <<SASS, :dasherize => true)
|
1116
|
+
@mixin under-scored-mixin($under-scored-arg: $under-scored-default) {
|
1117
|
+
bar: $under-scored-arg; }
|
1118
|
+
|
1119
|
+
div {
|
1120
|
+
foo: under-scored-fn($under-scored-var + "before\#{$another-under-scored-var}after");
|
1121
|
+
@include under-scored-mixin($passed-arg);
|
1122
|
+
selector-\#{$under-scored-interp}: bold; }
|
1123
|
+
|
1124
|
+
@if $under-scored {
|
1125
|
+
@for $for-var from $from-var to $to-var {
|
1126
|
+
@while $while-var == true {
|
1127
|
+
$while-var: false; } } }
|
1128
|
+
SCSS
|
1129
|
+
=under_scored_mixin($under_scored_arg: $under_scored_default)
|
1130
|
+
bar: $under_scored_arg
|
1131
|
+
div
|
1132
|
+
foo: under_scored_fn($under_scored_var + "before\#{$another_under_scored_var}after")
|
1133
|
+
+under_scored_mixin($passed_arg)
|
1134
|
+
selector-\#{$under_scored_interp}: bold
|
1135
|
+
@if $under_scored
|
1136
|
+
@for $for_var from $from_var to $to_var
|
1137
|
+
@while $while_var == true
|
1138
|
+
$while_var : false
|
1139
|
+
SASS
|
1140
|
+
end
|
1141
|
+
|
1142
|
+
def test_sass2_var_in_property_interpolation
|
1143
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
1144
|
+
foo {
|
1145
|
+
a: b \#{$c} d; }
|
1146
|
+
SCSS
|
1147
|
+
foo
|
1148
|
+
a: b \#{!c} d
|
1149
|
+
SASS
|
1150
|
+
end
|
1151
|
+
|
1152
|
+
def test_sass2_var_in_selector_interpolation
|
1153
|
+
assert_sass_to_scss <<SCSS, <<SASS
|
1154
|
+
foo-\#{$c} {
|
1155
|
+
a: b; }
|
1156
|
+
SCSS
|
1157
|
+
foo-\#{!c}
|
1158
|
+
a: b
|
1159
|
+
SASS
|
1160
|
+
end
|
1161
|
+
|
1162
|
+
private
|
1163
|
+
|
1164
|
+
def assert_sass_to_sass(sass, options = {})
|
1165
|
+
assert_equal(sass.rstrip, to_sass(sass, options).rstrip,
|
1166
|
+
"Expected Sass to transform to itself")
|
1167
|
+
end
|
1168
|
+
|
1169
|
+
def assert_scss_to_sass(sass, scss, options = {})
|
1170
|
+
assert_equal(sass.rstrip, to_sass(scss, options.merge(:syntax => :scss)).rstrip,
|
1171
|
+
"Expected SCSS to transform to Sass")
|
1172
|
+
end
|
1173
|
+
|
1174
|
+
def assert_scss_to_scss(scss, in_scss = nil, options = nil)
|
1175
|
+
if in_scss.is_a?(Hash)
|
1176
|
+
options = in_scss
|
1177
|
+
in_scss = nil
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
in_scss ||= scss
|
1181
|
+
options ||= {}
|
1182
|
+
|
1183
|
+
assert_equal(scss.rstrip, to_scss(in_scss, options.merge(:syntax => :scss)).rstrip,
|
1184
|
+
"Expected SCSS to transform to #{scss == in_scss ? 'itself' : 'SCSS'}k")
|
1185
|
+
end
|
1186
|
+
|
1187
|
+
def assert_sass_to_scss(scss, sass, options = {})
|
1188
|
+
assert_equal(scss.rstrip, to_scss(sass, options).rstrip,
|
1189
|
+
"Expected Sass to transform to SCSS")
|
1190
|
+
end
|
1191
|
+
|
1192
|
+
def assert_renders(sass, scss, options = {})
|
1193
|
+
assert_sass_to_sass(sass, options)
|
1194
|
+
assert_scss_to_sass(sass, scss, options)
|
1195
|
+
assert_scss_to_scss(scss, options)
|
1196
|
+
assert_sass_to_scss(scss, sass, options)
|
1197
|
+
end
|
1198
|
+
|
1199
|
+
def to_sass(scss, options = {})
|
1200
|
+
Sass::Util.silence_sass_warnings do
|
1201
|
+
Sass::Engine.new(scss, options).to_tree.to_sass(options)
|
1202
|
+
end
|
1203
|
+
end
|
1204
|
+
|
1205
|
+
def to_scss(sass, options = {})
|
1206
|
+
Sass::Util.silence_sass_warnings do
|
1207
|
+
Sass::Engine.new(sass, options).to_tree.to_scss(options)
|
1208
|
+
end
|
1209
|
+
end
|
1210
|
+
end
|