Class: Lapillus::MultiLineLabel

Inherits:
Component show all
Defined in:
lib/lapillus/components.rb

Instance Attribute Summary collapse

Attributes inherited from Component

#behaviours, #identifier, #model, #property, #visible

Instance Method Summary collapse

Methods inherited from Component

#add_behaviour, #behaviour, #has_behaviour?, #has_model?, #has_parent?, #initialize, #on_render, #parent, #path, #render_component, #response_page=, #session, #value, #visible?, #webpage

Constructor Details

This class inherits a constructor from Lapillus::Component

Instance Attribute Details

#html_content=(value) ⇒ Object

Sets the attribute html_content

Parameters:

  • value

    the value to set the attribute html_content to.



40
41
42
# File 'lib/lapillus/components.rb', line 40

def html_content=(value)
  @html_content = value
end

Instance Method Details

#add_text(element, text) ⇒ Object



74
75
76
77
78
# File 'lib/lapillus/components.rb', line 74

def add_text(element, text)
  text = REXML::Text.new(text)
  text.raw = html_content
  element.add_text(text)
end

#render_to_element(element) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/lapillus/components.rb', line 46

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



63
64
65
66
67
68
69
70
71
72
# File 'lib/lapillus/components.rb', line 63

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



56
57
58
59
60
61
# File 'lib/lapillus/components.rb', line 56

def split_paragraphs(text,parent,re)
  paragr_array = text.split(re)
  paragr_array.each { |elem|
    split_breaks(elem,parent.add_element("p"))
  }
end