Class: Bunto::Converters::Scss
- Inherits:
-
Converter
- Object
- Converter
- Bunto::Converters::Scss
- Defined in:
- lib/bunto/converters/scss.rb
Direct Known Subclasses
Constant Summary collapse
- BYTE_ORDER_MARK =
/^\xEF\xBB\xBF/
- SyntaxError =
Class.new(ArgumentError)
- ALLOWED_STYLES =
%w(nested expanded compact compressed).freeze
Instance Method Summary collapse
- #add_charset? ⇒ Boolean
- #allow_caching? ⇒ Boolean
- #bunto_sass_configuration ⇒ Object
- #convert(content) ⇒ Object
- #matches(ext) ⇒ Object
- #output_ext(ext) ⇒ Object
- #safe? ⇒ Boolean
- #sass_build_configuration_options(overrides) ⇒ Object
- #sass_configs ⇒ Object
- #sass_dir ⇒ Object
- #sass_dir_relative_to_site_source ⇒ Object
- #sass_load_paths ⇒ Object
- #sass_style ⇒ Object
- #syntax ⇒ Object
- #user_sass_load_paths ⇒ Object
Instance Method Details
#add_charset? ⇒ Boolean
89 90 91 |
# File 'lib/bunto/converters/scss.rb', line 89 def add_charset? !!bunto_sass_configuration["add_charset"] end |
#allow_caching? ⇒ Boolean
85 86 87 |
# File 'lib/bunto/converters/scss.rb', line 85 def allow_caching? !safe? end |
#bunto_sass_configuration ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/bunto/converters/scss.rb', line 29 def bunto_sass_configuration = @config["sass"] || {} unless ["style"].nil? ["style"] = ["style"].to_s.gsub(/\A:/, '').to_sym end end |
#convert(content) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/bunto/converters/scss.rb', line 101 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 |
#matches(ext) ⇒ Object
17 18 19 |
# File 'lib/bunto/converters/scss.rb', line 17 def matches(ext) ext =~ /^\.scss$/i end |
#output_ext(ext) ⇒ Object
21 22 23 |
# File 'lib/bunto/converters/scss.rb', line 21 def output_ext(ext) ".css" end |
#safe? ⇒ Boolean
25 26 27 |
# File 'lib/bunto/converters/scss.rb', line 25 def safe? !!@config["safe"] end |
#sass_build_configuration_options(overrides) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bunto/converters/scss.rb', line 37 def (overrides) if safe? { :load_paths => sass_load_paths, :syntax => syntax, :style => sass_style, :cache => false } else Bunto::Utils.symbolize_hash_keys( Bunto::Utils.deep_merge_hashes( bunto_sass_configuration, overrides ) ) end end |
#sass_configs ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/bunto/converters/scss.rb', line 93 def sass_configs ({ "syntax" => syntax, "cache" => allow_caching?, "load_paths" => sass_load_paths }) end |
#sass_dir ⇒ Object
59 60 61 62 |
# File 'lib/bunto/converters/scss.rb', line 59 def sass_dir return "_sass" if bunto_sass_configuration["sass_dir"].to_s.empty? bunto_sass_configuration["sass_dir"] end |
#sass_dir_relative_to_site_source ⇒ Object
73 74 75 |
# File 'lib/bunto/converters/scss.rb', line 73 def sass_dir_relative_to_site_source Bunto.sanitized_path(@config["source"], sass_dir) end |
#sass_load_paths ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/bunto/converters/scss.rb', line 77 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_style ⇒ Object
64 65 66 67 |
# File 'lib/bunto/converters/scss.rb', line 64 def sass_style style = bunto_sass_configuration.fetch("style", :compact) ALLOWED_STYLES.include?(style.to_s) ? style.to_sym : :compact end |
#syntax ⇒ Object
55 56 57 |
# File 'lib/bunto/converters/scss.rb', line 55 def syntax :scss end |
#user_sass_load_paths ⇒ Object
69 70 71 |
# File 'lib/bunto/converters/scss.rb', line 69 def user_sass_load_paths Array(bunto_sass_configuration["load_paths"]) end |