Login  Register

Question How to Create new :image block in block processor (PlantUML, Graphviz)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Question How to Create new :image block in block processor (PlantUML, Graphviz)

Arnold Iterate
First, wow, thanks for Asciidoctor.
I haven't been this excited about writing documentation in years.  Been living in DocBook wonderland.
The new extension mechanism is fantastic.


I've created
  text --> plantuml --> image
and
  text --> GraphViz --> image
implemenations in Ruby.

The last piece to a working solution is getting the syntax correct in my BlockProcessor to replace text with an image.

Here is a stripped down version of what I'm trying to do, the very small test document and the error that I see:

Basic questions are:
1)  What is the correct syntax to create a new image block in a block processor to replace the existing text block?
2)  Can the source parameter be an empty list in the replacement block or does it have to look like an "image::x.png[]"
3) I've tried various things to set the attributes parameter to match the alt, width, height, and target attributes that you normally have in an image block.  Always blows up with error about the "include?" method.

Thanks in advance for any help.

#! /usr/bin/env jruby
require 'asciidoctor'
require 'asciidoctor/extensions'

class SpecialBlockProcessor < Asciidoctor::Extensions::BlockProcessor

  option :contexts, [:paragraph]
  option :content_model, :simple

  def process parent, reader, attributes
    Asciidoctor::Block.new(parent, :image,
          :source => ["image::an_image.png[]"],
          :attributes => {:alt=>"alt", :width=>50, :height=>60, :target=>"out.png"})
  end

end

Asciidoctor::Extensions.register do |document|
  block :special_block, SpecialBlockProcessor
end

Asciidoctor.render_file('test.adoc', :safe => 0, :to_dir => "/Published", :header_footer => true)


= Test Document

== Section

[special_block]
xxxx, yyyy


NoMethodError: undefined method `include?' for nil:NilClass
    image_uri at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/asciidoctor-0.1.4/lib/asciidoctor/abstract_node.rb:300
        image at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/asciidoctor-0.1.4/lib/asciidoctor/backends/html5.rb:873
       result at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/asciidoctor-0.1.4/lib/asciidoctor/backends/html5.rb:890
       render at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/asciidoctor-0.1.4/lib/asciidoctor/backends/base_template.rb:51
       render at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/asciidoctor-0.1.4/lib/asciidoctor/renderer.rb:137
       render at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/asciidoctor-0.1.4/lib/asciidoctor/abstract_block.rb:54
      content at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/asciidoctor-0.1.4/lib/asciidoctor/abstract_block.rb:60
          map at org/jruby/RubyArray.java:2409
      content at /usr/local/jruby-1.7.9/lib/ruby/gems/shared/gems/asciidoctor-0.1.4/lib/asciidoctor/abstract_block.rb:60





Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Question How to Create new :image block in block processor (PlantUML, Graphviz)

Arnold Iterate
Answering my own question...

This seems to satisfy the attributes for the image block.

 Asciidoctor::Block.new(parent, :image, :source => [], :attributes => {"alt"=>"test_image", 1=>"test_image", "width"=>"150", 2=>"150", "height"=>"180", 3=>"180", "target"=>"an_image.png"})