出于某种原因,sass 没有运行我的自定义函数。环境变量已定义并可以像我在应用程序中使用它的其他 ruby 代码一样工作。我只是无法弄清楚为什么 SASS 没有运行该功能。我感谢您的帮助。
我在 application.rb 文件中有一个自定义的 sass 方法:
module Sass::Script::Functions
def get_env
Sass::Script::String.new(ENV['THE_ENV'])
end
declare :get_env, args: []
end
THE_ENV
环境变量在 application.yml 文件中定义。
在我的 application.sass 文件中,我有以下内容,它总是设置 #d71f2b:
$primary_color: #d71f2b
@if get_env() == "xyz"
$primary_color: #39A163
@else
$primary_color: #d71f2b
Gemfile.lock 包含:
sass (3.4.22)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)