How do I load extensions to the Sass::Script::Functions module?

感情迁移 提交于 2019-12-01 06:32:47

I just solved this to be able to use the compact function from Compass. Here's the whole scoop:

lib/sass.rb (created a new file)

# Compact function pulled from compass
module Sass::Script::Functions

  module CustomSassExtensions
    def compact(*args)
      sep = :comma
      if args.size == 1 && args.first.is_a?(Sass::Script::List)
        args = args.first.value
        sep = args.first.separator
      end
      Sass::Script::List.new(args.reject{|a| !a.to_bool}, sep)
    end
  end

  include CustomSassExtensions

end

config/application.rb (place this inside inside class Application right after the lines with config.autoload_paths)

if config.respond_to?(:sass)
  require "#{config.root}/lib/sass.rb"
end

Let me know if it worked for you.

I usually make a folder in lib named "sass" and in that folder create a sass-hex.rb (make sure this folder is on the load path)

module Sass::Script::Functions
  module SassHex
    def hex(decimal)
      Sass::Script::String.new("%02x" % decimal)
    end
  end
  include SassHex
end

All you should have todo is require the sass-hex.rb file I use this trick a lot in compass when extending sass.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!