haml 3.0.25 → 3.1.0.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of haml might be problematic. Click here for more details.
- data/.yardopts +1 -1
- data/CONTRIBUTING +0 -1
- data/EDGE_GEM_VERSION +1 -0
- data/MIT-LICENSE +1 -1
- data/README.md +10 -175
- data/Rakefile +56 -84
- data/VERSION +1 -1
- data/VERSION_NAME +1 -1
- data/init.rb +1 -1
- data/lib/haml.rb +14 -12
- data/lib/haml/engine.rb +1 -1
- data/lib/haml/exec.rb +19 -316
- data/lib/haml/helpers/action_view_extensions.rb +1 -1
- data/lib/haml/html.rb +69 -76
- data/lib/haml/precompiler.rb +34 -41
- data/lib/haml/railtie.rb +4 -6
- data/lib/haml/template/plugin.rb +6 -16
- data/lib/haml/util.rb +91 -107
- data/lib/haml/version.rb +7 -0
- data/test/benchmark.rb +2 -9
- data/test/haml/engine_test.rb +195 -92
- data/test/haml/html2haml/erb_tests.rb +0 -14
- data/test/haml/util_test.rb +32 -0
- data/test/test_helper.rb +0 -39
- metadata +96 -324
- data/bin/css2sass +0 -13
- data/bin/sass +0 -8
- data/bin/sass-convert +0 -7
- data/extra/haml-mode.el +0 -753
- data/extra/sass-mode.el +0 -207
- data/lib/haml/util/subset_map.rb +0 -101
- data/lib/sass.rb +0 -29
- data/lib/sass/callbacks.rb +0 -52
- data/lib/sass/css.rb +0 -294
- data/lib/sass/engine.rb +0 -720
- data/lib/sass/environment.rb +0 -143
- data/lib/sass/error.rb +0 -198
- data/lib/sass/files.rb +0 -160
- data/lib/sass/less.rb +0 -382
- data/lib/sass/plugin.rb +0 -279
- data/lib/sass/plugin/configuration.rb +0 -221
- data/lib/sass/plugin/generic.rb +0 -15
- data/lib/sass/plugin/merb.rb +0 -37
- data/lib/sass/plugin/rack.rb +0 -47
- data/lib/sass/plugin/rails.rb +0 -32
- data/lib/sass/plugin/staleness_checker.rb +0 -123
- data/lib/sass/repl.rb +0 -58
- data/lib/sass/script.rb +0 -63
- data/lib/sass/script/bool.rb +0 -18
- data/lib/sass/script/color.rb +0 -491
- data/lib/sass/script/css_lexer.rb +0 -29
- data/lib/sass/script/css_parser.rb +0 -31
- data/lib/sass/script/funcall.rb +0 -77
- data/lib/sass/script/functions.rb +0 -861
- data/lib/sass/script/interpolation.rb +0 -70
- data/lib/sass/script/lexer.rb +0 -337
- data/lib/sass/script/literal.rb +0 -236
- data/lib/sass/script/node.rb +0 -112
- data/lib/sass/script/number.rb +0 -423
- data/lib/sass/script/operation.rb +0 -95
- data/lib/sass/script/parser.rb +0 -401
- data/lib/sass/script/string.rb +0 -67
- data/lib/sass/script/string_interpolation.rb +0 -93
- data/lib/sass/script/unary_operation.rb +0 -57
- data/lib/sass/script/variable.rb +0 -48
- data/lib/sass/scss.rb +0 -17
- data/lib/sass/scss/css_parser.rb +0 -46
- data/lib/sass/scss/parser.rb +0 -855
- data/lib/sass/scss/rx.rb +0 -126
- data/lib/sass/scss/sass_parser.rb +0 -11
- data/lib/sass/scss/script_lexer.rb +0 -15
- data/lib/sass/scss/script_parser.rb +0 -25
- data/lib/sass/scss/static_parser.rb +0 -40
- data/lib/sass/selector.rb +0 -361
- data/lib/sass/selector/abstract_sequence.rb +0 -62
- data/lib/sass/selector/comma_sequence.rb +0 -82
- data/lib/sass/selector/sequence.rb +0 -237
- data/lib/sass/selector/simple.rb +0 -113
- data/lib/sass/selector/simple_sequence.rb +0 -136
- data/lib/sass/tree/charset_node.rb +0 -37
- data/lib/sass/tree/comment_node.rb +0 -128
- data/lib/sass/tree/debug_node.rb +0 -36
- data/lib/sass/tree/directive_node.rb +0 -75
- data/lib/sass/tree/extend_node.rb +0 -65
- data/lib/sass/tree/for_node.rb +0 -55
- data/lib/sass/tree/if_node.rb +0 -69
- data/lib/sass/tree/import_node.rb +0 -102
- data/lib/sass/tree/mixin_def_node.rb +0 -48
- data/lib/sass/tree/mixin_node.rb +0 -111
- data/lib/sass/tree/node.rb +0 -464
- data/lib/sass/tree/prop_node.rb +0 -220
- data/lib/sass/tree/root_node.rb +0 -163
- data/lib/sass/tree/rule_node.rb +0 -261
- data/lib/sass/tree/variable_node.rb +0 -39
- data/lib/sass/tree/warn_node.rb +0 -42
- data/lib/sass/tree/while_node.rb +0 -36
- data/test/haml/util/subset_map_test.rb +0 -91
- data/test/sass/callbacks_test.rb +0 -61
- data/test/sass/conversion_test.rb +0 -1218
- data/test/sass/css2sass_test.rb +0 -364
- data/test/sass/data/hsl-rgb.txt +0 -319
- data/test/sass/engine_test.rb +0 -2267
- data/test/sass/extend_test.rb +0 -1348
- data/test/sass/functions_test.rb +0 -556
- data/test/sass/less_conversion_test.rb +0 -653
- data/test/sass/more_results/more1.css +0 -9
- data/test/sass/more_results/more1_with_line_comments.css +0 -26
- data/test/sass/more_results/more_import.css +0 -29
- data/test/sass/more_templates/_more_partial.sass +0 -2
- data/test/sass/more_templates/more1.sass +0 -23
- data/test/sass/more_templates/more_import.sass +0 -11
- data/test/sass/plugin_test.rb +0 -433
- data/test/sass/results/alt.css +0 -4
- data/test/sass/results/basic.css +0 -9
- data/test/sass/results/compact.css +0 -5
- data/test/sass/results/complex.css +0 -86
- data/test/sass/results/compressed.css +0 -1
- data/test/sass/results/expanded.css +0 -19
- data/test/sass/results/import.css +0 -31
- data/test/sass/results/import_charset.css +0 -4
- data/test/sass/results/import_charset_1_8.css +0 -4
- data/test/sass/results/import_charset_ibm866.css +0 -4
- data/test/sass/results/line_numbers.css +0 -49
- data/test/sass/results/mixins.css +0 -95
- data/test/sass/results/multiline.css +0 -24
- data/test/sass/results/nested.css +0 -22
- data/test/sass/results/options.css +0 -1
- data/test/sass/results/parent_ref.css +0 -13
- data/test/sass/results/script.css +0 -16
- data/test/sass/results/scss_import.css +0 -31
- data/test/sass/results/scss_importee.css +0 -2
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
- data/test/sass/results/subdir/subdir.css +0 -3
- data/test/sass/results/units.css +0 -11
- data/test/sass/results/warn.css +0 -0
- data/test/sass/results/warn_imported.css +0 -0
- data/test/sass/script_conversion_test.rb +0 -314
- data/test/sass/script_test.rb +0 -470
- data/test/sass/scss/css_test.rb +0 -916
- data/test/sass/scss/rx_test.rb +0 -156
- data/test/sass/scss/scss_test.rb +0 -1122
- data/test/sass/scss/test_helper.rb +0 -37
- data/test/sass/templates/_imported_charset_ibm866.sass +0 -4
- data/test/sass/templates/_imported_charset_utf8.sass +0 -4
- data/test/sass/templates/_partial.sass +0 -2
- data/test/sass/templates/alt.sass +0 -16
- data/test/sass/templates/basic.sass +0 -23
- data/test/sass/templates/bork1.sass +0 -2
- data/test/sass/templates/bork2.sass +0 -2
- data/test/sass/templates/bork3.sass +0 -2
- data/test/sass/templates/bork4.sass +0 -2
- data/test/sass/templates/compact.sass +0 -17
- data/test/sass/templates/complex.sass +0 -305
- data/test/sass/templates/compressed.sass +0 -15
- data/test/sass/templates/expanded.sass +0 -17
- data/test/sass/templates/import.sass +0 -12
- data/test/sass/templates/import_charset.sass +0 -7
- data/test/sass/templates/import_charset_1_8.sass +0 -4
- data/test/sass/templates/import_charset_ibm866.sass +0 -9
- data/test/sass/templates/importee.less +0 -2
- data/test/sass/templates/importee.sass +0 -19
- data/test/sass/templates/line_numbers.sass +0 -13
- data/test/sass/templates/mixin_bork.sass +0 -5
- data/test/sass/templates/mixins.sass +0 -76
- data/test/sass/templates/multiline.sass +0 -20
- data/test/sass/templates/nested.sass +0 -25
- data/test/sass/templates/nested_bork1.sass +0 -2
- data/test/sass/templates/nested_bork2.sass +0 -2
- data/test/sass/templates/nested_bork3.sass +0 -2
- data/test/sass/templates/nested_bork4.sass +0 -2
- data/test/sass/templates/nested_mixin_bork.sass +0 -6
- data/test/sass/templates/options.sass +0 -2
- data/test/sass/templates/parent_ref.sass +0 -25
- data/test/sass/templates/script.sass +0 -101
- data/test/sass/templates/scss_import.scss +0 -11
- data/test/sass/templates/scss_importee.scss +0 -1
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
- data/test/sass/templates/subdir/subdir.sass +0 -6
- data/test/sass/templates/units.sass +0 -11
- data/test/sass/templates/warn.sass +0 -3
- data/test/sass/templates/warn_imported.sass +0 -4
- data/vendor/fssm/LICENSE +0 -20
- data/vendor/fssm/README.markdown +0 -55
- data/vendor/fssm/Rakefile +0 -59
- data/vendor/fssm/VERSION.yml +0 -5
- data/vendor/fssm/example.rb +0 -9
- data/vendor/fssm/fssm.gemspec +0 -77
- data/vendor/fssm/lib/fssm.rb +0 -33
- data/vendor/fssm/lib/fssm/backends/fsevents.rb +0 -36
- data/vendor/fssm/lib/fssm/backends/inotify.rb +0 -26
- data/vendor/fssm/lib/fssm/backends/polling.rb +0 -25
- data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +0 -131
- data/vendor/fssm/lib/fssm/monitor.rb +0 -26
- data/vendor/fssm/lib/fssm/path.rb +0 -91
- data/vendor/fssm/lib/fssm/pathname.rb +0 -502
- data/vendor/fssm/lib/fssm/state/directory.rb +0 -57
- data/vendor/fssm/lib/fssm/state/file.rb +0 -24
- data/vendor/fssm/lib/fssm/support.rb +0 -63
- data/vendor/fssm/lib/fssm/tree.rb +0 -176
- data/vendor/fssm/profile/prof-cache.rb +0 -40
- data/vendor/fssm/profile/prof-fssm-pathname.html +0 -1231
- data/vendor/fssm/profile/prof-pathname.rb +0 -68
- data/vendor/fssm/profile/prof-plain-pathname.html +0 -988
- data/vendor/fssm/profile/prof.html +0 -2379
- data/vendor/fssm/spec/path_spec.rb +0 -75
- 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 +0 -14
data/lib/sass/environment.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
module Sass
|
4
|
-
# The lexical environment for SassScript.
|
5
|
-
# This keeps track of variable and mixin definitions.
|
6
|
-
#
|
7
|
-
# A new environment is created for each level of Sass nesting.
|
8
|
-
# This allows variables to be lexically scoped.
|
9
|
-
# The new environment refers to the environment in the upper scope,
|
10
|
-
# so it has access to variables defined in enclosing scopes,
|
11
|
-
# but new variables are defined locally.
|
12
|
-
#
|
13
|
-
# Environment also keeps track of the {Engine} options
|
14
|
-
# so that they can be made available to {Sass::Script::Functions}.
|
15
|
-
class Environment
|
16
|
-
# The enclosing environment,
|
17
|
-
# or nil if this is the global environment.
|
18
|
-
#
|
19
|
-
# @return [Environment]
|
20
|
-
attr_reader :parent
|
21
|
-
attr_writer :options
|
22
|
-
|
23
|
-
# @param parent [Environment] See \{#parent}
|
24
|
-
def initialize(parent = nil)
|
25
|
-
@vars = {}
|
26
|
-
@mixins = {}
|
27
|
-
@parent = parent
|
28
|
-
@stack = [] unless parent
|
29
|
-
@mixins_in_use = Set.new unless parent
|
30
|
-
set_var("important", Script::String.new("!important")) unless @parent
|
31
|
-
end
|
32
|
-
|
33
|
-
# The options hash.
|
34
|
-
# See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
|
35
|
-
#
|
36
|
-
# @return [{Symbol => Object}]
|
37
|
-
def options
|
38
|
-
@options || (parent && parent.options) || {}
|
39
|
-
end
|
40
|
-
|
41
|
-
# Push a new stack frame onto the mixin/include stack.
|
42
|
-
#
|
43
|
-
# @param frame_info [{Symbol => Object}]
|
44
|
-
# Frame information has the following keys:
|
45
|
-
#
|
46
|
-
# `:filename`
|
47
|
-
# : The name of the file in which the lexical scope changed.
|
48
|
-
#
|
49
|
-
# `:mixin`
|
50
|
-
# : The name of the mixin in which the lexical scope changed,
|
51
|
-
# or `nil` if it wasn't within in a mixin.
|
52
|
-
#
|
53
|
-
# `:line`
|
54
|
-
# : The line of the file on which the lexical scope changed. Never nil.
|
55
|
-
def push_frame(frame_info)
|
56
|
-
if stack.last && stack.last[:prepared]
|
57
|
-
stack.last.delete(:prepared)
|
58
|
-
stack.last.merge!(frame_info)
|
59
|
-
else
|
60
|
-
stack.push(frame_info)
|
61
|
-
end
|
62
|
-
mixins_in_use << stack.last[:mixin] if stack.last[:mixin] && !stack.last[:prepared]
|
63
|
-
end
|
64
|
-
|
65
|
-
# Like \{#push\_frame}, but next time a stack frame is pushed,
|
66
|
-
# it will be merged with this frame.
|
67
|
-
#
|
68
|
-
# @param frame_info [{Symbol => Object}] Same as for \{#push\_frame}.
|
69
|
-
def prepare_frame(frame_info)
|
70
|
-
push_frame(frame_info.merge(:prepared => true))
|
71
|
-
end
|
72
|
-
|
73
|
-
# Pop a stack frame from the mixin/include stack.
|
74
|
-
def pop_frame
|
75
|
-
stack.pop if stack.last && stack.last[:prepared]
|
76
|
-
popped = stack.pop
|
77
|
-
mixins_in_use.delete(popped[:mixin]) if popped && popped[:mixin]
|
78
|
-
end
|
79
|
-
|
80
|
-
# A list of stack frames in the mixin/include stack.
|
81
|
-
# The last element in the list is the most deeply-nested frame.
|
82
|
-
#
|
83
|
-
# @return [Array<{Symbol => Object}>] The stack frames,
|
84
|
-
# of the form passed to \{#push\_frame}.
|
85
|
-
def stack
|
86
|
-
@stack ||= @parent.stack
|
87
|
-
end
|
88
|
-
|
89
|
-
# A set of names of mixins currently present in the stack.
|
90
|
-
#
|
91
|
-
# @return [Set<String>] The mixin names.
|
92
|
-
def mixins_in_use
|
93
|
-
@mixins_in_use ||= @parent.mixins_in_use
|
94
|
-
end
|
95
|
-
|
96
|
-
class << self
|
97
|
-
private
|
98
|
-
|
99
|
-
# Note: when updating this,
|
100
|
-
# update haml/yard/inherited_hash.rb as well.
|
101
|
-
def inherited_hash(name)
|
102
|
-
class_eval <<RUBY, __FILE__, __LINE__ + 1
|
103
|
-
def #{name}(name)
|
104
|
-
_#{name}(name.gsub('_', '-'))
|
105
|
-
end
|
106
|
-
|
107
|
-
def _#{name}(name)
|
108
|
-
@#{name}s[name] || @parent && @parent._#{name}(name)
|
109
|
-
end
|
110
|
-
protected :_#{name}
|
111
|
-
|
112
|
-
def set_#{name}(name, value)
|
113
|
-
name = name.gsub('_', '-')
|
114
|
-
@#{name}s[name] = value unless try_set_#{name}(name, value)
|
115
|
-
end
|
116
|
-
|
117
|
-
def try_set_#{name}(name, value)
|
118
|
-
if @#{name}s.include?(name)
|
119
|
-
@#{name}s[name] = value
|
120
|
-
true
|
121
|
-
elsif @parent
|
122
|
-
@parent.try_set_#{name}(name, value)
|
123
|
-
else
|
124
|
-
false
|
125
|
-
end
|
126
|
-
end
|
127
|
-
protected :try_set_#{name}
|
128
|
-
|
129
|
-
def set_local_#{name}(name, value)
|
130
|
-
@#{name}s[name.gsub('_', '-')] = value
|
131
|
-
end
|
132
|
-
RUBY
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
# variable
|
137
|
-
# Script::Literal
|
138
|
-
inherited_hash :var
|
139
|
-
# mixin
|
140
|
-
# Engine::Mixin
|
141
|
-
inherited_hash :mixin
|
142
|
-
end
|
143
|
-
end
|
data/lib/sass/error.rb
DELETED
@@ -1,198 +0,0 @@
|
|
1
|
-
module Sass
|
2
|
-
# An exception class that keeps track of
|
3
|
-
# the line of the Sass template it was raised on
|
4
|
-
# and the Sass file that was being parsed (if applicable).
|
5
|
-
#
|
6
|
-
# All Sass errors are raised as {Sass::SyntaxError}s.
|
7
|
-
#
|
8
|
-
# When dealing with SyntaxErrors,
|
9
|
-
# it's important to provide filename and line number information.
|
10
|
-
# This will be used in various error reports to users, including backtraces;
|
11
|
-
# see \{#sass\_backtrace} for details.
|
12
|
-
#
|
13
|
-
# Some of this information is usually provided as part of the constructor.
|
14
|
-
# New backtrace entries can be added with \{#add\_backtrace},
|
15
|
-
# which is called when an exception is raised between files (e.g. with `@import`).
|
16
|
-
#
|
17
|
-
# Often, a chunk of code will all have similar backtrace information -
|
18
|
-
# the same filename or even line.
|
19
|
-
# It may also be useful to have a default line number set.
|
20
|
-
# In those situations, the default values can be used
|
21
|
-
# by omitting the information on the original exception,
|
22
|
-
# and then calling \{#modify\_backtrace} in a wrapper `rescue`.
|
23
|
-
# When doing this, be sure that all exceptions ultimately end up
|
24
|
-
# with the information filled in.
|
25
|
-
class SyntaxError < StandardError
|
26
|
-
# The backtrace of the error within Sass files.
|
27
|
-
# This is an array of hashes containing information for a single entry.
|
28
|
-
# The hashes have the following keys:
|
29
|
-
#
|
30
|
-
# `:filename`
|
31
|
-
# : The name of the file in which the exception was raised,
|
32
|
-
# or `nil` if no filename is available.
|
33
|
-
#
|
34
|
-
# `:mixin`
|
35
|
-
# : The name of the mixin in which the exception was raised,
|
36
|
-
# or `nil` if it wasn't raised in a mixin.
|
37
|
-
#
|
38
|
-
# `:line`
|
39
|
-
# : The line of the file on which the error occurred. Never nil.
|
40
|
-
#
|
41
|
-
# This information is also included in standard backtrace format
|
42
|
-
# in the output of \{#backtrace}.
|
43
|
-
#
|
44
|
-
# @return [Aray<{Symbol => Object>}]
|
45
|
-
attr_accessor :sass_backtrace
|
46
|
-
|
47
|
-
# The text of the template where this error was raised.
|
48
|
-
#
|
49
|
-
# @return [String]
|
50
|
-
attr_accessor :sass_template
|
51
|
-
|
52
|
-
# @param msg [String] The error message
|
53
|
-
# @param attrs [{Symbol => Object}] The information in the backtrace entry.
|
54
|
-
# See \{#sass\_backtrace}
|
55
|
-
def initialize(msg, attrs = {})
|
56
|
-
@message = msg
|
57
|
-
@sass_backtrace = []
|
58
|
-
add_backtrace(attrs)
|
59
|
-
end
|
60
|
-
|
61
|
-
# The name of the file in which the exception was raised.
|
62
|
-
# This could be `nil` if no filename is available.
|
63
|
-
#
|
64
|
-
# @return [String, nil]
|
65
|
-
def sass_filename
|
66
|
-
sass_backtrace.first[:filename]
|
67
|
-
end
|
68
|
-
|
69
|
-
# The name of the mixin in which the error occurred.
|
70
|
-
# This could be `nil` if the error occurred outside a mixin.
|
71
|
-
#
|
72
|
-
# @return [Fixnum]
|
73
|
-
def sass_mixin
|
74
|
-
sass_backtrace.first[:mixin]
|
75
|
-
end
|
76
|
-
|
77
|
-
# The line of the Sass template on which the error occurred.
|
78
|
-
#
|
79
|
-
# @return [Fixnum]
|
80
|
-
def sass_line
|
81
|
-
sass_backtrace.first[:line]
|
82
|
-
end
|
83
|
-
|
84
|
-
# Adds an entry to the exception's Sass backtrace.
|
85
|
-
#
|
86
|
-
# @param attrs [{Symbol => Object}] The information in the backtrace entry.
|
87
|
-
# See \{#sass\_backtrace}
|
88
|
-
def add_backtrace(attrs)
|
89
|
-
sass_backtrace << attrs.reject {|k, v| v.nil?}
|
90
|
-
end
|
91
|
-
|
92
|
-
# Modify the top Sass backtrace entries
|
93
|
-
# (that is, the most deeply nested ones)
|
94
|
-
# to have the given attributes.
|
95
|
-
#
|
96
|
-
# Specifically, this goes through the backtrace entries
|
97
|
-
# from most deeply nested to least,
|
98
|
-
# setting the given attributes for each entry.
|
99
|
-
# If an entry already has one of the given attributes set,
|
100
|
-
# the pre-existing attribute takes precedence
|
101
|
-
# and is not used for less deeply-nested entries
|
102
|
-
# (even if they don't have that attribute set).
|
103
|
-
#
|
104
|
-
# @param attrs [{Symbol => Object}] The information to add to the backtrace entry.
|
105
|
-
# See \{#sass\_backtrace}
|
106
|
-
def modify_backtrace(attrs)
|
107
|
-
attrs = attrs.reject {|k, v| v.nil?}
|
108
|
-
# Move backwards through the backtrace
|
109
|
-
(0...sass_backtrace.size).to_a.reverse.each do |i|
|
110
|
-
entry = sass_backtrace[i]
|
111
|
-
sass_backtrace[i] = attrs.merge(entry)
|
112
|
-
attrs.reject! {|k, v| entry.include?(k)}
|
113
|
-
break if attrs.empty?
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
# @return [String] The error message
|
118
|
-
def to_s
|
119
|
-
@message
|
120
|
-
end
|
121
|
-
|
122
|
-
# Returns the standard exception backtrace,
|
123
|
-
# including the Sass backtrace.
|
124
|
-
#
|
125
|
-
# @return [Array<String>]
|
126
|
-
def backtrace
|
127
|
-
return nil if super.nil?
|
128
|
-
sass_backtrace.map do |h|
|
129
|
-
"#{h[:filename] || "(sass)"}:#{h[:line]}" +
|
130
|
-
(h[:mixin] ? ":in `#{h[:mixin]}'" : "")
|
131
|
-
end + super
|
132
|
-
end
|
133
|
-
|
134
|
-
# Returns a string representation of the Sass backtrace.
|
135
|
-
#
|
136
|
-
# @param default_filename [String] The filename to use for unknown files
|
137
|
-
# @see #sass_backtrace
|
138
|
-
# @return [String]
|
139
|
-
def sass_backtrace_str(default_filename = "an unknown file")
|
140
|
-
lines = self.message.split("\n")
|
141
|
-
msg = lines[0] + lines[1..-1].
|
142
|
-
map {|l| "\n" + (" " * "Syntax error: ".size) + l}.join
|
143
|
-
"Syntax error: #{msg}" +
|
144
|
-
Haml::Util.enum_with_index(sass_backtrace).map do |entry, i|
|
145
|
-
"\n #{i == 0 ? "on" : "from"} line #{entry[:line]}" +
|
146
|
-
" of #{entry[:filename] || default_filename}" +
|
147
|
-
(entry[:mixin] ? ", in `#{entry[:mixin]}'" : "")
|
148
|
-
end.join
|
149
|
-
end
|
150
|
-
|
151
|
-
class << self
|
152
|
-
# Returns an error report for an exception in CSS format.
|
153
|
-
#
|
154
|
-
# @param e [Exception]
|
155
|
-
# @param options [{Symbol => Object}] The options passed to {Sass::Engine#initialize}
|
156
|
-
# @return [String] The error report
|
157
|
-
# @raise [Exception] `e`, if the
|
158
|
-
# {file:SASS_REFERENCE.md#full_exception-option `:full_exception`} option
|
159
|
-
# is set to false.
|
160
|
-
def exception_to_css(e, options)
|
161
|
-
raise e unless options[:full_exception]
|
162
|
-
|
163
|
-
header = header_string(e, options)
|
164
|
-
|
165
|
-
<<END
|
166
|
-
/*
|
167
|
-
#{header}
|
168
|
-
|
169
|
-
Backtrace:\n#{e.backtrace.join("\n")}
|
170
|
-
*/
|
171
|
-
body:before {
|
172
|
-
white-space: pre;
|
173
|
-
font-family: monospace;
|
174
|
-
content: "#{header.gsub('"', '\"').gsub("\n", '\\A ')}"; }
|
175
|
-
END
|
176
|
-
end
|
177
|
-
|
178
|
-
private
|
179
|
-
|
180
|
-
def header_string(e, options)
|
181
|
-
return "#{e.class}: #{e.message}" unless e.is_a? Sass::SyntaxError
|
182
|
-
|
183
|
-
line_offset = options[:line] || 1
|
184
|
-
line_num = e.sass_line + 1 - line_offset
|
185
|
-
min = [line_num - 6, 0].max
|
186
|
-
section = e.sass_template.rstrip.split("\n")[min ... line_num + 5]
|
187
|
-
return e.sass_backtrace_str if section.nil? || section.empty?
|
188
|
-
|
189
|
-
e.sass_backtrace_str + "\n\n" + Haml::Util.enum_with_index(section).
|
190
|
-
map {|line, i| "#{line_offset + min + i}: #{line}"}.join("\n")
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
# The class for Sass errors that are raised due to invalid unit conversions
|
196
|
-
# in SassScript.
|
197
|
-
class UnitConversionError < SyntaxError; end
|
198
|
-
end
|
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
|