Skip to content

Commit

Permalink
Add an 'scss' executable that is the same as the 'sass' executable bu…
Browse files Browse the repository at this point in the history
…t defaults to the scss syntax.
  • Loading branch information
chriseppstein committed Mar 23, 2011
1 parent 6c22a79 commit 99e6fdf
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
8 changes: 8 additions & 0 deletions 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!
5 changes: 5 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Expand Up @@ -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.
Expand Down
11 changes: 10 additions & 1 deletion doc-src/SASS_REFERENCE.md
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
39 changes: 29 additions & 10 deletions lib/sass/exec.rb
Expand Up @@ -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
Expand All @@ -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.',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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])
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 99e6fdf

Please sign in to comment.