Class: Mayu::VDOM::Descriptor::FactoryImpl
- Inherits:
-
Object
- Object
- Mayu::VDOM::Descriptor::FactoryImpl
- Extended by:
- T::Sig
- Includes:
- Interfaces::Descriptor::Factory
- Defined in:
- lib/mayu/vdom/descriptor.rb
Instance Method Summary collapse
- #add_comments_between_texts(descriptors) ⇒ Object
- #clean(children, parent_type: nil) ⇒ Object
- #comment ⇒ Object
- #or_text(obj) ⇒ Object
- #text(text_content) ⇒ Object
Instance Method Details
#add_comments_between_texts(descriptors) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mayu/vdom/descriptor.rb', line 56 def add_comments_between_texts(descriptors) comment = self.comment [*descriptors, nil].each_cons(2) .flat_map do |curr, succ| if curr&.text? && succ&.text? [curr, comment] else curr end end .compact end |
#clean(children, parent_type: nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mayu/vdom/descriptor.rb', line 40 def clean(children, parent_type: nil) cleaned = Array(children).flatten.select(&:itself) # Remove anything falsy if parent_type == :title # <title> can only have text children cleaned.map { text(_1) } else cleaned.map { or_text(_1) } end end |
#comment ⇒ Object
18 19 20 |
# File 'lib/mayu/vdom/descriptor.rb', line 18 def comment Descriptor[Interfaces::Descriptor::COMMENT] end |
#or_text(obj) ⇒ Object
31 32 33 |
# File 'lib/mayu/vdom/descriptor.rb', line 31 def or_text(obj) Descriptor === obj ? obj : text(obj.to_s) end |
#text(text_content) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/mayu/vdom/descriptor.rb', line 23 def text(text_content) Descriptor[ Interfaces::Descriptor::TEXT, text_content: text_content.to_s ] end |