Class: OMF::Web::Widget::Text::Maruku::WidgetElement
- Inherits:
-
Base::LObject
- Object
- Base::LObject
- OMF::Web::Widget::Text::Maruku::WidgetElement
- Defined in:
- lib/omf-web/widget/text/maruku.rb
Constant Summary collapse
- @@pre_create_handlers =
[]
Instance Attribute Summary collapse
-
#widget ⇒ Object
readonly
Returns the value of attribute widget.
Class Method Summary collapse
- .create(wdescr) ⇒ Object
-
.on_pre_create(&block) ⇒ Object
Register a block which is presented with the widget description (Hash) we are about to create.
Instance Method Summary collapse
-
#initialize(wdescr) ⇒ WidgetElement
constructor
A new instance of WidgetElement.
- #node_type ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(wdescr) ⇒ WidgetElement
Returns a new instance of WidgetElement.
82 83 84 85 86 87 |
# File 'lib/omf-web/widget/text/maruku.rb', line 82 def initialize(wdescr) debug "Embedding widget - #{wdescr} " @wdescr = wdescr @widget = OMF::Web::Widget.(wdescr) debug "Created widget - #{@widget.class}" end |
Instance Attribute Details
#widget ⇒ Object (readonly)
Returns the value of attribute widget.
80 81 82 |
# File 'lib/omf-web/widget/text/maruku.rb', line 80 def @widget end |
Class Method Details
.create(wdescr) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/omf-web/widget/text/maruku.rb', line 69 def self.create(wdescr) wdescr = @@pre_create_handlers.reduce(wdescr) do |wd, block| wd2 = block.call(wd) unless wd2.is_a? Hash raise "Pre_create handler '#{block}' does not return hash, but '#{wd2}'" end wd2 end self.new(wdescr) end |
.on_pre_create(&block) ⇒ Object
Register a block which is presented with the widget description (Hash) we are about to create. The block is assumed to return a widget description.
65 66 67 |
# File 'lib/omf-web/widget/text/maruku.rb', line 65 def self.on_pre_create(&block) @@pre_create_handlers << block end |
Instance Method Details
#node_type ⇒ Object
107 108 109 |
# File 'lib/omf-web/widget/text/maruku.rb', line 107 def node_type :widget end |
#to_html ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/omf-web/widget/text/maruku.rb', line 89 def to_html content = @widget.content h = content.to_html klass = ['embedded'] if = @wdescr[:caption] || @widget.title if mt = @wdescr[:'mime-type'] klass << "embedded-#{mt.gsub('/', '-')}" end if ty = @wdescr[:type] klass << "embedded-#{ty.gsub('/', '-')}" end h += "<div class='caption'><span class='figure'>Figure: </span><span class='text'>#{}</span></div>" end root = ::REXML::Document.new("<div class='#{klass.join(' ')}'>#{h}</div>").root #puts "EMBEDDED >>> #{root}" root end |