Skip to content

Commit

Permalink
Merge remote branch 'refs/remotes/haml/stable' into stable
Browse files Browse the repository at this point in the history
Closes gh-24
Closes gh-22
  • Loading branch information
nex3 committed Nov 16, 2010
2 parents e86dfb3 + 5bf898e commit 422b633
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 11 deletions.
8 changes: 8 additions & 0 deletions doc-src/HAML_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
* Table of contents
{:toc}

## 3.0.24 (Unreleased)

* `html2haml` now properly generates Haml for silent script expressions
nested within blocks.

* IronRuby compatibility. This is sort of a hack: IronRuby reports its version as 1.9,
but it doesn't support the encoding APIs, so we treat it as 1.8 instead.

## 3.0.23

[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.23).
Expand Down
12 changes: 12 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
* Table of contents
{:toc}

## 3.0.24 (Unreleased)

* Raise an error when `@else` appears without an `@if` in SCSS.

* Fix some cases where `@if` rules were causing the line numbers in error reports
to become incorrect.

* IronRuby compatibility. This is sort of a hack: IronRuby reports its version as 1.9,
but it doesn't support the encoding APIs, so we treat it as 1.8 instead.

* The `--quiet` option now silences informational output from `--update` and `--watch`.

## 3.0.23

[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.23).
Expand Down
11 changes: 10 additions & 1 deletion lib/haml/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,18 @@ def process_result
# @param color [Symbol] The name of the color to use for this action.
# Can be `:red`, `:green`, or `:yellow`.
def puts_action(name, color, arg)
return if @options[:for_engine][:quiet]
printf color(color, "%11s %s\n"), name, arg
end

# Same as \{Kernel.puts}, but doesn't print anything if the `--quiet` option is set.
#
# @param args [Array] Passed on to \{Kernel.puts}
def puts(*args)
return if @options[:for_engine][:quiet]
Kernel.puts(*args)
end

# Wraps the given string in terminal escapes
# causing it to have the given color.
# If terminal esapes aren't supported on this platform,
Expand Down Expand Up @@ -300,7 +309,7 @@ def set_opts(opts)
'Output style. Can be nested (default), compact, compressed, or expanded.') do |name|
@options[:for_engine][:style] = name.to_sym
end
opts.on('-q', '--quiet', 'Silence warnings during compilation.') do
opts.on('-q', '--quiet', 'Silence warnings and status messages during compilation.') do
@options[:for_engine][:quiet] = true
end
opts.on('-g', '--debug-info',
Expand Down
14 changes: 7 additions & 7 deletions lib/haml/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,20 @@ class BaseEle
# @private
HAML_TAGS = %w[haml:block haml:loud haml:silent]

Hpricot::ElementContent.keys.each do |k|
HAML_TAGS.each do |el|
val = Hpricot::ElementContent[k]
val[el.hash] = true if val.is_a?(Hash)
end
end

HAML_TAGS.each do |t|
Hpricot::ElementContent[t] = {}
Hpricot::ElementContent.keys.each do |key|
Hpricot::ElementContent[t][key.hash] = true
end
end

Hpricot::ElementContent.keys.each do |k|
HAML_TAGS.each do |el|
val = Hpricot::ElementContent[k]
val[el.hash] = true if val.is_a?(Hash)
end
end

module Haml
# Converts HTML documents into Haml templates.
# Depends on [Hpricot](http://github.com/whymirror/hpricot) for HTML parsing.
Expand Down
19 changes: 18 additions & 1 deletion lib/haml/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ module Util
# @api public
RUBY_VERSION = ::RUBY_VERSION.split(".").map {|s| s.to_i}

# The Ruby engine we're running under. Defaults to `"ruby"`
# if the top-level constant is undefined.
# @api public
RUBY_ENGINE = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : "ruby"

# Returns the path of a file relative to the Haml root directory.
#
# @param file [String] The filename relative to the Haml root
Expand Down Expand Up @@ -415,13 +420,25 @@ def windows?
RbConfig::CONFIG['host_os'] =~ /mswin|windows|mingw/i
end

# Whether or not this is running on IronRuby.
#
# @return [Boolean]
def ironruby?
RUBY_ENGINE == "ironruby"
end

## Cross-Ruby-Version Compatibility

# Whether or not this is running under Ruby 1.8 or lower.
#
# Note that IronRuby counts as Ruby 1.8,
# because it doesn't support the Ruby 1.9 encoding API.
#
# @return [Boolean]
def ruby1_8?
Haml::Util::RUBY_VERSION[0] == 1 && Haml::Util::RUBY_VERSION[1] < 9
# IronRuby says its version is 1.9, but doesn't support any of the encoding APIs.
# We have to fall back to 1.8 behavior.
ironruby? || (Haml::Util::RUBY_VERSION[0] == 1 && Haml::Util::RUBY_VERSION[1] < 9)
end

# Whether or not this is running under Ruby 1.8.6 or lower.
Expand Down
13 changes: 11 additions & 2 deletions lib/sass/scss/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def process_comment(text, node)
node << comment
end

DIRECTIVES = Set[:mixin, :include, :debug, :warn, :for, :while, :if, :extend, :import,
:media, :charset]
DIRECTIVES = Set[:mixin, :include, :debug, :warn, :for, :while, :if, :else,
:extend, :import, :media, :charset]

def directive
return unless tok(/@/)
Expand Down Expand Up @@ -180,12 +180,14 @@ def if_directive
ss
node = block(node(Sass::Tree::IfNode.new(expr)), :directive)
pos = @scanner.pos
line = @line
ss

else_block(node) ||
begin
# Backtrack in case there are any comments we want to parse
@scanner.pos = pos
@line = line
node
end
end
Expand All @@ -198,16 +200,23 @@ def else_block(node)
:directive)
node.add_else(else_node)
pos = @scanner.pos
line = @line
ss

else_block(node) ||
begin
# Backtrack in case there are any comments we want to parse
@scanner.pos = pos
@line = line
node
end
end

def else_directive
raise Sass::SyntaxError.new(
"Invalid CSS: @else must come after @if", :line => @line)
end

def extend_directive
node(Sass::Tree::ExtendNode.new(expr!(:selector)))
end
Expand Down
14 changes: 14 additions & 0 deletions test/haml/html2haml/erb_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,20 @@ def test_tag_inside_block
<tr></tr>
<% end %>
</table>
ERB
end

def test_silent_inside_block_inside_tag
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
%table
- foo.each do
- haml_puts "foo"
HAML
<table>
<% foo.each do %>
<% haml_puts "foo" %>
<% end %>
</table>
ERB
end
end
14 changes: 14 additions & 0 deletions test/sass/scss/scss_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,14 @@ def test_no_interpolation_in_unrecognized_directives
SCSS
end

def test_no_lonely_else
assert_raise_message(Sass::SyntaxError, <<MESSAGE.rstrip) {render <<SCSS}
Invalid CSS: @else must come after @if
MESSAGE
@else {foo: bar}
SCSS
end

# Regression

def test_weird_added_space
Expand Down Expand Up @@ -1083,6 +1091,12 @@ def test_newlines_removed_from_selectors_when_compressed
}
}
SCSS
end

def test_if_error_line
assert_raise_line(2) {render(<<SCSS)}
@if true {foo: bar}
}
SCSS
end
end
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,12 @@ def assert_raise_message(klass, message)
else
flunk "Expected exception #{klass}, none raised"
end

def assert_raise_line(line)
yield
rescue Sass::SyntaxError => e
assert_equal(line, e.sass_line)
else
flunk "Expected exception on line #{line}, none raised"
end
end

0 comments on commit 422b633

Please sign in to comment.