app/models/site.rb
def compile_css(preview = false, custom_variables = {})
    # Generate the body with the specified site_settings
    env = Rails.application.assets
    template = site_template_name
    body = template_body(env, template, custom_variables)

    # Save the body in a temporal file to be accessible from sprockets
    filename = "#{id}_#{Time.now.to_i}.scss"
    folder = File.join(Rails.root, 'tmp', 'compiled_css')
    FileUtils.mkdir_p(folder) unless File.directory?(folder)
    scss_file_path = File.join(folder, filename)
    scss_file = File.open(scss_file_path, 'w') { |f| f.write(body); f.flush }

    # Recover the asset with sprockets (including dependencies on the own file)
    asset = asset_resource(env, filename, scss_file)
    source = asset_resource_compiled(asset)
    File.write(scss_file, source)

    # Move the temporal file to the final destination including the dependencies
    # with the values from site settings
    folder = Rails.root + 'public/stylesheets/front/sites'
    FileUtils.mkdir_p(folder) unless File.directory?(folder)
    File.rename(
      scss_file.path,
      "#{folder}/#{id}#{preview ? '-preview' : ''}.css")
  ensure
    scss_file.close
    File.delete(scss_file) if File.exist?(scss_file.path)
  end
# Compiles the site's css and creates a file with it
Compiles the site's css and creates a file with it
Compiles the site ' s css and creates a file with it
def compile_css(preview = false, custom_variables = {})
    env = Rails.application.assets
    template = site_template_name
    body = template_body(env, template, custom_variables)
    filename = "#{id}_#{Time.now.to_i}.scss"
    folder = File.join(Rails.root, 'tmp', 'compiled_css')
    FileUtils.mkdir_p(folder) unless File.directory?(folder)
    scss_file_path = File.join(folder, filename)
    scss_file = File.open(scss_file_path, 'w') { |f| f.write(body); f.flush }
    asset = asset_resource(env, filename, scss_file)
    source = asset_resource_compiled(asset)
    File.write(scss_file, source)
    folder = Rails.root + 'public/stylesheets/front/sites'
    FileUtils.mkdir_p(folder) unless File.directory?(folder)
    File.rename(
      scss_file.path,
      "#{folder}/#{id}#{preview ? '-preview' : ''}.css")
  ensure
    scss_file.close
    File.delete(scss_file) if File.exist?(scss_file.path)
  end
def compile_css ( preview = false , custom_variables = { } ) env = Rails . application . assets template = site_template_name body = template_body ( env , template , custom_variables ) filename = "#{id}_#{Time.now.to_i}.scss" folder = File . join ( Rails . root , 'tmp' , 'compiled_css' ) FileUtils . mkdir_p ( folder ) unless File . directory? ( folder ) scss_file_path = File . join ( folder , filename ) scss_file = File . open ( scss_file_path , 'w' ) { | f | f . write ( body ) ; f . flush } asset = asset_resource ( env , filename , scss_file ) source = asset_resource_compiled ( asset ) File . write ( scss_file , source ) folder = Rails . root + 'public/stylesheets/front/sites' FileUtils . mkdir_p ( folder ) unless File . directory? ( folder ) File . rename ( scss_file . path , "#{folder}/#{id}#{preview ? '-preview' : ''}.css" ) ensure scss_file . close File . delete ( scss_file ) if File . exist? ( scss_file . path ) end
Compiles the site's css and creates a file with it
Compiles the site ' s css and creates a file with it
# Generate the body with the specified site_settings # Save the body in a temporal file to be accessible from sprockets # Recover the asset with sprockets (including dependencies on the own file) # Move the temporal file to the final destination including the dependencies # with the values from site settings
preview
custom_variables