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.
71 72 73 74 75 76 |
# File 'lib/omf-web/widget/text/maruku.rb', line 71 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.
69 70 71 |
# File 'lib/omf-web/widget/text/maruku.rb', line 69 def @widget end |
Class Method Details
.create(wdescr) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/omf-web/widget/text/maruku.rb', line 58 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.
54 55 56 |
# File 'lib/omf-web/widget/text/maruku.rb', line 54 def self.on_pre_create(&block) @@pre_create_handlers << block end |
Instance Method Details
#node_type ⇒ Object
96 97 98 |
# File 'lib/omf-web/widget/text/maruku.rb', line 96 def node_type :widget end |
#to_html ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/omf-web/widget/text/maruku.rb', line 78 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 |