Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Hi I am trying to run a very simple Ruby extension I have developed from CLI, but it don't work. Probably it is because of something related of Ruby and not Asciidoctor.
[source, ruby] .extension.rb ---- require 'asciidoctor' require 'asciidoctor/extensions' class EmojifyBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor def process parent, target, attributes size = (attributes.has_key? 'size') ? attributes['size'] : '24' source = %( <img height="#{size}" src="http://www.tortue.me/emoji/#{target}.png" width="#{size}" /> ) Asciidoctor::Block.new parent, :pass, :content_model => :raw, :source => source end end Asciidoctor::Extensions.register do |document| if document.basebackend? 'html' block_macro :emoji, EmojifyBlockMacro end end ---- Then when I run from the same directory of extension.rb next line: asciidoctor test.adoc -r ./extension.rb -o test.html Next exception id thrown: extension.rb:17:in `block in <top (required)>': undefined method `basebackend?' for #<Asciidoctor::Extensions::Registry:0x00000002777228> (NoMethodError) from /var/lib/gems/1.9.1/gems/asciidoctor-1.5.1/lib/asciidoctor/extensions.rb:507:in `call' from /var/lib/gems/1.9.1/gems/asciidoctor-1.5.1/lib/asciidoctor/extensions.rb:507:in `block in activate' from /var/lib/gems/1.9.1/gems/asciidoctor-1.5.1/lib/asciidoctor/extensions.rb:500:in `each' But I have seen that this method currently exists in document class, so what it is missing? Thanks. |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Administrator
|
Alex, This is happening because you are naming the block parameter document when it's really a registry. To access the document from the register block, you can either use the instance variable, @document: [source,ruby] ---- Asciidoctor::Extensions.register do if @document.basebackend? 'html' block_macro :emoji, EmojifyBlockMacro end end ---- We don't currently support document as an argument to the block, but we could if we check for an arity of 2. See https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/extensions.rb#L503. That would allow: [source,ruby] ---- Asciidoctor::Extensions.register do |registry, document| if document.basebackend? 'html' block_macro :emoji, EmojifyBlockMacro end end ---- Please note the second example is not currently supported. Cheers, -Dan On Wed, Oct 29, 2014 at 3:33 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote: Hi I am trying to run a very simple Ruby extension I have developed from CLI, but it don't work. Probably it is because of something related of Ruby and not Asciidoctor. ... [show rest of quote] Dan Allen | http://google.com/profiles/dan.j.allen |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Ok, I have followed (copy/paste) the example in http://asciidoctor.org/docs/user-manual/#block-macro-processor-example maybe we could improve it. Thank you so much for your time. 2014-10-29 23:25 GMT+01:00 mojavelinux [via Asciidoctor :: Discussion] <[hidden email]>:
... [show rest of quote] +----------------------------------------------------------+ Alex Soto Bueno - Computer Engineer www.lordofthejars.com +----------------------------------------------------------+ |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Administrator
|
The extension examples in the user manual came from the 0.1.4 release notes, so they likely all need reviewing. Sorry for misleading you. -Dan |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
No worries :) Sorry for disturbing you with my basic questions hehehe. 2014-10-30 8:51 GMT+01:00 mojavelinux [via Asciidoctor :: Discussion] <[hidden email]>:
+----------------------------------------------------------+ Alex Soto Bueno - Computer Engineer www.lordofthejars.com +----------------------------------------------------------+ |
Free forum by Nabble | Edit this page |