Method: Sibu::DynamicStyle#compile

Defined in:
app/models/sibu/dynamic_style.rb

#compileObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/sibu/dynamic_style.rb', line 17

def compile
  if @styles_changed
    find_or_create_scss

    begin
      scss_file.write generate_css
      scss_file.flush
      scss_file.close
      css_file_path = scss_file_path.gsub('scss', 'css')
      File.rename(scss_file_path, css_file_path)
      site.update(style: File.new(css_file_path))
    rescue Exception => ex
        Rails.logger.error(ex)
    ensure
      File.delete(scss_file_path) if scss_file_path && File.exist?(scss_file_path)
      File.delete(css_file_path) if css_file_path && File.exist?(css_file_path)
    end
  end
end