Class: OMF::Web::Widget::TextWidget

Inherits:
AbstractWidget show all
Defined in:
lib/omf-web/widget/text/text_widget.rb

Overview

Supports widgets which displays text with potentially other widgets embedded.

Instance Attribute Summary

Attributes inherited from AbstractWidget

#name, #opts, #widget_id, #widget_type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractWidget

#layout?, #title, #tools_menu, #widget_info

Constructor Details

#initialize(opts) ⇒ TextWidget

Returns a new instance of TextWidget.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/omf-web/widget/text/text_widget.rb', line 16

def initialize(opts)
  opts = opts.dup # not sure why we may need to this. Is this hash used anywhere else?
  super opts

  unless (content_descr = opts[:content])
    raise "Missing 'content' option in '#{opts.inspect}'"
  end
  # if content_descr.is_a? OMF::Web::ContentProxy
    # self.content_proxy = content_descr
  # else
    # #self.content_proxy = OMF::Web::ContentRepository[opts].load(content_descr)
    # self.content_proxy = OMF::Web::ContentRepository.create_content_proxy_for(content_descr, opts)
  # end
  self.content_proxy = OMF::Web::ContentRepository.create_content_proxy_for(content_descr, opts)
end

Class Method Details

.create_text_widget(type, wdescr) ⇒ Object



12
13
14
# File 'lib/omf-web/widget/text/text_widget.rb', line 12

def self.create_text_widget(type, wdescr)
  return self.new(wdescr)
end

Instance Method Details

#collect_data_sources(ds_set) ⇒ Object



63
64
65
66
67
# File 'lib/omf-web/widget/text/text_widget.rb', line 63

def collect_data_sources(ds_set)
  update()
  @widgets.each {|w| w.collect_data_sources(ds_set) }
  ds_set
end

#contentObject



36
37
38
39
40
41
# File 'lib/omf-web/widget/text/text_widget.rb', line 36

def content()
  update()
  OMF::Web::Theme.require 'text_renderer'
  @opts[:title] = @content.attributes[:title] || opts[:title]
  OMF::Web::Theme::TextRenderer.new(self, @content, @opts)
end

#content_idObject



55
56
57
# File 'lib/omf-web/widget/text/text_widget.rb', line 55

def content_id
  @content_proxy.content_url
end

#content_proxy=(content_proxy) ⇒ Object



32
33
34
# File 'lib/omf-web/widget/text/text_widget.rb', line 32

def content_proxy=(content_proxy)
  @content_proxy = content_proxy
end

#content_urlObject



51
52
53
# File 'lib/omf-web/widget/text/text_widget.rb', line 51

def content_url
  @content_proxy.content_url
end

#mime_typeObject



59
60
61
# File 'lib/omf-web/widget/text/text_widget.rb', line 59

def mime_type
  'text/html'
end

#updateObject



43
44
45
46
47
48
# File 'lib/omf-web/widget/text/text_widget.rb', line 43

def update()
  # Could avoid doing the next three steps every time if we would know if the
  # content in content_proxy has changed.
  @content = OMF::Web::Widget::Text::Maruku.format_content_proxy(@content_proxy)
  @widgets = @content.attributes[:widgets] || []
end