Class: Lapillus::MultiLineLabel
- Inherits:
-
Component
- Object
- RenderableComponent
- Component
- Lapillus::MultiLineLabel
- Defined in:
- lib/lapillus/components.rb
Instance Attribute Summary collapse
-
#html_content ⇒ Object
writeonly
Sets the attribute html_content.
Attributes inherited from Component
#behaviours, #identifier, #model, #property, #visible
Instance Method Summary collapse
- #add_text(element, text) ⇒ Object
- #render_to_element(element) ⇒ Object
- #split_breaks(text, parent) ⇒ Object
- #split_paragraphs(text, parent, re) ⇒ Object
Methods inherited from Component
#add_behaviour, #behaviour, #has_behaviour?, #has_model?, #has_parent?, #initialize, #parent, #path, #response_page=, #session, #value, #webpage
Methods inherited from RenderableComponent
#initialize, #on_render, #render_behaviours, #render_children, #render_component, #render_container, #visible?
Constructor Details
This class inherits a constructor from Lapillus::Component
Instance Attribute Details
#html_content=(value) ⇒ Object
Sets the attribute html_content
41 42 43 |
# File 'lib/lapillus/components.rb', line 41 def html_content=(value) @html_content = value end |
Instance Method Details
#add_text(element, text) ⇒ Object
75 76 77 78 79 |
# File 'lib/lapillus/components.rb', line 75 def add_text(element, text) text = REXML::Text.new(text) text.raw = html_content element.add_text(text) end |
#render_to_element(element) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/lapillus/components.rb', line 47 def render_to_element(element) element.text = "" re = Regexp.new('\n\n+') if((value =~ re)!=nil) split_paragraphs(value,element,re) else split_breaks(value,element) end end |
#split_breaks(text, parent) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/lapillus/components.rb', line 64 def split_breaks(text,parent) break_array = text.split(/\n/,-1) if !break_array.empty? add_text(parent, break_array[0]) break_array[1..-1].each { |elem| parent.add_element("br") add_text(parent, elem) } end end |
#split_paragraphs(text, parent, re) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/lapillus/components.rb', line 57 def split_paragraphs(text,parent,re) paragr_array = text.split(re) paragr_array.each { |elem| split_breaks(elem,parent.add_element("p")) } end |