通过http导入SASS部分而不是文件系统 [英] import SASS partial over http instead of filesystem

查看:141
本文介绍了通过http导入SASS部分而不是文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个rails项目,我想根据用户变量动态创建一个sass文件(作为用户自定义站点的一种方式)。我需要通过http将@import该文件导入到网站的主sass文件中,因为它是动态生成的,而不是实际写入文件系统。

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 site's main sass file through http, since it's dynamically generated and not actually written to the filesystem.

如何配置:load_paths指令告诉SASS通过http而不是通过文件系统查找该文件?

How do I configure the :load_paths directive to tell SASS to look for that file over http instead of through the filesystem?

文档说它有可能,但我在网上找不到任何例子。
http://sass-lang.com/docs/yardoc /file.SASS_REFERENCE.html#custom_importers

The documentation says it's possible but I can't find any examples online. http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#custom_importers

推荐答案

本文档讨论的是您可以实现自己的导入程序;以HTTP为例。幸运的是,这样做并不太难。

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.

在这里,我实现了一个简单的HTTP导入器: https://gist.github.com/1111803

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

它没有尽可能积极地缓存,你应该知道除了文件系统之外,Sass还会使用它来查找所有导入(如果你使用像Compass这样的框架,那么有很多这样的框架)。如果您需要更高的性能,则应该在这种情况下缓存故障。不过,它似乎在我的测试中有效。

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.

您可以通过要求 sass_http.rb 文件来使用它然后将其添加到加载路径:

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/")

当前路径必须引用目录(即以斜杠结尾)。您应该获得所有常用的调试信息(使用HTTP,而不是文件系统,路径)。

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).

这篇关于通过http导入SASS部分而不是文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆