# using macros and replacement.
#
# A macro is represented as a string identifier like `%MACRO%` in the template
-# string. Using `TemplateString`, macros can be replaced by any `Streamable` data:
+# string. Using `TemplateString`, macros can be replaced by any `Writable` data:
#
# var tpl = new TemplateString("Hello %NAME%!")
# tpl.replace("NAME", "Dave")
# Loads the template file contents.
private fun load_template_file(tpl_file: String): String do
- var file = new IFStream.open(tpl_file)
+ var file = new FileReader.open(tpl_file)
var text = file.read_all
file.close
return text
# Also build `self` template parts using original template text.
private fun parse do
var text = tpl_text
- var chars = text.chars
var pos = 0
var out = new FlatBuffer
var start_pos: Int
# var tpl = new TemplateString("Hello %NAME%!")
# tpl.replace("NAME", "Dave")
# assert tpl.write_to_string == "Hello Dave!"
- fun replace(name: String, replacement: Streamable) do
+ fun replace(name: String, replacement: Writable) do
assert has_macro(name)
for macro in macros[name] do
macro.replacement = replacement
# tpl.replace("FIRSTNAME", "Corben")
# tpl.replace("LASTNAME", "Dallas")
# for name, rep in tpl do assert rep != null
- fun iterator: MapIterator[String, nullable Streamable] do
+ fun iterator: MapIterator[String, nullable Writable] do
return new TemplateStringIterator(self)
end
end
var end_pos: Int
# Macro replacement if any.
- var replacement: nullable Streamable = null
+ var replacement: nullable Writable = null
# Does `self` already have a `replacement`?
fun is_replaced: Bool do return replacement != null
end
private class TemplateStringIterator
- super MapIterator[String, nullable Streamable]
+ super MapIterator[String, nullable Writable]
var subject: TemplateString
var key_it: Iterator[String] is noinit