| Class | Texy::TextualElement |
| In: |
lib/texy/dom.rb
|
| Parent: | BlockElement |
This element represent one line of text.
Text represents content and children is array of InlineTagElement
| content | [R] |
# File lib/texy/dom.rb, line 189 def initialize(texy) super # is content HTML-safe? @html_safe = false @content = '' end
# File lib/texy/dom.rb, line 256 def append_child(child, inner_text = nil) self.content_type = [self.content_type, child.content_type].max if child.kind_of? InlineTagElement key_open = hash_key(child.content_type, true) key_close = hash_key(child.content_type, false) @children << [key_open, child] @children << [key_close, child] key_open + inner_text + key_close else key = hash_key child.content_type @children << [key, child] key end end
# File lib/texy/dom.rb, line 206 def safe_content(only_return = false) safe_content = if @html_safe then content else Html.html_chars(content) end if only_return safe_content else @html_safe = true @content = safe_content end end
# File lib/texy/dom.rb, line 201 def set_content(text, html_safe = false) @content = text; @html_safe = html_safe end
# File lib/texy/dom.rb, line 219 def generate_content set_content(safe_content(true)) unless @children.empty? @children.each do |(key, child)| child.behave_as_opening = Texy.hash_opening?(key) content.gsub! key, child.to_html end end content end
Generate unique HASH key - useful for freezing (folding) some substrings Key consist of unique chars \x19, \x1B-\x1E (noncontent) (or \x1F detect opening tag)
\x1A, \x1B-\x1E (with content)
# File lib/texy/dom.rb, line 245 def hash_key(content_type = nil, opening = false) border = if content_type == CONTENT_NONE then "\x19" else "\x1A" end border + if opening then "\x1F" else "" end + @children.size.to_s(4).tr('0123', "\x1B\x1C\x1D\x1E") + ## wtf? border end