Module: CommonMarkerPluggable
- Defined in:
- lib/commonmarker-pluggable.rb,
lib/commonmarker-pluggable/version.rb
Overview
An extension to CommonMarker that adds plugin support
CommonMarkerPluggable is a shim that adds itself to CommonMarker and intercepts calls to ‘CommonMarker.render_doc`. After a document object is created, CommonMarkerPluggable calls the `.call` method of each plugin, passing the updated document object each time.
Constant Summary collapse
- VERSION =
"0.3.0"
Class Method Summary collapse
-
.plugins ⇒ Object
Collect the plugins.
Instance Method Summary collapse
-
#render_doc(text, options = :DEFAULT, extensions = []) ⇒ Object
Render the CommonMark document.
Class Method Details
.plugins ⇒ Object
Collect the plugins
19 20 21 22 23 24 |
# File 'lib/commonmarker-pluggable.rb', line 19 def self.plugins @plugins ||= CommonMarker::Plugin.constants.reduce(Array.new) do |total,c| next total unless (m = CommonMarker::Plugin.const_get(c)).is_a? Module total.push m end end |
Instance Method Details
#render_doc(text, options = :DEFAULT, extensions = []) ⇒ Object
Render the CommonMark document
29 30 31 32 33 34 35 |
# File 'lib/commonmarker-pluggable.rb', line 29 def render_doc(text, = :DEFAULT, extensions = []) doc = super(text, , extensions) CommonMarkerPluggable.plugins.each do |plugin| plugin.call doc end doc end |