Skip to content

Commit

Permalink
Treat IronRuby as Ruby 1.8 even if it says it's 1.9.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Nov 16, 2010
1 parent 01ecd6b commit 21812ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc-src/HAML_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* `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
3 changes: 3 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
* 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.

## 3.0.23

[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.23).
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

0 comments on commit 21812ac

Please sign in to comment.