Class: Jekyll::Converters::Scss

Inherits:
Converter
  • Object
show all
Defined in:
lib/jekyll/converters/scss.rb

Direct Known Subclasses

Sass

Constant Summary collapse

SyntaxError =
Class.new(ArgumentError)
ALLOWED_STYLES =
%w(nested expanded compact compressed).freeze

Instance Method Summary collapse

Instance Method Details

#allow_caching?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/jekyll/converters/scss.rb', line 82

def allow_caching?
  !safe?
end

#convert(content) ⇒ Object



94
95
96
97
98
# File 'lib/jekyll/converters/scss.rb', line 94

def convert(content)
  ::Sass.compile(content, sass_configs)
rescue ::Sass::SyntaxError => e
  raise SyntaxError.new("#{e.to_s} on line #{e.sass_line}")
end

#jekyll_sass_configurationObject



26
27
28
29
30
31
32
# File 'lib/jekyll/converters/scss.rb', line 26

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) ⇒ Object



14
15
16
# File 'lib/jekyll/converters/scss.rb', line 14

def matches(ext)
  ext =~ /^\.scss$/i
end

#output_ext(ext) ⇒ Object



18
19
20
# File 'lib/jekyll/converters/scss.rb', line 18

def output_ext(ext)
  ".css"
end

#safe?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/jekyll/converters/scss.rb', line 22

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

#sass_build_configuration_options(overrides) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jekyll/converters/scss.rb', line 34

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_configsObject



86
87
88
89
90
91
92
# File 'lib/jekyll/converters/scss.rb', line 86

def sass_configs
  sass_build_configuration_options({
    "syntax"     => syntax,
    "cache"      => allow_caching?,
    "load_paths" => sass_load_paths
  })
end

#sass_dirObject



56
57
58
59
# File 'lib/jekyll/converters/scss.rb', line 56

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_sourceObject



70
71
72
# File 'lib/jekyll/converters/scss.rb', line 70

def sass_dir_relative_to_site_source
  Jekyll.sanitized_path(@config["source"], sass_dir)
end

#sass_load_pathsObject



74
75
76
77
78
79
80
# File 'lib/jekyll/converters/scss.rb', line 74

def sass_load_paths
  if safe?
    [sass_dir_relative_to_site_source]
  else
    (user_sass_load_paths + [sass_dir_relative_to_site_source]).uniq
  end.select { |load_path| File.directory?(load_path) }
end

#sass_styleObject



61
62
63
64
# File 'lib/jekyll/converters/scss.rb', line 61

def sass_style
  style = jekyll_sass_configuration.fetch("style", :compact)
  ALLOWED_STYLES.include?(style.to_s) ? style.to_sym : :compact
end

#syntaxObject



52
53
54
# File 'lib/jekyll/converters/scss.rb', line 52

def syntax
  :scss
end

#user_sass_load_pathsObject



66
67
68
# File 'lib/jekyll/converters/scss.rb', line 66

def user_sass_load_paths
  Array(jekyll_sass_configuration["load_paths"])
end