Class: Fmt::Embed

Inherits:
Model
  • Object
show all
Defined in:
lib/fmt/models/embed.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#ast, #source, #urtext

AST Processors collapse

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #self?

Methods included from Matchable

#deconstruct, #deconstruct_keys

Constructor Details

This class inherits a constructor from Fmt::Model

Instance Attribute Details

#keyObject (readonly)

: Symbol – key for embed



7
8
9
# File 'lib/fmt/models/embed.rb', line 7

def key
  @key
end

#placeholderObject (readonly)

: String – placeholder for embed



8
9
10
# File 'lib/fmt/models/embed.rb', line 8

def placeholder
  @placeholder
end

#templateObject (readonly)

: Template



9
10
11
# File 'lib/fmt/models/embed.rb', line 9

def template
  @template
end

Instance Method Details

#on_embed(node) ⇒ Object

Processes an embed AST node



24
25
26
# File 'lib/fmt/models/embed.rb', line 24

def on_embed(node)
  process_all node.children
end

#on_key(node) ⇒ Object

Processes a key AST node



31
32
33
# File 'lib/fmt/models/embed.rb', line 31

def on_key(node)
  @key = node.children.first
end

#on_placeholder(node) ⇒ Object

Processes a placeholder AST node



38
39
40
# File 'lib/fmt/models/embed.rb', line 38

def on_placeholder(node)
  @placeholder = node.children.first
end

#on_template(node) ⇒ Object

Processes a template AST node



44
45
46
# File 'lib/fmt/models/embed.rb', line 44

def on_template(node)
  @template = Template.new(node)
end

#to_hObject

Hash representation of the model (required for pattern matching)



13
14
15
# File 'lib/fmt/models/embed.rb', line 13

def to_h
  super.merge placeholder: placeholder, template: template&.to_h
end