module Sass

重写编译

Attributes

tests_running[RW]

@private

Public Class Methods

compile(contents, options = {}) click to toggle source

Compile a Sass or SCSS string to CSS. Defaults to SCSS.

@param contents [String] The contents of the Sass file. @param options [{Symbol => Object}] An options hash;

see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}

@raise [Sass::SyntaxError] if there’s an error in the document @raise [Encoding::UndefinedConversionError] if the source encoding

cannot be converted to UTF-8

@raise [ArgumentError] if the document uses an unknown encoding with ‘@charset`

# File lib/sassmagic/reset.rb, line 107
def self.compile(contents, options = {})
  options[:syntax] ||= :scss
  Engine.new(contents, options).to_css
end
compile_file(filename, *args) click to toggle source

Compile a file on disk to CSS.

@raise [Sass::SyntaxError] if there’s an error in the document @raise [Encoding::UndefinedConversionError] if the source encoding

cannot be converted to UTF-8

@raise [ArgumentError] if the document uses an unknown encoding with ‘@charset`

@overload compile_file(filename, options = {})

Return the compiled CSS rather than writing it to a file.

@param filename [String] The path to the Sass, SCSS, or CSS file on disk.
@param options [{Symbol => Object}] An options hash;
  see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
@return [String] The compiled CSS.

@overload compile_file(filename, css_filename, options = {})

Write the compiled CSS to a file.

@param filename [String] The path to the Sass, SCSS, or CSS file on disk.
@param options [{Symbol => Object}] An options hash;
  see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
@param css_filename [String] The location to which to write the compiled CSS.
# File lib/sassmagic/reset.rb, line 134
def self.compile_file(filename, *args)
  # debugger
  # puts filename
  # puts args
  # Sass.logger(filename, args)
  ctx = Sass::Script::Functions::EvaluationContext.new(Sass::Environment.new(nil, {}))

  # print 'star compile file:'
  #加载json
  # 获取设置
  $configHash = ctx.load_json(File.expand_path("#{File.dirname(filename)}/../config/sassmagic.json")) || {}
  # puts $configHash
  options = args.last.is_a?(Hash) ? args.pop : {}
  options = options.merge $configHash
  css_filename = args.shift
  #是否写入loadpath
  # debugger
  if (options.has_key?"remoteStylesheet") && (options["remoteStylesheet"] != '')
    RemoteSass.location = options["remoteStylesheet"]
  end
  #
  # debugger
  #是否需要额外输出样式表
  if options.has_key?"outputExtra"
    options["outputExtra"] ||= []
    options["outputExtra"].each {|v|

      extra_filename = css_filename + ''
      #替换成1x 2x 3x
      extra_filename.gsub!(/\.css$/ , '.'+v+'.css')
      if extra_filename
        options[:css_filename] = extra_filename
        options["multiple"] = v
        result = Sass::Engine.for_file(filename, options).render
        # open(css_filename, "w") {|css_file| css_file.write(result)}
        File.open(extra_filename, 'w') {|css_file| css_file.write(result)}
        nil
      else
        result = Sass::Engine.for_file(filename, options).render
        result
      end
    }
  end

  options.delete("multiple")
  # debugger
  result = Sass::Engine.for_file(filename, options).render
  if css_filename
    options[:css_filename] ||= css_filename
    open(css_filename, "w") {|css_file| css_file.write(result)}
    nil
  else
    result
  end
end
load_paths() click to toggle source

The global load paths for Sass files. This is meant for plugins and libraries to register the paths to their Sass stylesheets to that they may be ‘@imported`. This load path is used by every instance of {Sass::Engine}. They are lower-precedence than any load paths passed in via the {file:SASS_REFERENCE.md#load_paths-option `:load_paths` option}.

If the ‘SASS_PATH` environment variable is set, the initial value of `load_paths` will be initialized based on that. The variable should be a colon-separated list of path names (semicolon-separated on Windows).

Note that files on the global load path are never compiled to CSS themselves, even if they aren’t partials. They exist only to be imported.

@example

Sass.load_paths << File.dirname(__FILE__ + '/sass')

@return [Array<String, Pathname, Sass::Importers::Base>]

# File lib/sassmagic/reset.rb, line 89
def self.load_paths
  @load_paths ||= if ENV['SASS_PATH']
                    ENV['SASS_PATH'].split(Sass::Util.windows? ? ';' : ':')
                  else
                    []
                  end
end