Skip to content

Instantly share code, notes, and snippets.

@deep-spaced
Created July 30, 2015 15:33
Show Gist options
  • Select an option

  • Save deep-spaced/301bf46425c389e96680 to your computer and use it in GitHub Desktop.

Select an option

Save deep-spaced/301bf46425c389e96680 to your computer and use it in GitHub Desktop.
# Used in a Stylesheet model to import other Stylesheet instances. Compile like this.
# The gsub is used to clean out NULL byte characters.
#
# class Stylesheet < ActiveRecord::Base
# include SassImporters
#
# def compile
# compressed_styles = SassC::Engine.new(self.sass.gsub("\u0000", ''), { :importer => DatabaseImporter }).render
# end
# end
module SassImporters
class DatabaseImporter < SassC::Importer
def imports(name, parent_path)
if ss = Stylesheets.find_by_name(name)
Import.new("#{ss.name}.scss", source: ss.sass)
elsif ss = Stylesheets.find_by_name("_#{name}")
Import.new("_#{ss.name}.scss", source: ss.sass)
else
nil
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment