TextClass

TextClass #

A TextClass is a class in which you will write your text. You should create your own sub-class for each part of your text.
A TextClass takes a Section as parameter.

class MyDatas(Datas)
  def __init__(self, json_in)
     super().__init__(json_in)

     self.my_job = "developer"

class MyText(TextClass):
  def __init__(self, section):
    super().__init__(section)

    self.text = (
      "Hello", self.nlg_syn("world", "everyone"), ".",

      self.nlg_tags('br'),

      self.nlg_tags('b', "Nice to meet you."),

      "I am a", self.my_job,  "."
    )

my_datas = MyDatas(input)

document = Document(my_datas)

my_section = document.new_section(html_elem_attr={"id": "mySection"})

MyText(my_section)

document.write()

# <div id="mySection">Hello everyone.<br> <b>Nice to meet you.</b> I am a developer.</div>

The TextClass is a powerful object which allows you to call all the NlgTools methods with self.
You can also access every attributes of your Datas class the same way.

The self.text write your text in the Section that was send as a parameter to your TextClass.
You can use it with strings, nested lists or tuples and it will do the same job as the TextVar object.
Don’t be afraid ! The ‘=’ operator is override, to enjoy all the possibility of it, you should do :

self.text = "Hello,"
self.text = "this is one sentence"
self.text = (
  "that I am",
  "writing here."
)

# Hello, this is one sentence that I am writing here.