Class: Fmt::Template

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

Overview

Note:

Embeds are processed from inner to outer

Represents a formattable string

A Template is comprised of:

  1. embeds: Array – embedded templates

  2. pipelines

    Array – sets of Macros

Instance Attribute Summary collapse

Attributes inherited from Model

#ast, #source, #urtext

AST Processors collapse

Instance Method Summary collapse

Methods inherited from Model

#inspect, #self?

Methods included from Matchable

#deconstruct, #deconstruct_keys

Constructor Details

#initialize(ast) ⇒ Template

Constructor



17
18
19
20
21
# File 'lib/fmt/models/template.rb', line 17

def initialize(ast)
  @embeds = []
  @pipelines = []
  super
end

Instance Attribute Details

#embedsObject (readonly)

: Array



23
24
25
# File 'lib/fmt/models/template.rb', line 23

def embeds
  @embeds
end

#pipelinesObject (readonly)

: Array



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

def pipelines
  @pipelines
end

Instance Method Details

#on_embed(node) ⇒ Object



43
44
45
# File 'lib/fmt/models/template.rb', line 43

def on_embed(node)
  embeds << Embed.new(node)
end

#on_embeds(node) ⇒ Object



39
40
41
# File 'lib/fmt/models/template.rb', line 39

def on_embeds(node)
  process_all node.children
end

#on_pipeline(node) ⇒ Object



51
52
53
# File 'lib/fmt/models/template.rb', line 51

def on_pipeline(node)
  pipelines << Pipeline.new(node)
end

#on_pipelines(node) ⇒ Object



47
48
49
# File 'lib/fmt/models/template.rb', line 47

def on_pipelines(node)
  process_all node.children
end

#on_template(node) ⇒ Object

.….….….….….….….….….….….….….….….….….….. .….….….….….….….….….….….….….….….….….…..



35
36
37
# File 'lib/fmt/models/template.rb', line 35

def on_template(node)
  process_all node.children
end

#to_hObject



27
28
29
# File 'lib/fmt/models/template.rb', line 27

def to_h
  super.merge embeds: embeds.map(&:to_h), pipelines: pipelines.map(&:to_h)
end