Class: OMF::Web::Widget::CodeWidget

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

Overview

Maintains the context for a particular code rendering within a specific session.

Instance Attribute Summary collapse

Attributes inherited from AbstractWidget

#name, #opts, #widget_id, #widget_type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractWidget

#layout?, #tools_menu, #widget_info

Methods included from Common::Loggable

#_logger, #debug, #error, #fatal, #info, init_log, logger, set_environment, #warn

Constructor Details

#initialize(opts) ⇒ CodeWidget

Returns a new instance of CodeWidget.



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

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

Instance Attribute Details

#content_proxyObject

Returns the value of attribute content_proxy.



15
16
17
# File 'lib/omf-web/widget/code_widget.rb', line 15

def content_proxy
  @content_proxy
end

Class Method Details

.create_code_widget(type, wdescr) ⇒ Object



11
12
13
# File 'lib/omf-web/widget/code_widget.rb', line 11

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

Instance Method Details

#code_type(source) ⇒ Object

Return the language the code is written in



87
88
89
90
91
92
93
94
95
# File 'lib/omf-web/widget/code_widget.rb', line 87

def code_type(source)
  if source.end_with? '.rb'
    :ruby
  elsif source.end_with? '.xml'
    :xml
  else
    :text
  end
end

#collect_data_sources(ds_set) ⇒ Object



54
55
56
# File 'lib/omf-web/widget/code_widget.rb', line 54

def collect_data_sources(ds_set)
  ds_set
end

#contentObject



48
49
50
51
52
# File 'lib/omf-web/widget/code_widget.rb', line 48

def content()
  OMF::Web::Theme.require 'code_renderer'
  mode = @content_proxy.mime_type.split('/')[-1]
  OMF::Web::Theme::CodeRenderer.new(self, @content_proxy.content, mode, @opts)
end

#content_idObject



44
45
46
# File 'lib/omf-web/widget/code_widget.rb', line 44

def content_id
  @content_proxy.content_id
end

#mime_typeObject



35
36
37
# File 'lib/omf-web/widget/code_widget.rb', line 35

def mime_type
  @content_proxy.mime_type
end

#titleObject



31
32
33
# File 'lib/omf-web/widget/code_widget.rb', line 31

def title 
  @content_proxy.name
end

#update_urlObject



40
41
42
# File 'lib/omf-web/widget/code_widget.rb', line 40

def update_url
  @content_proxy.content_url
end