Class: Spider::SassCompiler

Inherits:
Object show all
Defined in:
lib/spiderfw/templates/resources/sass.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path) ⇒ SassCompiler

Returns a new instance of SassCompiler.



44
45
46
# File 'lib/spiderfw/templates/resources/sass.rb', line 44

def initialize(base_path)
    @base_path = base_path
end

Class Method Details

.optionsObject



40
41
42
# File 'lib/spiderfw/templates/resources/sass.rb', line 40

def self.options
    @options ||= {:load_paths => []}
end

Instance Method Details

#compile(src, dest) ⇒ Object



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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/spiderfw/templates/resources/sass.rb', line 48

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)

        sass_options = Compass.sass_engine_options.merge({
            :cache_location => File.join(work_dir, '.sass_cache')
        })
        # Spider.apps.each do |name, app|
        #     sass_options[:load_paths] << Sass::Importers::Filesystem.new(app.pub_path)
        # end
        Spider.app_paths.each do |path|
            sass_options[:load_paths] << SassAppImporter.new(path)
        end

        options = {
            :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 => sass_options,
            :css_filename => dest
        }
        
        config = Compass::Configuration::Data.new(:spider, options)
        Compass.add_project_configuration(config)
        compiler = Compass::Compiler.new(work_dir, File.dirname(src), File.dirname(dest), options)
        compiler.run
    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