Skip to content

Commit

Permalink
Merge branch 'master' into scss
Browse files Browse the repository at this point in the history
Conflicts:
	lib/haml/util.rb
	test/haml/util_test.rb
  • Loading branch information
nex3 committed Mar 22, 2010
2 parents 7ba6975 + 92d84f2 commit 1258f5b
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 61 deletions.
70 changes: 43 additions & 27 deletions Rakefile
Expand Up @@ -384,41 +384,57 @@ end

# ----- Handling Updates -----

def ensure_git_cleanup
def email_on_error
yield
rescue Exception => e
IO.popen("sendmail nex342@gmail.com", "w") do |sm|
sm << "From: nex3@nex-3.com\n" <<
"To: nex342@gmail.com\n" <<
"Subject: Exception when running rake #{Rake.application.top_level_tasks.join(', ')}\n" <<
e.message << "\n\n" <<
e.backtrace.join("\n")
end
ensure
raise e if e
end

def ensure_git_cleanup
email_on_error {yield}
ensure
sh %{git reset --hard HEAD}
sh %{git clean -xdf}
sh %{git checkout master}
end

task :handle_update do
unless ENV["REF"] =~ %r{^refs/heads/(master|stable|(?:haml|sass)-pages)$}
puts "#{'=' * 20} Ignoring rake handle_update REF=#{ENV["REF"].inspect}"
next
end
branch = $1

puts
puts
puts '=' * 150
puts "Running rake handle_update REF=#{ENV["REF"].inspect}"
email_on_error do
unless ENV["REF"] =~ %r{^refs/heads/(master|stable|(?:haml|sass)-pages)$}
puts "#{'=' * 20} Ignoring rake handle_update REF=#{ENV["REF"].inspect}"
next
end
branch = $1

puts
puts
puts '=' * 150
puts "Running rake handle_update REF=#{ENV["REF"].inspect}"

sh %{git fetch origin}
sh %{git checkout stable}
sh %{git reset --hard origin/stable}
sh %{git checkout master}
sh %{git reset --hard origin/master}

if branch == "master"
sh %{rake release_edge --trace}
elsif branch == "stable"
sh %{rake pages --trace PROJ=haml}
sh %{rake pages --trace PROJ=sass}
elsif branch =~ /^(haml|sass)-pages$/
sh %{rake pages --trace PROJ=#{$1}}
end

sh %{git fetch origin}
sh %{git checkout stable}
sh %{git reset --hard origin/stable}
sh %{git checkout master}
sh %{git reset --hard origin/master}

if branch == "master"
sh %{rake release_edge --trace}
elsif branch == "stable"
sh %{rake pages --trace PROJ=haml}
sh %{rake pages --trace PROJ=sass}
elsif branch =~ /^(haml|sass)-pages$/
sh %{rake pages --trace PROJ=#{$1}}
puts 'Done running handle_update'
puts '=' * 150
end

puts 'Done running handle_update'
puts '=' * 150
end
27 changes: 21 additions & 6 deletions doc-src/HAML_CHANGELOG.md
Expand Up @@ -126,6 +126,11 @@ can now take regular expressions that specify which tags to make self-closing.
The Haml executable now has a `--double-quote-attributes` option (short form: `-q`)
that causes attributes to use a double-quote mark rather than single-quote.

### `:css` Filter

Haml now supports a {file:HAML_REFERENCE.md#css-filter `:css` filter}
that surrounds the filtered text with `<style>` and CDATA tags.

### `haml-spec` Integration

We've added the cross-implementation tests from the [haml-spec](http://github.com/norman/haml-spec) project
Expand All @@ -141,18 +146,18 @@ of the many and varied [Haml implementations](http://en.wikipedia.org/wiki/Haml#
* Haml and `html2haml` now accept Unicode documents with a
[byte-order-mark](http://en.wikipedia.org/wiki/Byte_order_mark).

### `:css` Filter

Haml now supports a {file:HAML_REFERENCE.md#css-filter `:css` filter}
that surrounds the filtered text with `<style>` and CDATA tags.

### Rails Support

* When `form_for` is used with `=`, or `form_tag` is used with `=` and a block,
they will now raise errors explaining that they should be used with `-`.
This is similar to how {Haml::Helpers#haml\_concat} behaves,
and will hopefully clear up some difficult bugs for some users.

### Rip Support

Haml is now compatible with the [Rip](http://hellorip.com/) package management system.
Thanks to [Josh Peek](http://joshpeek.com/).

### `html2haml` Improvements

* Ruby blocks within ERB are now supported.
Expand Down Expand Up @@ -252,7 +257,9 @@ that surrounds the filtered text with `<style>` and CDATA tags.
* The `puts` helper has been removed.
Use {Haml::Helpers#haml\_concat} instead.

## 2.2.22 (Unreleased)
## 2.2.22

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

* Add a railtie so Haml and Sass will be automatically loaded in Rails 3.
Thanks to [Daniel Neighman](http://pancakestacks.wordpress.com/).
Expand All @@ -261,6 +268,14 @@ that surrounds the filtered text with `<style>` and CDATA tags.
that return strings in Rails 3.
This is [the same deprecation that exists in Rails 3](http://github.com/rails/rails/commit/9de83050d3a4b260d4aeb5d09ec4eb64f913ba64).

* Make sure line numbers are reported correctly when filters are being used.

* Make loading the gemspec not crash on read-only filesystems like Heroku's.

* Don't crash when methods like `form_for` return `nil` in, for example, Rails 3 beta.

* Compatibility with Rails 3 beta's RJS facilities.

## 2.2.21

[Tagged on GitHub](http://github.com/nex3/haml/commit/2.2.21).
Expand Down
21 changes: 20 additions & 1 deletion doc-src/SASS_CHANGELOG.md
Expand Up @@ -229,6 +229,21 @@ That is, with the nested properties indented in the source.
The Sass Rails plugin now works using Rack middleware by default
in versions of Rails that support it (2.3 and onwards).

### Firebug Support

A new {file:SASS_REFERENCE.md#debug_info-option `:debug_info` option}
has been added that emits line-number and filename information
to the CSS file in a browser-readable format.
This can be used with the new [FireSass Firebug extension](https://addons.mozilla.org/en-US/firefox/addon/103988)
to report the Sass filename and line number for generated CSS files.

This is also available via the `--debug-info` command-line flag.

### Rip Support

Haml is now compatible with the [Rip](http://hellorip.com/) package management system.
Thanks to [Josh Peek](http://joshpeek.com/).

### Sass::Plugin Callbacks

{Sass::Plugin} now has a large collection of callbacks that allow users
Expand Down Expand Up @@ -269,11 +284,15 @@ Several bug fixes and minor improvements have been made, including:
and `tealbang(12)` now renders as `tealbang(12)`
rather than `teal bang(12)`.

## 2.2.22 (Unreleased)
## 2.2.22

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

* Add a railtie so Haml and Sass will be automatically loaded in Rails 3.
Thanks to [Daniel Neighman](http://pancakestacks.wordpress.com/).

* Make loading the gemspec not crash on read-only filesystems like Heroku's.

## 2.2.21

[Tagged on GitHub](http://github.com/nex3/haml/commit/2.2.21).
Expand Down
12 changes: 11 additions & 1 deletion doc-src/SASS_REFERENCE.md
Expand Up @@ -208,9 +208,19 @@ Available options are:
{#line_numbers-option} `:line_numbers`
: When set to true, causes the line number and file
where a selector is defined to be emitted into the compiled CSS
as a comment. Useful for debugging especially when using imports
as a comment. Useful for debugging, especially when using imports
and mixins.
This option may also be called `:line_comments`.
Automatically disabled when using the `:compressed` output style
or the `:debug_info` option.

{#debug_info-option} `:debug_info`
: When set to true, causes the line number and file
where a selector is defined to be emitted into the compiled CSS
in a format that can be understood by the browser.
Useful in conjunction with [the FireSass Firebug extension](https://addons.mozilla.org/en-US/firefox/addon/103988)
for displaying the Sass filename and line number.
Automatically disabled when using the `:compressed` output style.

{#custom-option} `:custom`
: An option that's available for individual applications to set
Expand Down
10 changes: 10 additions & 0 deletions ext/extconf.rb
@@ -0,0 +1,10 @@
root = File.expand_path("../..", __FILE__)
File.open(File.expand_path("lib/haml/root.rb", root), "w") do |f|
f << <<-RUBY
module Haml
ROOT_DIR = #{root.inspect}
end
RUBY
end

File.open('Makefile', 'w') { |f| f.puts("install:\n\t$(exit 0)") }
19 changes: 14 additions & 5 deletions haml.gemspec
Expand Up @@ -25,14 +25,23 @@ HAML_GEMSPEC = Gem::Specification.new do |spec|
spec.add_development_dependency 'yard', '>= 0.5.3'
spec.add_development_dependency 'maruku', '>= 0.5.9'

# We need the revision file to exist,
# so we just create it if it doesn't.
# It'll usually just get overwritten, though.
File.open('REVISION', 'w') { |f| f.puts "(unknown)" } unless File.exist?('REVISION')
have_revision = true
unless File.exist?('REVISION')
begin
# We need the revision file to exist,
# so we just create it if it doesn't.
# It'll usually just get overwritten, though.
File.open('REVISION', 'w') { |f| f.puts "(unknown)" }
rescue
# If the file can't be created (e.g. on Heroku) continue without it
have_revision = false
end
end

readmes = FileList.new('*') do |list|
list.exclude(/(^|[^.a-z])[a-z]+/)
list.exclude('TODO')
list.include('REVISION')
list.include('REVISION') if have_revision
end.to_a
spec.executables = ['haml', 'html2haml', 'sass', 'css2sass']
spec.files = FileList['rails/init.rb', 'lib/**/*', 'vendor/**/*',
Expand Down
4 changes: 4 additions & 0 deletions lib/haml/exec.rb
Expand Up @@ -233,6 +233,10 @@ 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('-g', '--debug-info',
'Emit extra information in the generated CSS that can be used by the FireSass Firebug plugin.') do
@options[:for_engine][:debug_info] = true
end
opts.on('-l', '--line-numbers', '--line-comments',
'Emit comments in the generated CSS indicating the corresponding sass line.') do
@options[:for_engine][:line_numbers] = true
Expand Down
10 changes: 8 additions & 2 deletions lib/haml/filters.rb
Expand Up @@ -100,8 +100,10 @@ def compile(precompiler, text)
if contains_interpolation?(text)
return if options[:suppress_eval]

push_script <<RUBY, :escape_html => false
find_and_preserve(#{filter.inspect}.render_with_options(#{unescape_interpolation(text)}, _hamlout.options))
text = unescape_interpolation(text).gsub("\\n", "\n")
newline if text.gsub!(/\n"\Z/, "\\n\"")
push_script <<RUBY.strip, :escape_html => false
find_and_preserve(#{filter.inspect}.render_with_options(#{text}, _hamlout.options))
RUBY
return
end
Expand All @@ -113,6 +115,10 @@ def compile(precompiler, text)
else
push_text(rendered.rstrip)
end

(text.count("\n") - 1).times {newline}
resolve_newlines
newline
end
end

Expand Down
7 changes: 6 additions & 1 deletion lib/haml/helpers/xss_mods.rb
Expand Up @@ -106,7 +106,12 @@ module ActionView
module Helpers
module CaptureHelper
def with_output_buffer_with_haml_xss(*args, &block)
Haml::Util.html_safe(with_output_buffer_without_haml_xss(*args, &block))
res = with_output_buffer_without_haml_xss(*args, &block)
case res
when Array; res.map {|s| Haml::Util.html_safe(s)}
when String; Haml::Util.html_safe(res)
else; res
end
end
alias_method :with_output_buffer_without_haml_xss, :with_output_buffer
alias_method :with_output_buffer, :with_output_buffer_with_haml_xss
Expand Down
1 change: 0 additions & 1 deletion lib/haml/precompiler.rb
Expand Up @@ -189,7 +189,6 @@ def precompile
if flat?
push_flat(@line)
@line = @next_line
newline
next
end

Expand Down
3 changes: 3 additions & 0 deletions lib/haml/root.rb
@@ -0,0 +1,3 @@
module Haml
ROOT_DIR = File.expand_path("../../..", __FILE__)
end
16 changes: 13 additions & 3 deletions lib/haml/util.rb
Expand Up @@ -2,6 +2,7 @@
require 'set'
require 'enumerator'
require 'stringio'
require 'haml/root'

module Haml
# A module containing various useful functions.
Expand All @@ -16,7 +17,7 @@ module Util
# @param file [String] The filename relative to the Haml root
# @return [String] The filename relative to the the working directory
def scope(file)
File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), file)
File.join(Haml::ROOT_DIR, file)
end

# Converts an array of `[key, value]` pairs to a hash.
Expand Down Expand Up @@ -244,9 +245,10 @@ def rails_xss_safe?
# With older versions of the Rails XSS-safety mechanism,
# this destructively modifies the HTML-safety of `text`.
#
# @param text [String]
# @return [String] `text`, marked as HTML-safe
# @param text [String, nil]
# @return [String, nil] `text`, marked as HTML-safe
def html_safe(text)
return unless text
return text.html_safe if defined?(ActiveSupport::SafeBuffer)
text.html_safe!
end
Expand Down Expand Up @@ -345,6 +347,14 @@ def enum_cons(enum, n)
ruby1_8? ? enum.enum_cons(n) : enum.each_cons(n)
end

# Returns the ASCII code of the given character.
#
# @param c [String] All characters but the first are ignored.
# @return [Fixnum] The ASCII code of `c`.
def ord(c)
ruby1_8? ? c[0] : c.ord
end

## Static Method Stuff

# The context in which the ERB for \{#def\_static\_method} will be run.
Expand Down

0 comments on commit 1258f5b

Please sign in to comment.