Recursion Sass mixin; @Include loop

Does anyone know if it is possible to return the Sass function to prevent the "bug fix" 1 that was implemented to prevent @include recursion?

Message:

Syntax error: An @include loop has been found: <mixin-name> includes itself

This was “fixed” 1 in 3.0.5 , and I would rather not read (read: I can't) lower it far. Unfortunately, I don’t know enough Ruby to sift through the source, and while I take the time to change this, it doesn’t help me right now.

So, is it possible 2 to return this functionality to version 3.0.5 without the need to downgrade; is there a floating patch somewhere? I could not find him.

Edit: While I myself answered this question, I am still open for better answers; in particular, more portable solutions, since now Sass files will be split somewhere else (somewhere not until 3.0.5)

<sub> 1 Quotations used to indicate that I do not think this is a correction. I think this is break; I will take this with those who are responsible. 2 I know that this is possible, but I mean specifically for those who do not have practical experience with Ruby. I am learning Ruby! Sub>

+1
source share
2 answers

Well, there’s a cleaner way to apply your hack: monkey fix with Compass .

This will allow you to safely share your project, and everyone else will be able to compile it without changing their own SASS compilers.

1)

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)

Require monkey patch from config.rb :

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

3)

Compile your project with compass compile .

+2
source

You know, I know Ruby enough to comment on a line or two;)

In .\lib\sass\tree\visitors\perform.rb : 249 just a comment:

 # 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 

IN:

 # 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 

Suddenly a rainbow of glorious recursion.

+1
source

All Articles