Sha256: 23513a632e5d58388ad5c3e68a3a99598c39634d2be22117950c533167f135c5

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'sass'
require 'jekyll/utils'

module Jekyll
  module Converters
    class Sass < Converter
      safe true
      priority :low

      def matches(ext)
        ext =~ /^\.s(a|c)ss$/i
      end

      def output_ext(ext)
        ".css"
      end

      def jekyll_sass_configuration
        options = @config["sass"] || {}
        unless options["style"].nil?
          options["style"] = options["style"].to_s.gsub(/\A:/, '').to_sym
        end
        options
      end

      def sass_build_configuration_options(overrides)
        Jekyll::Utils.symbolize_hash_keys(
          Jekyll::Utils.deep_merge_hashes(jekyll_sass_configuration, overrides)
        )
      end

      def syntax_type_of_content(content)
        if content.include?(";") || content.include?("{")
          :scss
        else
          :sass
        end
      end

      def sass_dir
        return "_sass" if jekyll_sass_configuration["sass_dir"].to_s.empty?
        jekyll_sass_configuration["sass_dir"]
      end

      def sass_dir_relative_to_site_source
        # FIXME: Not Windows-safe. Can only change once Jekyll 2.0.0 is out
        Jekyll.sanitized_path(@config["source"], sass_dir)
      end

      def allow_caching?
        !@config["safe"]
      end

      def sass_configs(content = "")
        sass_build_configuration_options({
          "syntax" => syntax_type_of_content(content),
          "cache"  => allow_caching?,
          "load_paths" => [sass_dir_relative_to_site_source]
        })
      end

      def convert(content)
        ::Sass.compile(content, sass_configs(content))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-sass-converter-1.0.0.rc4 lib/jekyll/converters/sass.rb