Class: Cecil::Node::Template

Inherits:
Cecil::Node show all
Defined in:
lib/cecil/node.rb

Overview

A node that has placeholders but does not yet have values or children. Created with backticks or #`(code_str)

When #with/#[] is called on the node, it will replace itself with a Literal or LiteralWithChildren

Instance Method Summary collapse

Methods inherited from Cecil::Node

#<<, #[]

Instance Method Details

#with(*positional_values, **named_values) ⇒ Object

See Also:



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/cecil/node.rb', line 371

def with(*positional_values, **named_values, &)
  src =
    case [positional_values, named_values, @placeholders]
    in [], {}, []
      @src
    in [], _, _
      Text.interpolate_named(@src, @placeholders, named_values)
    in _, {}, _
      Text.interpolate_positional(@src, @placeholders, positional_values)
    else
      raise "Method expects to be called with either named arguments or positional arguments but not both"
    end

  Literal
    .build(src:, parent:, &)
    .tap { builder.replace_node self, _1 }
end