Class: Spider::SassCompiler
- Defined in:
- lib/spiderfw/templates/resources/sass.rb
Instance Method Summary collapse
- #compile(src, dest) ⇒ Object
-
#initialize(base_path) ⇒ SassCompiler
constructor
A new instance of SassCompiler.
Constructor Details
#initialize(base_path) ⇒ SassCompiler
Returns a new instance of SassCompiler.
25 26 27 |
# File 'lib/spiderfw/templates/resources/sass.rb', line 25 def initialize(base_path) @base_path = base_path end |
Instance Method Details
#compile(src, dest) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/spiderfw/templates/resources/sass.rb', line 29 def compile(src, dest) use_compass = false if Spider.conf.get('css.sass.use_compass') begin require 'compass' use_compass = true rescue LoadError => exc Spider.logger.debug(exc) Spider.logger.debug("Compass not found. Please install 'compass' gem") end end if use_compass work_dir = FileUtils.mkdir_p(File.join(Spider.paths[:tmp], 'sass')) src_dir = File.dirname(src) src_dir = src_dir # dest_dir = File.dirname(dest) = { :project_path => @base_path, :css_dir => 'css', :sass_dir => 'sass', # :fonts_path => src_dir, # :images_path => src_dir, :fonts_dir => 'fonts', :images_dir => 'img', :javascripts_dir => 'js', :relative_assets => true, :line_comments => Spider.runmode == 'devel' ? true : false, :sass => Compass..merge({ :cache_location => File.join(work_dir, '.sass_cache') }), :css_filename => dest } config = Compass::Configuration::Data.new(:spider, ) Compass.add_project_configuration(config) compiler = Compass::Compiler.new(work_dir, File.dirname(src), File.dirname(dest), ) compiler.compile(src, dest) if compiler.out_of_date? else engine = Sass::Engine.for_file(src, {}) output = engine.render File.open(dest, 'w') do |f| f.write "/* This file is autogenerated; do not edit directly (edit #{src} instead) */\n\n" f.write output end end end |