mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Pipe all warnings through Haml::Util.haml_warn.
This commit is contained in:
parent
39fb6609df
commit
3a3b8234a2
7 changed files with 41 additions and 7 deletions
|
@ -77,7 +77,7 @@ if Haml::Util.rails_root
|
|||
FileUtils.cp(haml_init_file, rails_init_file) unless FileUtils.cmp(rails_init_file, haml_init_file)
|
||||
end
|
||||
rescue SystemCallError
|
||||
warn <<END
|
||||
Haml::Util.haml_warn <<END
|
||||
HAML WARNING:
|
||||
#{rails_init_file} is out of date and couldn't be automatically updated.
|
||||
Please run `haml --rails #{File.expand_path(Haml::Util.rails_root)}' to update it.
|
||||
|
|
|
@ -168,6 +168,26 @@ module Haml
|
|||
$stderr = the_real_stderr
|
||||
end
|
||||
|
||||
@@silence_warnings = false
|
||||
# Silences all Haml warnings within a block.
|
||||
#
|
||||
# @yield A block in which no Haml warnings will be printed
|
||||
def silence_haml_warnings
|
||||
old_silence_warnings = @@silence_warnings
|
||||
@@silence_warnings = true
|
||||
yield
|
||||
ensure
|
||||
@@silence_warnings = old_silence_warnings
|
||||
end
|
||||
|
||||
# The same as `Kernel#warn`, but is silenced by \{#silence\_haml\_warnings}.
|
||||
#
|
||||
# @param msg [String]
|
||||
def haml_warn(msg)
|
||||
return if @@silence_warnings
|
||||
warn(msg)
|
||||
end
|
||||
|
||||
## Cross Rails Version Compatibility
|
||||
|
||||
# Returns the root of the Rails application,
|
||||
|
|
|
@ -356,7 +356,7 @@ MSG
|
|||
|
||||
def check_for_no_children(node)
|
||||
return unless node.is_a?(Tree::RuleNode) && node.children.empty?
|
||||
warn(<<WARNING.strip)
|
||||
Haml::Util.haml_warn(<<WARNING.strip)
|
||||
WARNING on line #{node.line}#{" of #{node.filename}" if node.filename}:
|
||||
This selector doesn't have any properties and will not be rendered.
|
||||
WARNING
|
||||
|
|
|
@ -81,7 +81,7 @@ module Sass
|
|||
|
||||
return new_filename if new_filename
|
||||
unless was_sass || was_scss
|
||||
warn <<END
|
||||
Haml::Util.haml_warn <<END
|
||||
WARNING: Neither #{filename}.sass nor .scss found. Using #{filename}.css instead.
|
||||
This behavior is deprecated and will be removed in a future version.
|
||||
If you really need #{filename}.css, import it explicitly.
|
||||
|
@ -116,7 +116,7 @@ END
|
|||
return Marshal.load(f.read)
|
||||
end
|
||||
rescue EOFError, TypeError, ArgumentError => e
|
||||
warn "Warning. Error encountered while reading cache #{compiled_filename}: #{e}"
|
||||
Haml::Util.haml_warn "Warning. Error encountered while reading cache #{compiled_filename}: #{e}"
|
||||
end
|
||||
|
||||
def try_to_write_sassc(root, compiled_filename, sha, options)
|
||||
|
|
|
@ -40,7 +40,7 @@ module Sass
|
|||
|
||||
# @private
|
||||
def self.var_warning(varname, line, offset, filename)
|
||||
warn <<MESSAGE
|
||||
Haml::Util.haml_warn <<MESSAGE
|
||||
DEPRECATION WARNING:
|
||||
On line #{line}, character #{offset}#{" of '#{filename}'" if filename}
|
||||
Variables with ! have been deprecated and will be removed in version 3.2.
|
||||
|
@ -49,7 +49,7 @@ MESSAGE
|
|||
end
|
||||
|
||||
def self.equals_warning(types, name, val, line, offset, filename)
|
||||
warn <<MESSAGE
|
||||
Haml::Util.haml_warn <<MESSAGE
|
||||
DEPRECATION WARNING:
|
||||
On line #{line}#{", character #{offset}" if offset}#{" of '#{filename}'" if filename}
|
||||
Setting #{types} with = has been deprecated and will be removed in version 3.2.
|
||||
|
|
|
@ -184,7 +184,7 @@ module Sass::Script
|
|||
# @deprecated This will be removed in version 3.2.
|
||||
# @see #rgb
|
||||
def value
|
||||
warn <<END
|
||||
Haml::Util.haml_warn <<END
|
||||
DEPRECATION WARNING:
|
||||
The Sass::Script::Color #value attribute is deprecated and will be
|
||||
removed in version 3.2. Use the #rgb attribute instead.
|
||||
|
|
|
@ -85,6 +85,20 @@ class UtilTest < Test::Unit::TestCase
|
|||
$stderr = old_stderr
|
||||
end
|
||||
|
||||
def test_haml_warn
|
||||
assert_warning("Foo!") {haml_warn "Foo!"}
|
||||
end
|
||||
|
||||
def test_silence_haml_warnings
|
||||
old_stderr, $stderr = $stderr, StringIO.new
|
||||
silence_haml_warnings {warn "Out"}
|
||||
assert_equal("Out\n", $stderr.string)
|
||||
silence_haml_warnings {haml_warn "In"}
|
||||
assert_equal("Out\n", $stderr.string)
|
||||
ensure
|
||||
$stderr = old_stderr
|
||||
end
|
||||
|
||||
def test_has
|
||||
assert(has?(:instance_method, String, :chomp!))
|
||||
assert(has?(:private_instance_method, Haml::Engine, :set_locals))
|
||||
|
|
Loading…
Reference in a new issue