From 268f8782a7337de3d32499b6e9900a76eb12e269 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Wed, 20 Jan 2010 20:30:14 -0800 Subject: [PATCH 01/11] [Sass] Test case to make sure options get passed from the plugin to the stylesheet environment. Conflicts: test/test_helper.rb --- test/sass/plugin_test.rb | 1 + test/sass/results/options.css | 1 + test/sass/templates/options.sass | 2 ++ test/test_helper.rb | 4 ++++ 4 files changed, 8 insertions(+) create mode 100644 test/sass/results/options.css create mode 100644 test/sass/templates/options.sass diff --git a/test/sass/plugin_test.rb b/test/sass/plugin_test.rb index b18c097d..9ffe6fce 100755 --- a/test/sass/plugin_test.rb +++ b/test/sass/plugin_test.rb @@ -7,6 +7,7 @@ class SassPluginTest < Test::Unit::TestCase @@templates = %w{ complex script parent_ref import alt subdir/subdir subdir/nested_subdir/nested_subdir + options } def setup diff --git a/test/sass/results/options.css b/test/sass/results/options.css new file mode 100644 index 00000000..628f4c33 --- /dev/null +++ b/test/sass/results/options.css @@ -0,0 +1 @@ +foo { style: compact; } \ No newline at end of file diff --git a/test/sass/templates/options.sass b/test/sass/templates/options.sass new file mode 100644 index 00000000..17e669f8 --- /dev/null +++ b/test/sass/templates/options.sass @@ -0,0 +1,2 @@ +foo + style= option("style") \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 13715a43..be79d28e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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 From c11d09680e48a55f221f94b3127eef87513372a6 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 21 Nov 2009 10:10:40 -0800 Subject: [PATCH 02/11] [Sass] Fix a bug that caused the Sass::Engine options to not get passed to the Stylesheet Environment. --- lib/sass/tree/root_node.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/sass/tree/root_node.rb b/lib/sass/tree/root_node.rb index 7fafb246..4331eaa6 100644 --- a/lib/sass/tree/root_node.rb +++ b/lib/sass/tree/root_node.rb @@ -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, From 32f7eba94d0d15137ac02e8af9b94361c53d526b Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 21 Jan 2010 20:07:16 -0800 Subject: [PATCH 03/11] Abstracted out Rails environment to Haml::Util to allow backwards compatability. --- lib/haml/template.rb | 2 +- lib/haml/util.rb | 11 +++++++++++ lib/sass/plugin/rails.rb | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/haml/template.rb b/lib/haml/template.rb index 1aa26a46..6455ada3 100644 --- a/lib/haml/template.rb +++ b/lib/haml/template.rb @@ -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 diff --git a/lib/haml/util.rb b/lib/haml/util.rb index 4cf37213..16b2f5b4 100644 --- a/lib/haml/util.rb +++ b/lib/haml/util.rb @@ -146,6 +146,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`, diff --git a/lib/sass/plugin/rails.rb b/lib/sass/plugin/rails.rb index 8d4a5f40..0d2c6292 100644 --- a/lib/sass/plugin/rails.rb +++ b/lib/sass/plugin/rails.rb @@ -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?(ActionDispatch::Callbacks.to_prepare) # Rails >= 3.0.0 From 9984c35c29992f326f013649b7cadd359d4e3124 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 21 Jan 2010 20:08:46 -0800 Subject: [PATCH 04/11] Add changelog entries for Haml::Util.rails_env. --- doc-src/HAML_CHANGELOG.md | 5 +++++ doc-src/SASS_CHANGELOG.md | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/doc-src/HAML_CHANGELOG.md b/doc-src/HAML_CHANGELOG.md index 4217358c..e1402625 100644 --- a/doc-src/HAML_CHANGELOG.md +++ b/doc-src/HAML_CHANGELOG.md @@ -3,6 +3,11 @@ * Table of contents {:toc} +## 2.2.18 (Unreleased) + +* Use `Rails.env` rather than `RAILS_ENV` when running under Rails 3.0. + Thanks to [Duncan Grazier](http://duncangrazier.com/). + ## [2.2.17](http://github.com/nex3/haml/commit/2.2.16) * Fix compilation of HTML5 doctypes when using `html2haml`. diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index 20007c54..0f7ffa6f 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -3,6 +3,11 @@ * Table of contents {:toc} +## 2.2.18 (Unreleased) + +* Use `Rails.env` rather than `RAILS_ENV` when running under Rails 3.0. + Thanks to [Duncan Grazier](http://duncangrazier.com/). + ## [2.2.17](http://github.com/nex3/haml/commit/2.2.16) * When the {file:SASS_REFERENCE.md#full_exception-option `:full_exception` option} From 6ff8c045234aa18fd5440ee54433bd4cfdc803f0 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 21 Jan 2010 20:18:46 -0800 Subject: [PATCH 05/11] [Haml] Fix a minor error in the reference. --- doc-src/HAML_REFERENCE.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/doc-src/HAML_REFERENCE.md b/doc-src/HAML_REFERENCE.md index 0d66a804..8e34759a 100644 --- a/doc-src/HAML_REFERENCE.md +++ b/doc-src/HAML_REFERENCE.md @@ -1132,19 +1132,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: - - I think this might get pretty long so I should probably make it multiline so it doesn't look awful. - + I think this might get pretty long so I should probably make it multiline so it doesn't look awful.

This is short

From 436d4fd3958b7d6d53d60ecfc605b2b33fb043ff Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Fri, 22 Jan 2010 08:51:03 -0800 Subject: [PATCH 06/11] [Sass] Make :line_numbers an alias for :line_comments. --- doc-src/SASS_CHANGELOG.md | 3 +++ doc-src/SASS_REFERENCE.md | 1 + lib/sass/engine.rb | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index 0f7ffa6f..97819a37 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -8,6 +8,9 @@ * 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. + ## [2.2.17](http://github.com/nex3/haml/commit/2.2.16) * When the {file:SASS_REFERENCE.md#full_exception-option `:full_exception` option} diff --git a/doc-src/SASS_REFERENCE.md b/doc-src/SASS_REFERENCE.md index 53711f71..a2a77cf8 100644 --- a/doc-src/SASS_REFERENCE.md +++ b/doc-src/SASS_REFERENCE.md @@ -205,6 +205,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 diff --git a/lib/sass/engine.rb b/lib/sass/engine.rb index 2998d4aa..f8d639ae 100644 --- a/lib/sass/engine.rb +++ b/lib/sass/engine.rb @@ -144,6 +144,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] From ea814b0bfaa98234c4b28eb820596cf346ddd4c3 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sat, 23 Jan 2010 12:17:05 -0800 Subject: [PATCH 07/11] [Sass] Make --line-numbers work for --line-comments on the command-line. --- lib/haml/exec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/haml/exec.rb b/lib/haml/exec.rb index bfefae62..54c3ae21 100644 --- a/lib/haml/exec.rb +++ b/lib/haml/exec.rb @@ -214,9 +214,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 From 518ba4cc2a3487f509d717ac952a8557cf31a75d Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sat, 23 Jan 2010 12:52:30 -0800 Subject: [PATCH 08/11] Add a command-line option for writing files in binary mode on Windows. --- lib/haml/exec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/haml/exec.rb b/lib/haml/exec.rb index 54c3ae21..1c44c5d2 100644 --- a/lib/haml/exec.rb +++ b/lib/haml/exec.rb @@ -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 From bddbcff8c611160bab648e4b8b5212bd0ca3276c Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sat, 23 Jan 2010 12:58:46 -0800 Subject: [PATCH 09/11] [Sass] Document --line-numbers. --- doc-src/SASS_CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index 97819a37..265c9a4d 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -10,6 +10,7 @@ * 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. ## [2.2.17](http://github.com/nex3/haml/commit/2.2.16) From 75ca39ea79c05c4434c35d5bcf74dbab009c7efd Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sat, 23 Jan 2010 13:00:14 -0800 Subject: [PATCH 10/11] Document --unix-newlines. --- doc-src/HAML_CHANGELOG.md | 3 +++ doc-src/SASS_CHANGELOG.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/doc-src/HAML_CHANGELOG.md b/doc-src/HAML_CHANGELOG.md index e1402625..ad5dedda 100644 --- a/doc-src/HAML_CHANGELOG.md +++ b/doc-src/HAML_CHANGELOG.md @@ -8,6 +8,9 @@ * 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`. diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index 265c9a4d..00aab303 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -12,6 +12,9 @@ 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. + ## [2.2.17](http://github.com/nex3/haml/commit/2.2.16) * When the {file:SASS_REFERENCE.md#full_exception-option `:full_exception` option} From 579a659b7d97dc537a6b6ec7b72290f037584292 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sat, 23 Jan 2010 13:06:45 -0800 Subject: [PATCH 11/11] [Sass] Add a :unix_newlines option for Sass::Plugin. Closes gh-82 --- doc-src/SASS_CHANGELOG.md | 3 +++ doc-src/SASS_REFERENCE.md | 5 +++++ lib/sass/plugin.rb | 7 ++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index 00aab303..92763216 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -15,6 +15,9 @@ * 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} diff --git a/doc-src/SASS_REFERENCE.md b/doc-src/SASS_REFERENCE.md index a2a77cf8..5a0895be 100644 --- a/doc-src/SASS_REFERENCE.md +++ b/doc-src/SASS_REFERENCE.md @@ -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, diff --git a/lib/sass/plugin.rb b/lib/sass/plugin.rb index 5339e7f9..a5f2f60f 100644 --- a/lib/sass/plugin.rb +++ b/lib/sass/plugin.rb @@ -1,4 +1,5 @@ require 'sass' +require 'rbconfig' module Sass # This module handles the compilation of Sass files. @@ -103,9 +104,9 @@ module Sass mkpath(css_location, name) # 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 # Create any successive directories required to be able to write a file to: File.join(base,name)