Skip to content

Commit

Permalink
Merge branch 'stable' into merged
Browse files Browse the repository at this point in the history
Conflicts:
	VERSION
	doc-src/HAML_CHANGELOG.md
	doc-src/SASS_CHANGELOG.md
  • Loading branch information
nex3 committed Nov 19, 2010
2 parents 47e6abb + abdcf1c commit 6b55552
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 15 deletions.
10 changes: 10 additions & 0 deletions doc-src/HAML_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
This flag hasn't been necessary since Rails 2.0.
Existing Rails 2.0 installations will continue to work.

## 3.0.24

[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.24).

* `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
21 changes: 21 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@
This flag hasn't been necessary since Rails 2.0.
Existing Rails 2.0 installations will continue to work.

## 3.0.25 (Unreleased)

* When displaying a Sass error in an imported stylesheet,
use the imported stylesheet's contents rather than the top-level stylesheet.

* Fix a bug that caused some lines with non-ASCII characters to be ignored in Ruby 1.8.

## 3.0.24

[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.24).

* 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 @@ -220,7 +229,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 @@ -448,13 +453,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
2 changes: 1 addition & 1 deletion lib/sass/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def tabulate(string)
comment_tab_str = nil
first = true
lines = []
string.gsub(/\r|\n|\r\n|\r\n/, "\n").scan(/^.*?$/).each_with_index do |line, index|
string.gsub(/\r|\n|\r\n|\r\n/, "\n").scan(/^[^\n]*?$/).each_with_index do |line, index|
index += (@options[:line] || 1)
if line.strip.empty?
lines.last.text << "\n" if lines.last && lines.last.comment?
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
6 changes: 3 additions & 3 deletions lib/sass/tree/root_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(template)
def to_s(*args)
super
rescue Sass::SyntaxError => e
e.sass_template = @template
e.sass_template ||= @template
raise e
end

Expand All @@ -36,7 +36,7 @@ def perform(environment)
environment.options = @options if environment.options.nil? || environment.options.empty?
super
rescue Sass::SyntaxError => e
e.sass_template = @template
e.sass_template ||= @template
raise e
end

Expand All @@ -49,7 +49,7 @@ def perform(environment)
def cssize(extends = Haml::Util::SubsetMap.new, parent = nil)
return super(extends, parent), extends
rescue Sass::SyntaxError => e
e.sass_template = @template
e.sass_template ||= @template
raise e
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 6b55552

Please sign in to comment.