Class: OMF::Web::Widget::Code::CodeWidget
- Inherits:
-
AbstractWidget
- Object
- Erector::Widget
- AbstractWidget
- OMF::Web::Widget::Code::CodeWidget
- Defined in:
- lib/omf-web/widget/UNUSED/code/code_widget.rb
Overview
Maintains the context for a particular code rendering within a specific session.
Constant Summary collapse
- @@codeType2mime =
{ :ruby => '/text/ruby', :xml => '/text/xml' }
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Attributes inherited from AbstractWidget
Instance Method Summary collapse
-
#code_type ⇒ Object
Return the language the code is written in.
- #content ⇒ Object
- #file_content ⇒ Object
-
#initialize(opts) ⇒ CodeWidget
constructor
A new instance of CodeWidget.
- #render_code ⇒ Object
Methods inherited from AbstractWidget
#collect_data_sources, #layout?, #mime_type, #title, #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.
16 17 18 |
# File 'lib/omf-web/widget/UNUSED/code/code_widget.rb', line 16 def initialize(opts) super opts end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/omf-web/widget/UNUSED/code/code_widget.rb', line 14 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
14 15 16 |
# File 'lib/omf-web/widget/UNUSED/code/code_widget.rb', line 14 def opts @opts end |
Instance Method Details
#code_type ⇒ Object
Return the language the code is written in
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/omf-web/widget/UNUSED/code/code_widget.rb', line 59 def code_type() path = @opts[:file] if path.end_with? '.rb' :ruby elsif path.end_with? '.xml' :xml else :text end end |
#content ⇒ Object
20 21 22 23 24 |
# File 'lib/omf-web/widget/UNUSED/code/code_widget.rb', line 20 def content() div :id => @base_id, :class => "oml_code CodeRay" do rawtext render_code end end |
#file_content ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/omf-web/widget/UNUSED/code/code_widget.rb', line 47 def file_content() ## HACK!!!! path = @opts[:file] if File.readable?(path) File.new(path).read else "Can't find #{path}" end end |
#render_code ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/omf-web/widget/UNUSED/code/code_widget.rb', line 32 def render_code() content = file_content type = code_type mimeType = @@codeType2mime[type] #puts ">>>>RENDER_CODE>> #{content.length}" begin tokens = CodeRay.scan content, type tokens.html :line_numbers => :inline, :tab_width => 2, :wrap => :div rescue Exception => ex puts ">>>> ERORRO: #{ex} #{ex.backtrace}" end #puts "<<<<< END OF RENDER CODE #{tokens.inspect}" end |