问题描述
是否可以使用SASS在已编译的CSS文件上自动添加时间戳记?
eg
Is it possible to automatically add a timestamp on the compiled CSS file using SASS?e.g.
/* CSS Compiled on: {date+time} */
...compiled css goes here...
我检查了SASS和Compass文档,但没有提到这样的功能。
I've checked the SASS and Compass docs but no mention of such a feature.
推荐答案
我不知道有任何内置的SASS或指南针功能,但它不是太难添加一个自定义的Ruby函数来做。 (请参阅SASS中的一节请参阅。)
I don't know of any built-in SASS or Compass feature for this, but it's not too hard to add a custom Ruby function to do it. (See the section entitled "Adding Custom Functions" in the SASS reference here.)
使用Ruby函数的文件看起来像这样(我们称之为timestamp.rb):
Your file with the Ruby function would look like this (let's call it "timestamp.rb"):
module Sass::Script::Functions
def timestamp()
return Sass::Script::String.new(Time.now.to_s)
end
end
您可以在SASS文件中引用新的时间戳功能,如下所示:
And you'd reference the new timestamp function in your SASS file like this:
/*!
* CSS Compiled on: #{timestamp()}
*/
您只需要确保在编译SASS时加载timestamp.rb文件,无论是通过Compass配置文件,还是使用 - require
参数与SASS命令行。当所有的描述和完成,你应该得到如下输出:
You just need to make sure your "timestamp.rb" file is loaded when you compile the SASS, either by requiring it from a Compass config file, or by using the --require
parameter with the SASS command line. When all is said and done, you should get output like the following:
/*
* CSS Compiled on: 2012-10-23 08:53:03 -0400
*/
这篇关于将时间戳添加到编译的sass / scss的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!