Class: Fmt::EmbedParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/fmt/parsers/embed_parser.rb

Overview

Parses embeds from a string and builds an AST (Abstract Syntax Tree)

Constant Summary

Constants inherited from Parser

Parser::Cache

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

esc

Constructor Details

#initialize(urtext = "", key:, placeholder:) ⇒ EmbedParser

Constructor



12
13
14
15
16
# File 'lib/fmt/parsers/embed_parser.rb', line 12

def initialize(urtext = "", key:, placeholder:)
  @urtext = urtext.to_s.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "?")
  @key = key
  @placeholder = placeholder
end

Instance Attribute Details

#keyObject (readonly)

: Symbol – key for embed



19
20
21
# File 'lib/fmt/parsers/embed_parser.rb', line 19

def key
  @key
end

#placeholderObject (readonly)

: String – placeholder for embed



20
21
22
# File 'lib/fmt/parsers/embed_parser.rb', line 20

def placeholder
  @placeholder
end

#urtextObject (readonly)

: String – original source code



18
19
20
# File 'lib/fmt/parsers/embed_parser.rb', line 18

def urtext
  @urtext
end

Instance Method Details

#parseObject

Parses the urtext (original source code)



24
25
26
# File 'lib/fmt/parsers/embed_parser.rb', line 24

def parse
  cache(urtext) { super }
end