import SASS partial over http instead of filesystem

后端 未结 1 1589
面向向阳花
面向向阳花 2021-02-06 16:57

I have a rails project where I want to dynamically create a sass file based on user variables, (as a way for users to customize the site). I need to @import that file into the s

1条回答
  •  孤独总比滥情好
    2021-02-06 17:31

    This documentation is discussing the fact that you can implement your own importer; HTTP is being used as an example. Fortunately, it is not too difficult to do so.

    Here, I've implemented a simple HTTP importer: https://gist.github.com/1111803

    It doesn't cache as aggressively as it could, and you should be aware that Sass will use it in addition to the filesystem to look for all imports (if you use a framework like Compass, there are many of these). If you need more performance, you should probably cache the failures in this case. Still, it seems to work in my testing.

    You can use it simply by requiring the sass_http.rb file and then adding it to the load path:

    require 'sass_http'
    Sass::Plugin.options[:load_paths] ||= []
    Sass::Plugin.options[:load_paths] << Sass::Importers::HTTP.new("http://stylesheets.example.com/")
    

    The path currently must refer to a directory (i.e. end in a slash). You should get all of the usual debugging information (with HTTP, rather than filesystem, paths).

    0 讨论(0)
提交回复
热议问题