Skip to content
Browse files

Add an 'scss' executable that is the same as the 'sass' executable bu…

…t defaults to the scss syntax.
  • Loading branch information...
1 parent 6c22a79 commit 99e6fdf849943c3e05aac573f2b41ecdfabfcc09 @chriseppstein chriseppstein committed Mar 22, 2011
Showing with 52 additions and 11 deletions.
  1. +8 −0 bin/scss
  2. +5 −0 doc-src/SASS_CHANGELOG.md
  3. +10 −1 doc-src/SASS_REFERENCE.md
  4. +29 −10 lib/sass/exec.rb
View
8 bin/scss
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+# The command line Sass parser.
+
+require File.dirname(__FILE__) + '/../lib/sass'
+require 'sass/exec'
+
+opts = Sass::Exec::Scss.new(ARGV)
+opts.parse!
View
5 doc-src/SASS_CHANGELOG.md
@@ -31,6 +31,11 @@
file -- even with compressed output. This is useful for adding copyright
notices to your stylesheets.
+* A new executable named `scss` is now available. It is exactly like the
+ `sass` executable except it defaults to assuming input is in the SCSS syntax.
+ Both programs will use the source file's extension to determine the syntax where
+ possible.
+
### Keyword Arguments
Both mixins and Sass functions now support the ability to pass in keyword arguments.
View
11 doc-src/SASS_REFERENCE.md
@@ -150,7 +150,7 @@ in `environment.rb` in Rails or `config.ru` in Rack...
...or by passing an options hash to {Sass::Engine#initialize}.
All relevant options are also available via flags
-to the `sass` command-line executable.
+to the `sass` and `scss` command-line executables.
Available options are:
{#style-option} `:style`
@@ -312,6 +312,15 @@ Available options are:
{#quiet-option} `:quiet`
: When set to true, causes warnings to be disabled.
+### Syntax Selection
+
+The Sass command-line tool will use the file extension to determine which
+syntax you are using, but there's not always a filename. The `sass`
+command-line program defaults to the indented syntax but you can pass the
+`--scss` option to it if the input should be interpreted as SCSS syntax.
+Alternatively, you can use the `scss` command-line program which is exactly
+like the `sass` program but it defaults to assuming the syntax is SCSS.
+
### Encodings
When running on Ruby 1.9 and later, Sass is aware of the character encoding of documents
View
39 lib/sass/exec.rb
@@ -176,12 +176,15 @@ def handle_load_error(err)
# The `sass` executable.
class Sass < Generic
+ attr_reader :default_syntax
+
# @param args [Array<String>] The command-line arguments
def initialize(args)
super
@options[:for_engine] = {
:load_paths => ['.'] + (ENV['SASSPATH'] || '').split(File::PATH_SEPARATOR)
}
+ @default_syntax = :sass
end
protected
@@ -193,22 +196,29 @@ def set_opts(opts)
super
opts.banner = <<END
-Usage: sass [options] [INPUT] [OUTPUT]
+Usage: #{default_syntax} [options] [INPUT] [OUTPUT]
Description:
Converts SCSS or Sass files to CSS.
Options:
END
- opts.on('--scss',
- 'Use the CSS-superset SCSS syntax.') do
- @options[:for_engine][:syntax] = :scss
+ if @default_syntax == :sass
+ opts.on('--scss',
+ 'Use the CSS-superset SCSS syntax.') do
+ @options[:for_engine][:syntax] = :scss
+ end
+ else
+ opts.on('--sass',
+ 'Use the Indented syntax.') do
+ @options[:for_engine][:syntax] = :sass
+ end
end
opts.on('--watch', 'Watch files or directories for changes.',
'The location of the generated CSS can be set using a colon:',
- ' sass --watch input.sass:output.css',
- ' sass --watch input-dir:output-dir') do
+ " #{@default_syntax} --watch input.#{@default_syntax}:output.css",
+ " #{@default_syntax} --watch input-dir:output-dir") do
@options[:watch] = true
end
opts.on('--update', 'Compile files or directories to CSS.',
@@ -239,7 +249,7 @@ def set_opts(opts)
@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
+ 'Emit comments in the generated CSS indicating the corresponding source line.') do
@options[:for_engine][:line_numbers] = true
end
opts.on('-i', '--interactive',
@@ -290,6 +300,7 @@ def process_result
output = @options[:output]
@options[:for_engine][:syntax] ||= :scss if input.is_a?(File) && input.path =~ /\.scss$/
+ @options[:for_engine][:syntax] ||= @default_syntax
engine =
if input.is_a?(File) && !@options[:check_syntax]
::Sass::Engine.for_file(input.path, @options[:for_engine])
@@ -341,8 +352,8 @@ def watch_or_update
raise <<MSG if @args.empty?
What files should I watch? Did you mean something like:
- sass --watch input.sass:output.css
- sass --watch input-dir:output-dir
+ #{@default_syntax} --watch input.#{@default_syntax}:output.css
+ #{@default_syntax} --watch input-dir:output-dir
MSG
if !colon_path?(@args[0]) && probably_dest_dir?(@args[1])
@@ -355,7 +366,7 @@ def watch_or_update
end
raise <<MSG if err
File #{@args[1]} #{err}.
- Did you mean: sass #{flag} #{@args[0]}:#{@args[1]}
+ Did you mean: #{@default_syntax} #{flag} #{@args[0]}:#{@args[1]}
MSG
end
@@ -422,6 +433,14 @@ def probably_dest_dir?(path)
end
end
+ class Scss < Sass
+ # @param args [Array<String>] The command-line arguments
+ def initialize(args)
+ super
+ @default_syntax = :scss
+ end
+ end
+
# The `sass-convert` executable.
class SassConvert < Generic
# @param args [Array<String>] The command-line arguments

0 comments on commit 99e6fdf

Please sign in to comment.
Something went wrong with that request. Please try again.