class Jekyll::Converters::Scss

Constants

ALLOWED_STYLES
BYTE_ORDER_MARK
SyntaxError

Public Instance Methods

add_charset?() click to toggle source
# File lib/jekyll/converters/scss.rb, line 105
def add_charset?
  !!jekyll_sass_configuration["add_charset"]
end
allow_caching?() click to toggle source
# File lib/jekyll/converters/scss.rb, line 101
def allow_caching?
  !safe?
end
convert(content) click to toggle source
# File lib/jekyll/converters/scss.rb, line 117
def convert(content)
  output = ::Sass.compile(content, sass_configs)
  replacement = add_charset? ? '@charset "UTF-8";' : ''
  output.sub(BYTE_ORDER_MARK, replacement)
rescue ::Sass::SyntaxError => e
  raise SyntaxError.new("#{e.to_s} on line #{e.sass_line}")
end
jekyll_sass_configuration() click to toggle source
# File lib/jekyll/converters/scss.rb, line 28
def jekyll_sass_configuration
  options = @config["sass"] || {}
  unless options["style"].nil?
    options["style"] = options["style"].to_s.gsub(/\A:/, '').to_sym
  end
  options
end
matches(ext) click to toggle source
# File lib/jekyll/converters/scss.rb, line 16
def matches(ext)
  ext =~ /^\.scss$/
end
output_ext(ext) click to toggle source
# File lib/jekyll/converters/scss.rb, line 20
def output_ext(ext)
  ".css"
end
safe?() click to toggle source
# File lib/jekyll/converters/scss.rb, line 24
def safe?
  !!@config["safe"]
end
sass_build_configuration_options(overrides) click to toggle source
# File lib/jekyll/converters/scss.rb, line 36
def sass_build_configuration_options(overrides)
  if safe?
    {
      :load_paths => sass_load_paths,
      :syntax     => syntax,
      :style      => sass_style,
      :cache      => false
    }
  else
    Jekyll::Utils.symbolize_hash_keys(
      Jekyll::Utils.deep_merge_hashes(
        jekyll_sass_configuration,
        overrides
      )
    )
  end
end
sass_configs() click to toggle source
# File lib/jekyll/converters/scss.rb, line 109
def sass_configs
  sass_build_configuration_options({
    "syntax"     => syntax,
    "cache"      => allow_caching?,
    "load_paths" => sass_load_paths
  })
end
sass_dir() click to toggle source
# File lib/jekyll/converters/scss.rb, line 58
def sass_dir
  return "_sass" if jekyll_sass_configuration["sass_dir"].to_s.empty?
  jekyll_sass_configuration["sass_dir"]
end
sass_dir_relative_to_site_source() click to toggle source
# File lib/jekyll/converters/scss.rb, line 72
def sass_dir_relative_to_site_source
  Jekyll.sanitized_path(site_source, sass_dir)
end
sass_load_paths() click to toggle source
# File lib/jekyll/converters/scss.rb, line 76
def sass_load_paths
  paths = user_sass_load_paths + [sass_dir_relative_to_site_source]

  if safe?
    # Sanitize paths to prevent any attack vectors (.e.g. `/**/*`)
    paths.map! { |path| Jekyll.sanitized_path(site_source, path) }
  end

  # Expand file globs (e.g. `node_modules/*/node_modules` )
  Dir.chdir(site_source) do
    paths = paths.map { |path| Dir.glob(path) }.flatten.uniq

    paths.map! do |path|
      if safe?
        # Sanitize again in case globbing was able to do something crazy.
        Jekyll.sanitized_path(site_source, path)
      else
        File.expand_path(path)
      end
    end
  end

  paths.select { |path| File.directory?(path) }
end
sass_style() click to toggle source
# File lib/jekyll/converters/scss.rb, line 63
def sass_style
  style = jekyll_sass_configuration.fetch("style", :compact)
  ALLOWED_STYLES.include?(style.to_s) ? style.to_sym : :compact
end
syntax() click to toggle source
# File lib/jekyll/converters/scss.rb, line 54
def syntax
  :scss
end
user_sass_load_paths() click to toggle source
# File lib/jekyll/converters/scss.rb, line 68
def user_sass_load_paths
  Array(jekyll_sass_configuration["load_paths"])
end

Private Instance Methods

site_source() click to toggle source
# File lib/jekyll/converters/scss.rb, line 126
def site_source
  @site_source ||= File.expand_path(@config["source"]).freeze
end