Sass mixin 递归;@include 循环 [英] Sass mixin recursion; @include loop

查看:94
本文介绍了Sass mixin 递归;@include 循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道是否可以恢复 Sass 的功能,以防止为防止 @include 递归而实施的错误修复"1?

Does anyone know if it's possible to revert Sass's functionality, to prevent the "bug-fix"1 that was implemented to prevent @include recursion?

消息是:

语法错误:发现一个@include 循环:<mixin-name>包含自身

这在中已修复"13.0.5,我不想(阅读:我不能)降级那么远.不幸的是,我对 Ruby 的了解不够,无法筛选源代码,虽然我正在花时间进行更改,但现在对我没有帮助.

This was "fixed"1 in 3.0.5, and I'd prefer not to (read: I can't) downgrade that far. I unfortunately don't know enough Ruby to go sifting through the source, and while I'm making time to change that, it doesn't help me now.

那么,是否可以2将此功能恢复到 3.0.5 之前的功能而无需降级?某处是否有重新补丁?我一直没能找到.

So, is it possible2 to revert this functionality to that of pre-3.0.5 without having to downgrade; is there a re-patch floating around somewhere? I haven't been able to find one.

虽然我现在自己回答了这个问题,但我仍然愿意接受更好的答案;具体来说,更便携的解决方案,因为现在 Sass 文件将在其他任何地方(3.0.5 之前的任何地方)

While I've answered this myself now, I'm still open to better answers; specifically, more portable solutions since now the Sass files will break anywhere else (anywhere that isn't pre-3.0.5)

<子>1 引号用于表示我认为这不是解决方法.我认为这是一个休息;不过,我会与负责的人一起解决这个问题.
2 我知道这是可能的,但我的意思是专门针对没有 Ruby 实践经验的人.我正在学习 Ruby!

1 Quotes used to indicate I don't think this is a fix. I think it is a break; I'll take that up with those responsible though.
2 I know its possible, but I mean specifically for someone with no practical experience with Ruby. I'm learning Ruby!

推荐答案

好的,有一个更简洁的方法来应用你的 hack:指南针 ">猴子补丁.

Okay, there's a cleaner way apply your hack: monkey-patching with Compass.

它可以让您安全地共享您的项目,其他人都可以在不修改他们自己的 SASS 编译器的情况下编译它.

It will let you share your project safely and everybody else will be able to compile it without modifying their own SASS compilers.

compass.rb 旁边创建 sass-visit-mixin-monkey-patch.rb 并从那里应用你的黑客:

Create sass-visit-mixin-monkey-patch.rb next to compass.rb and apply your hack from there:

class Sass::Tree::Visitors::Perform < Sass::Tree::Visitors::Base
  # Runs a mixin.
  def visit_mixin(node)
    #include_loop = true
    #handle_include_loop!(node) if @stack.any? {|e| e[:name] == node.name}
    include_loop = false

    @stack.push(:filename => node.filename, :line => node.line, :name => node.name)
    raise Sass::SyntaxError.new("Undefined mixin '#{node.name}'.") unless mixin = @environment.mixin(node.name)

    if node.children.any? && !mixin.has_content
      raise Sass::SyntaxError.new(%Q{Mixin "#{node.name}" does not accept a content block.})
    end

    args = node.args.map {|a| a.perform(@environment)}
    keywords = Sass::Util.map_hash(node.keywords) {|k, v| [k, v.perform(@environment)]}
    splat = node.splat.perform(@environment) if node.splat

    self.class.perform_arguments(mixin, args, keywords, splat) do |env|
      env.caller = Sass::Environment.new(@environment)
      env.content = node.children if node.has_children

      trace_node = Sass::Tree::TraceNode.from_node(node.name, node)
      with_environment(env) {trace_node.children = mixin.tree.map {|c| visit(c)}.flatten}
      trace_node
    end
  rescue Sass::SyntaxError => e
    unless include_loop
      e.modify_backtrace(:mixin => node.name, :line => node.line)
      e.add_backtrace(:line => node.line)
    end
    raise e
  ensure
    @stack.pop unless include_loop
  end
end

2)

需要 config.rb 中的猴子补丁:

# Enabling mixin recursion by applying a monkey patch to SASS compiler
require "./sass-visit-mixin-monkey-patch"

3)

使用 compass compile 编译您的项目.

这篇关于Sass mixin 递归;@include 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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