Class: Riml::Compiler::GetCurlyBraceNameNodeVisitor

Inherits:
ScopedVisitor show all
Defined in:
lib/riml/compiler.rb

Instance Method Summary collapse

Methods inherited from Visitor

#initialize, #visit

Constructor Details

This class inherits a constructor from Riml::Compiler::Visitor

Instance Method Details

#compile(node) ⇒ Object



374
375
376
377
378
# File 'lib/riml/compiler.rb', line 374

def compile(node)
  set_modifier(node)
  node.compiled_output = node.scope_modifier
  node.compiled_output << compile_parts(node.variable.parts)
end

#compile_nested_parts(parts, root_part) ⇒ Object



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/riml/compiler.rb', line 401

def compile_nested_parts(parts, root_part)
  nested = 0
  parts.each do |part|
    if !part.respond_to?(:value)
      part.accept(visitor_for_node(part, :propagate_up_tree => false))
      root_part.compiled_output << "{#{part.compiled_output}"
      nested += 1
      next
    end
    if part.value.is_a?(Array)
      compile_nested_parts(part.value, root_part)
      next
    end
    part.value.accept(visitor_for_node(part.value, :propagate_up_tree => false))
    root_part.compiled_output << "{#{part.value.compiled_output}}#{'}' * nested}"
  end
end

#compile_parts(parts) ⇒ Object



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/riml/compiler.rb', line 380

def compile_parts(parts)
  parts.map do |part|
    if CurlyBraceVariable === part
      compile_parts(part)
    elsif part.nested?
      compile_nested_parts(part.value, part)
      part.compiled_output
    elsif part.interpolated?
      part.value.accept(visitor_for_node(part.value))
      "{#{part.value.compiled_output}}"
    else
      if String === part.value
        part.value
      else
        part.value.accept(visitor_for_node(part.value))
        "{#{part.value.compiled_output}}".gsub(/\n/, '')
      end
    end
  end.join
end