Class: OMF::Web::Widget::CodeWidget
- Inherits:
-
AbstractWidget
- Object
- Erector::Widget
- AbstractWidget
- OMF::Web::Widget::CodeWidget
- 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
-
#content_proxy ⇒ Object
Returns the value of attribute content_proxy.
Attributes inherited from AbstractWidget
#name, #opts, #widget_id, #widget_type
Class Method Summary collapse
Instance Method Summary collapse
-
#code_type(source) ⇒ Object
Return the language the code is written in.
- #collect_data_sources(ds_set) ⇒ Object
- #content ⇒ Object
- #content_id ⇒ Object
-
#initialize(opts) ⇒ CodeWidget
constructor
A new instance of CodeWidget.
- #mime_type ⇒ Object
- #title ⇒ Object
- #update_url ⇒ Object
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 |
# 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 @content_proxy = OMF::Web::ContentRepository.create_content_proxy_for(content_descr, opts) end |
Instance Attribute Details
#content_proxy ⇒ Object
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.(type, wdescr) return self.new(wdescr) end |
Instance Method Details
#code_type(source) ⇒ Object
Return the language the code is written in
80 81 82 83 84 85 86 87 88 |
# File 'lib/omf-web/widget/code_widget.rb', line 80 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
47 48 49 |
# File 'lib/omf-web/widget/code_widget.rb', line 47 def collect_data_sources(ds_set) ds_set end |
#content ⇒ Object
41 42 43 44 45 |
# File 'lib/omf-web/widget/code_widget.rb', line 41 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_id ⇒ Object
37 38 39 |
# File 'lib/omf-web/widget/code_widget.rb', line 37 def content_id @content_proxy.content_id end |
#mime_type ⇒ Object
29 30 31 |
# File 'lib/omf-web/widget/code_widget.rb', line 29 def mime_type @content_proxy.mime_type end |
#title ⇒ Object
25 26 27 |
# File 'lib/omf-web/widget/code_widget.rb', line 25 def title @content_proxy.name end |
#update_url ⇒ Object
33 34 35 |
# File 'lib/omf-web/widget/code_widget.rb', line 33 def update_url @content_proxy.content_url end |