ruby - Sass: accessing the interpolated @debug and @warn messages from SassEngine#to_tree -


we use sass , scss @ codepen , i'm trying make super-fancy responding @warn , @debug directives in formatted array. don't want parse stdout, i'm trying capture results of debug , warn nodes via sass::engine#to_tree, method.

buuuut, we're running trouble. i'm sure i've not read lib long enough, jumpstarting help.

here's minimum test-case:

https://gist.github.com/tsabat/a91e8ebf9b8ec65f5c77

# ok, class bit sparse, encapsulates # logic empty lib, goal of conversion class cssservice    attr_reader :engine, :debugs, :warns, :extras    # markup - sass/csss   # syntax - 1 of [:sass, :scss]   # lib    - 1 of %w(bourbon compass)   def process(markup:, syntax:, lib: nil)     @markup = markup     @syntax = syntax     @lib    = lib     @debugs = []     @warns = []      # create sass::engine here, defaults     @engine = sassengine.new.get(syntax: syntax, markup: markup_with_imports)      output = rendered     write_non_render_nodes      output   end    private    def write_non_render_nodes     walk_nodes(engine.to_tree.children)      @extras = debugs + warns   end    # loop on nodes to debugnode , warnnode instances   def walk_nodes(nodes)     nodes.each |node|       push_node(node)       # program human       # recurse devine       walk_nodes(node.children) if node.has_children     end   end    # filter appropriate nodes   def push_node(node)     @debugs << message(node, :debug) if node.class == sass::tree::debugnode     @warns  << message(node, :warn) if node.class == sass::tree::warnnode   end    # cleanup   def message(child, type)     message = child.expr.to_sass.gsub!(/\a"|"\z/, '')     {type: type, message: message, line: child.line}   end    def rendered     engine.render   end    # can correct, interpolated output here if monkey-patch   # class   class sass::tree::visitors::perform     def visit_debug(node)       res = node.expr.perform(@environment)       if res.is_a?(sass::script::value::string)         res = res.value       else         res = res.to_sass       end       #ap res     end  end    # can ignored, codepen specific stuff   def markup_with_imports     return @markup if lib_empty?      "#{imports}\n#{@markup}"   end    def lib_empty?     @lib.nil? || @lib == ''   end    def imports     if @lib == 'bourbon'       (@syntax == :scss) ? "@import \"bourbon\";" : "@import \"bourbon\""     elsif @lib == 'compass'       (@syntax == :scss) ? "@import \"compass/css3\";" : "@import \"compass/css3\""     else       nil     end   end end 

basically, can @ nodes want, can't make them interpolate. example, debugnode filled with

"invalid color name: #{$color}, returning white instead.";

does not interpolate on expr.to_sass, here.

so, question remains. how can interpolated debug nodes?


Comments

Popular posts from this blog

shader - OpenGL Shadow Map -

stringtemplate - StringTemplate4 if conditional with length -