Module: Toppings::Helper::SassConversionHelper

Extended by:
ActiveSupport::Concern
Included in:
Generators::SassFileGenerator
Defined in:
lib/toppings/helper/sass_conversion_helper.rb

Instance Method Summary collapse

Instance Method Details

#convert_to_scss(content) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/toppings/helper/sass_conversion_helper.rb', line 16

def convert_to_scss(content)
  init_tempfiles_for_conversion(content)

  # convert source content to the target format, placed in the target file
  # TODO: make conversion more dynamic, by allowing conversion from scss to sass too.
  ::Sass::Util.silence_sass_warnings do
    Sass::Exec::SassConvert.new(['-F', 'sass', '-T', 'scss', source_file, target_file]).parse
  end

  converted_content
ensure
  [source_file, target_file].each(&:close)
  [source_file, target_file].each(&:unlink)
end

#load_compass_pathsObject



50
51
52
# File 'lib/toppings/helper/sass_conversion_helper.rb', line 50

def load_compass_paths
  load_paths.merge Compass.configuration.sass_load_paths
end

#load_dependencies(file_path = nil) ⇒ Object



44
45
46
47
48
# File 'lib/toppings/helper/sass_conversion_helper.rb', line 44

def load_dependencies(file_path = nil)
  Toppings::SASS_DEPENDENCIES.each { |dep| require dep.to_s }
  load_compass_paths
  load_paths << file_path if file_path
end

#load_pathsObject



54
55
56
# File 'lib/toppings/helper/sass_conversion_helper.rb', line 54

def load_paths
  sass_engine_options[:load_paths] ||= Set.new
end

#sass_engine_optionsObject



58
59
60
# File 'lib/toppings/helper/sass_conversion_helper.rb', line 58

def sass_engine_options
  @sass_engine_options ||= {}
end

#valid_sass?(content, file_path = nil) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/toppings/helper/sass_conversion_helper.rb', line 31

def valid_sass?(content, file_path = nil)
  load_dependencies(file_path)

  ::Sass::Util.silence_sass_warnings do
    begin
      Sass::Engine.new(content, sass_engine_options.merge(check_syntax: true)).render
    rescue ::Sass::SyntaxError => e
      say e.message
      false
    end
  end
end