mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
77 lines
2.8 KiB
Ruby
77 lines
2.8 KiB
Ruby
dir = File.dirname(__FILE__)
|
|
$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
|
|
|
|
require 'haml/version'
|
|
|
|
# The module that contains everything Sass-related:
|
|
#
|
|
# * {Sass::Engine} is the class used to render Sass/SCSS within Ruby code.
|
|
# * {Sass::Plugin} is interfaces with web frameworks (Rails and Merb in particular).
|
|
# * {Sass::SyntaxError} is raised when Sass encounters an error.
|
|
# * {Sass::CSS} handles conversion of CSS to Sass.
|
|
#
|
|
# Also see the {file:SASS_REFERENCE.md full Sass reference}.
|
|
module Sass
|
|
extend Haml::Version
|
|
|
|
# A string representing the version of Sass.
|
|
# A more fine-grained representation is available from {Haml::Version#version Sass.version}.
|
|
# @api public
|
|
VERSION = version[:string] unless defined?(Sass::VERSION)
|
|
|
|
# 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`
|
|
def self.compile(contents, options = {})
|
|
options[:syntax] ||= :scss
|
|
Engine.new(contents, options).to_css
|
|
end
|
|
|
|
# Compile a file on disk to CSS.
|
|
#
|
|
# @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}
|
|
# @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 [String] The compiled CSS.
|
|
#
|
|
# @overload compile_file(filename, css_filename, options = {})
|
|
# @param css_filename [String] The location to which to write the compiled CSS.
|
|
def self.compile_file(filename, *args)
|
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
|
css_filename ||= args.shift
|
|
if options[:syntax].nil? && filename =~ /\.(css|sass|scss)$/
|
|
options[:syntax] = $1.to_sym
|
|
end
|
|
options[:filename] = filename
|
|
options[:css_filename] = css_filename
|
|
result = Sass::Files.tree_for(filename, options).render
|
|
if css_filename
|
|
open(css_filename,"w") {|css_file| css_file.write(result) }
|
|
nil
|
|
else
|
|
result
|
|
end
|
|
end
|
|
end
|
|
|
|
require 'haml/util'
|
|
|
|
dir = Haml::Util.scope("vendor/fssm/lib")
|
|
$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
|
|
|
|
require 'sass/sass_file'
|
|
require 'sass/engine'
|
|
require 'sass/plugin' if defined?(Merb::Plugins)
|