Skip to content

Commit

Permalink
Add support for Ditaa command line options
Browse files Browse the repository at this point in the history
  • Loading branch information
Pepijn Van Eeckhoudt authored and Pepijn Van Eeckhoudt committed Mar 26, 2015
1 parent 10554e3 commit 887a577
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
Binary file removed lib/asciidoctor-diagram-java-1.3.1.jar
Binary file not shown.
Binary file added lib/asciidoctor-diagram-java-1.3.2.jar
Binary file not shown.
11 changes: 7 additions & 4 deletions lib/asciidoctor-diagram/ditaa/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ module Ditaa
end
Java.classpath.concat JARS

def ditaa(code)
def ditaa(code, attrs)
Java.load

response = Java.send_request(
:url => '/ditaa',
:body => code
:body => code,
:headers => {
'X-Options' => attrs.delete('options') || ''
}
)

unless response[:code] == 200
Expand All @@ -26,8 +29,8 @@ def ditaa(code)
end

def self.included(mod)
mod.register_format(:png, :image) do |c|
ditaa(c.to_s)
mod.register_format(:png, :image) do |c, _, attrs|
ditaa(c.to_s, attrs)
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/asciidoctor-diagram/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ def create_image_block(parent, source, attributes, format, generator_info)
metadata = {}
end

image_attributes = attributes.dup

if !File.exists?(image_file) || source.should_process?(image_file, metadata)
params = IMAGE_PARAMS[format]

result = instance_exec(source, parent, &generator_info[:generator])
result = instance_exec(source, parent, image_attributes, &generator_info[:generator])

result.force_encoding(params[:encoding])

Expand All @@ -156,7 +158,6 @@ def create_image_block(parent, source, attributes, format, generator_info)
File.open(metadata_file, 'w') { |f| JSON.dump(metadata, f) }
end

image_attributes = attributes.dup
image_attributes['target'] = image_name

scale = image_attributes['scale']
Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor-diagram/util/java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Diagram
module Java
def self.classpath
@classpath ||= [
File.expand_path(File.join('../..', 'asciidoctor-diagram-java-1.3.1.jar'), File.dirname(__FILE__))
File.expand_path(File.join('../..', 'asciidoctor-diagram-java-1.3.2.jar'), File.dirname(__FILE__))
]
end

Expand Down
31 changes: 31 additions & 0 deletions spec/ditaa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,35 @@
expect(target).to match /\.png$/
expect(File.exists?(target)).to be true
end

it "should support ditaa options as attributes" do
doc = <<-eos
= Hello, PlantUML!
Doc Writer <[email protected]>
== First Section
[ditaa, options="--no-shadows --no-separation --round-corners --scale 2.5"]
----
+--------+ +-------+ +-------+
| | --+ ditaa +--> | |
| Text | +-------+ |diagram|
|Document| |!magic!| | |
| {d}| | | | |
+---+----+ +-------+ +-------+
: ^
| Lots of work |
+-------------------------+
----
eos

d = Asciidoctor.load StringIO.new(doc)
expect(d).to_not be_nil

b = d.find { |b| b.context == :image }
expect(b).to_not be_nil
target = b.attributes['target']
expect(target).to match /\.png$/
expect(File.exists?(target)).to be true
end
end

0 comments on commit 887a577

Please sign in to comment.