Class: Legate::Web::SassCompiler
- Inherits:
-
Object
- Object
- Legate::Web::SassCompiler
- Defined in:
- lib/legate/web/sass_compiler.rb
Overview
Sass compiler for the web interface
Class Method Summary collapse
Instance Method Summary collapse
- #compile_all ⇒ Object
- #compile_file(sass_file) ⇒ Object
-
#initialize ⇒ SassCompiler
constructor
A new instance of SassCompiler.
Constructor Details
#initialize ⇒ SassCompiler
Returns a new instance of SassCompiler.
17 18 19 20 |
# File 'lib/legate/web/sass_compiler.rb', line 17 def initialize @logger = Logger.new($stdout) @logger.level = Logger::INFO end |
Class Method Details
.compile_all ⇒ Object
12 13 14 |
# File 'lib/legate/web/sass_compiler.rb', line 12 def compile_all new.compile_all end |
Instance Method Details
#compile_all ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/legate/web/sass_compiler.rb', line 22 def compile_all @logger.info('Compiling Sass files...') # Ensure the output directory exists FileUtils.mkdir_p(output_dir) # Find all Sass files sass_files = Dir.glob(File.join(source_dir, '**', '*.scss')) sass_files.each do |sass_file| compile_file(sass_file) end @logger.info('Sass compilation complete!') end |
#compile_file(sass_file) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/legate/web/sass_compiler.rb', line 38 def compile_file(sass_file) relative_path = sass_file.sub("#{source_dir}/", '') output_file = File.join(output_dir, relative_path.sub('.scss', '.css')) # Ensure the output directory exists FileUtils.mkdir_p(File.dirname(output_file)) @logger.info("Compiling #{relative_path} to #{output_file.sub("#{output_dir}/", '')}") begin # Compile the Sass file input = File.read(sass_file) result = Sass.compile_string(input, style: 'expanded', load_paths: [File.dirname(sass_file)]) # Write the compiled CSS to the output file File.write(output_file, result.css) @logger.info("Successfully compiled #{relative_path}") rescue StandardError => e @logger.error("Error compiling #{relative_path}: #{e.}") @logger.error(e.backtrace.join("\n")) end end |