Merge branch 'master' into scss

This commit is contained in:
Nathan Weizenbaum 2010-01-23 14:52:57 -08:00
commit 1372f5c527
15 changed files with 83 additions and 17 deletions

View File

@ -154,6 +154,14 @@ that surrounds the filtered text with `<style>` and CDATA tags.
* The `puts` helper has been removed.
Use {Haml::Helpers#haml\_concat} instead.
## 2.2.18 (Unreleased)
* Use `Rails.env` rather than `RAILS_ENV` when running under Rails 3.0.
Thanks to [Duncan Grazier](http://duncangrazier.com/).
* Add a `--unix-newlines` flag to all executables
for outputting Unix-style newlines on Windows.
## [2.2.17](http://github.com/nex3/haml/commit/2.2.16)
* Fix compilation of HTML5 doctypes when using `html2haml`.

View File

@ -1162,19 +1162,18 @@ should end wit `|`.**
For example:
%whoo
%hoo I think this might get |
pretty long so I should |
probably make it |
multiline so it doesn't |
look awful. |
%hoo= h( |
"I think this might get " + |
"pretty long so I should " + |
"probably make it " + |
"multiline so it doesn't " + |
"look awful.") |
%p This is short.
is compiled to:
<whoo>
<hoo>
I think this might get pretty long so I should probably make it multiline so it doesn't look awful.
</hoo>
<hoo>I think this might get pretty long so I should probably make it multiline so it doesn't look awful.</hoo>
<p>This is short</p>
</whoo>

View File

@ -144,6 +144,21 @@ 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.18 (Unreleased)
* Use `Rails.env` rather than `RAILS_ENV` when running under Rails 3.0.
Thanks to [Duncan Grazier](http://duncangrazier.com/).
* Support `:line_numbers` as an alias for {file:SASS_REFERENCE.md#line_numbers-option `:line_comments`},
since that's what the docs have said forever.
Similarly, support `--line-numbers` as a command-line option.
* Add a `--unix-newlines` flag to all executables
for outputting Unix-style newlines on Windows.
* Add a {file:SASS_REFERENCE.md#unix_newlines-option `:unix_newlines` option}
for {Sass::Plugin} for outputting Unix-style newlines on Windows.
## [2.2.17](http://github.com/nex3/haml/commit/2.2.16)
* When the {file:SASS_REFERENCE.md#full_exception-option `:full_exception` option}

View File

@ -184,6 +184,11 @@ Available options are:
Defaults to `"./tmp/sass-cache"` in Rails and Merb,
or `"./.sass-cache"` otherwise.
{#unix_newlines-option} `:unix_newlines`
: If true, use Unix-style newlines when writing files.
Only has meaning on Windows, and only when Sass is writing the files
(in Rack, Rails, or Merb, or when using {Sass::Plugin} directly).
{#filename-option} `:filename`
: The filename of the file being rendered.
This is used solely for reporting errors,
@ -205,6 +210,7 @@ Available options are:
where a selector is defined to be emitted into the compiled CSS
as a comment. Useful for debugging especially when using imports
and mixins.
This option may also be called `:line_comments`.
{#custom-option} `:custom`
: An option that's available for individual applications to set

View File

@ -1,5 +1,6 @@
require 'optparse'
require 'fileutils'
require 'rbconfig'
module Haml
# This module handles the various Haml executables (`haml`, `sass`, `css2sass`, etc).
@ -67,6 +68,12 @@ module Haml
@options[:trace] = true
end
if RbConfig::CONFIG['host_os'] =~ /mswin|windows/i
opts.on('--unix-newlines', 'Use Unix-style newlines in written files.') do
@options[:unix_newlines] = true
end
end
opts.on_tail("-?", "-h", "--help", "Show this message") do
puts opts
exit
@ -105,6 +112,7 @@ module Haml
def open_file(filename, flag = 'r')
return if filename.nil?
flag = 'wb' if @options[:unix_newlines] && flag == 'w'
File.open(filename, flag)
end
end
@ -218,9 +226,9 @@ END
'Output style. Can be nested (default), compact, compressed, or expanded.') do |name|
@options[:for_engine][:style] = name.to_sym
end
opts.on('-l', '--line-comments',
'Line Comments. Emit comments in the generated CSS indicating the corresponding sass line.') do
@options[:for_engine][:line_comments] = true
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
end
opts.on('-i', '--interactive',
'Run an interactive SassScript shell.') do

View File

@ -39,7 +39,7 @@ module Haml
end
end
if defined?(RAILS_ENV) && RAILS_ENV == "production"
if Haml::Util.rails_env == "production"
Haml::Template.options[:ugly] = true
end

View File

@ -180,6 +180,17 @@ module Haml
return nil
end
# Returns the environment of the Rails application,
# if this is running in a Rails context.
# Returns `nil` if no such environment is defined.
#
# @return [String, nil]
def rails_env
return Rails.env.to_s if defined?(Rails.root)
return RAILS_ENV.to_s if defined?(RAILS_ENV)
return nil
end
# Returns an ActionView::Template* class.
# In pre-3.0 versions of Rails, most of these classes
# were of the form `ActionView::TemplateFoo`,

View File

@ -147,6 +147,10 @@ module Sass
@options = DEFAULT_OPTIONS.merge(options.reject {|k, v| v.nil?})
@template = template
# Support both, because the docs said one and the other actually worked
# for quite a long time.
@options[:line_comments] ||= @options[:line_numbers]
# Backwards compatibility
@options[:property_syntax] ||= @options[:attribute_syntax]
case @options[:property_syntax]

View File

@ -1,4 +1,5 @@
require 'sass'
require 'rbconfig'
require 'fileutils'
@ -105,9 +106,9 @@ module Sass
FileUtils.mkdir_p(File.dirname(css))
# Finally, write the file
File.open(css, 'w') do |file|
file.print(result)
end
flag = 'w'
flag = 'wb' if RbConfig::CONFIG['host_os'] =~ /mswin|windows/i && options[:unix_newlines]
File.open(css, flag) {|file| file.print(result)}
end
def load_paths(opts = options)

View File

@ -4,8 +4,8 @@ unless defined?(Sass::RAILS_LOADED)
Sass::Plugin.options.merge!(:template_location => Haml::Util.rails_root + '/public/stylesheets/sass',
:css_location => Haml::Util.rails_root + '/public/stylesheets',
:cache_location => Haml::Util.rails_root + '/tmp/sass-cache',
:always_check => RAILS_ENV != "production",
:full_exception => RAILS_ENV != "production")
:always_check => Haml::Util.rails_env != "production",
:full_exception => Haml::Util.rails_env != "production")
if defined?(Rails.configuration.middleware)
# Rails >= 3.0

View File

@ -38,6 +38,12 @@ module Sass
raise e
end
# @see \{Node#perform!}
def perform!(environment)
environment.options = @options if environment.options.nil? || environment.options.empty?
super
end
protected
# Destructively converts this static Sass node into a static CSS node,

View File

@ -7,6 +7,7 @@ class SassPluginTest < Test::Unit::TestCase
@@templates = %w{
complex script parent_ref import scss_import alt
subdir/subdir subdir/nested_subdir/nested_subdir
options
}
def setup

View File

@ -0,0 +1 @@
foo { style: compact; }

View File

@ -0,0 +1,2 @@
foo
style= option("style")

View File

@ -12,6 +12,10 @@ Sass::RAILS_LOADED = true unless defined?(Sass::RAILS_LOADED)
module Sass::Script::Functions
module UserFunctions; end
include UserFunctions
def option(name)
Sass::Script::String.new(@options[name.value.to_sym].to_s)
end
end
class Test::Unit::TestCase