asciidoctor-diagram 1.0.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f744fe34b44f3eac8a72f5c54ba81f4d0fca756
4
+ data.tar.gz: 410fa9e1683434a389503f90bfc251fff713bb7a
5
+ SHA512:
6
+ metadata.gz: 4ad7018fb8ee56d873eb041ba9511c5866668912183837061bfd9336ec88ab74536459ef90667f82e4fcccea447b250f725b3896890c57205a7b5596bef55ffc
7
+ data.tar.gz: e8b358410c6107145a70edd1e819595a46283fa6d177a8534ec65946ce1476217bd49894a169bd56d8967ae1227b2731cf84164fc64bf0467f7020a3a2c35006
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ *.iml
4
+ .idea
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - jruby
7
+
8
+ install:
9
+ - sudo apt-get install -qq graphviz
10
+ - bundle install
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asciidoctor-diagram.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Pepijn Van Eeckhoudt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.adoc ADDED
@@ -0,0 +1,75 @@
1
+ = Asciidoctor Diagram
2
+ Pepijn Van_Eeckhoudt
3
+
4
+ Asciidoctor Diagram is a set of extensions for http://asciidoctor.org[Asciidoctor], the Ruby-based AsciiDoc processor.
5
+ These extensions allow you to embed diagrams written using the http://plantuml.sourceforge.net[PlantUML] or Ditaa syntax inside your AsciiDoc documents.
6
+ The extension takes care of running the diagram processor to generate the images from the input text and insert them into the rendered document.
7
+
8
+ This gem was inspired by the https://code.google.com/p/asciidoc-plantuml/[AsciiDoc PlantUML filter] for AsciiDoc Python.
9
+
10
+ == Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'asciidoctor-diagram'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install asciidoctor-diagram
25
+
26
+ == Usage
27
+
28
+ === Enable the extensions
29
+
30
+ The diagram extensions consist of a set of http://asciidoctor.org/docs/user-manual/#extension-points[block processors for Asciidoctor].
31
+ In order to use extensions you should need to invoke Asciidoctor via the http://asciidoctor.org/docs/user-manual/#api[Ruby API].
32
+ In your script you can then either require one or more of the following files:
33
+
34
+ . `asciidoctor-diagram`: to enable all the diagramming extensions
35
+ . `asciidoctor-diagram/ditaa`: to enable the ditaa extension
36
+ . `asciidoctor-diagram/plantuml`: to enable the plantuml extension
37
+
38
+ Requiring one or more of these files will automatically register the extensions for all processed documents. If you need
39
+ more fine grained control over when the extensions are enabled or not, `asciidoctor-diagram/ditaa/extension` and `asciidoctor-diagram/plantuml/extension` can be used instead.
40
+ This loads the extensions themselves but does not register them.
41
+ You should then register the extensions yourself at the appropriate time using the `Asciidoctor::Extensions` API.
42
+
43
+ === Using the extensions
44
+
45
+ Once the extensions are enabled support for `plantuml` and/or `ditaa` blocks becomes available for your documents.
46
+ Detailed descriptions of the supported syntax inside these blocks is available on the http://plantuml.sourceforge.net/[PlantUML] and http://ditaa.sourceforge.net/[ditaa] websites.
47
+
48
+ At this point you can start adding diagrams to your application, like the following example:
49
+
50
+ ----
51
+ ["plantuml", "asciidoctor-diagram-classes", "png"]
52
+ ---------------------------------------------------------------------
53
+ class BlockProcessor
54
+ class DiagramBlock
55
+ class DitaaBlock
56
+ class PlantUmlBlock
57
+
58
+ BlockProcessor <|-- DiagramBlock
59
+ DiagramBlock <|-- DitaaBlock
60
+ DiagramBlock <|-- PlantUmlBlock
61
+ ---------------------------------------------------------------------
62
+ ----
63
+
64
+ The diagram blocks support the following attributes:
65
+
66
+ . `target` (or 2nd position): the basename of the file to generate. If not specified an auto-generated name will be used.
67
+ . `format` (or 3rd position): the output format. PlantUML blocks support `png`, `svg` and `txt`. Ditaa only supports `png`.
68
+
69
+ == Contributing
70
+
71
+ . Fork it
72
+ . Create your feature branch (`git checkout -b my-new-feature`)
73
+ . Commit your changes (`git commit -am 'Add some feature'`)
74
+ . Push to the branch (`git push origin my-new-feature`)
75
+ . Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems/package_task'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:test)
5
+
6
+ task :default => :test
7
+
8
+ ['ruby', 'java'].map do |platform|
9
+ $platform = platform
10
+ Gem::Specification.reset
11
+ spec = Gem::Specification.load('asciidoctor-diagram.gemspec')
12
+ Gem::PackageTask.new(spec) { |task| }
13
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'asciidoctor-diagram/version'
5
+
6
+ $platform ||= RUBY_PLATFORM[/java/] || 'ruby'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "asciidoctor-diagram"
10
+ spec.version = Asciidoctor::Diagram::VERSION
11
+ spec.authors = ["Pepijn Van Eeckhoudt"]
12
+ spec.email = ["pepijn@vaneeckhoudt.net"]
13
+ spec.description = %q{Asciidoctor diagramming extension}
14
+ spec.summary = %q{An extension for asciidoctor that adds support for UML diagram generation using PlantUML}
15
+ spec.platform = $platform
16
+ spec.homepage = "https://github.com/asciidoctor/asciidoctor-diagram"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+
28
+ spec.add_runtime_dependency "asciidoctor", "~> 0.1.4"
29
+ spec.add_runtime_dependency "rjb", "~> 1.4.9" unless $platform == 'java'
30
+ end
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,2 @@
1
+ require 'asciidoctor-diagram/ditaa'
2
+ require 'asciidoctor-diagram/plantuml'
@@ -0,0 +1,26 @@
1
+ module Asciidoctor
2
+ module Diagram
3
+ class BinaryIO
4
+ def initialize(string)
5
+ @data = string
6
+ @offset = 0
7
+ end
8
+
9
+ def read_uint32_be
10
+ uint32 = @data[@offset,4].unpack('N')[0]
11
+ @offset += 4
12
+ uint32
13
+ end
14
+
15
+ def read_string(length, encoding = Encoding::ASCII_8BIT)
16
+ str = @data[@offset,length]
17
+ @offset += length
18
+ str.force_encoding(encoding)
19
+ end
20
+
21
+ def skip(length)
22
+ @offset += length
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,111 @@
1
+ require 'asciidoctor/extensions'
2
+ require 'digest'
3
+ require 'json'
4
+ require_relative 'java'
5
+ require_relative 'png'
6
+ require_relative 'svg'
7
+
8
+ module Asciidoctor
9
+ module Diagram
10
+ BLOCK_TYPES = {
11
+ :svg => :image,
12
+ :png => :image,
13
+ :txt => :asciiart
14
+ }
15
+
16
+ IMAGE_PARAMS = {
17
+ :svg => {
18
+ :encoding => Encoding::UTF_8,
19
+ :decoder => SVG
20
+ },
21
+ :png => {
22
+ :encoding => Encoding::ASCII_8BIT,
23
+ :decoder => PNG
24
+ }
25
+ }
26
+
27
+ class DiagramBlock < Asciidoctor::Extensions::BlockProcessor
28
+ option :contexts, [:listing, :literal, :open]
29
+ option :content_model, :simple
30
+ option :pos_attrs, ['target', 'format']
31
+ option :default_attrs, {'format' => 'png'}
32
+
33
+ def process(parent, reader, attributes)
34
+ diagram_code = reader.lines.join
35
+ format = attributes.delete('format').to_sym
36
+
37
+ raise "#{name} does not support output format #{format}" unless allowed_formats.include?(format)
38
+
39
+ case BLOCK_TYPES[format]
40
+ when :image
41
+ create_image_block(parent, diagram_code, attributes, format)
42
+ when :asciiart
43
+ create_ascii_art_block(parent, diagram_code, attributes)
44
+ else
45
+ raise "Unsupported output format: #{format}"
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def create_image_block(parent, diagram_code, attributes, format)
52
+ target = attributes.delete('target')
53
+
54
+ checksum = code_checksum(diagram_code)
55
+
56
+ image_name = "#{target || checksum}.#{format}"
57
+ image_dir = File.expand_path(document.attributes['imagesdir'] || '', parent.document.attributes['docdir'])
58
+ image_file = File.expand_path(image_name, image_dir)
59
+ cache_file = File.expand_path("#{image_name}.cache", image_dir)
60
+
61
+ if File.exists? cache_file
62
+ metadata = File.open(cache_file, 'r') { |f| JSON.load f }
63
+ else
64
+ metadata = nil
65
+ end
66
+
67
+ unless File.exists?(image_file) && metadata && metadata['checksum'] == checksum
68
+ params = IMAGE_PARAMS[format]
69
+
70
+ result = generate_image(parent, diagram_code, format)
71
+
72
+ result.force_encoding(params[:encoding])
73
+
74
+ metadata = {'checksum' => checksum}
75
+ metadata['width'], metadata['height'] = params[:decoder].get_image_size(result)
76
+
77
+ File.open(image_file, 'w') { |f| f.write result }
78
+ File.open(cache_file, 'w') { |f| JSON.dump(metadata, f) }
79
+ end
80
+
81
+ attributes['target'] = image_name
82
+ attributes['width'] ||= metadata['width'] if metadata['width']
83
+ attributes['height'] ||= metadata['height'] if metadata['height']
84
+ attributes['alt'] ||= if (title_text = attributes['title'])
85
+ title_text
86
+ elsif target
87
+ (File.basename target, (File.extname target) || '').tr '_-', ' '
88
+ else
89
+ 'Diagram'
90
+ end
91
+
92
+ Asciidoctor::Block.new parent, :image, :content_model => :empty, :attributes => attributes
93
+ end
94
+
95
+ def create_ascii_art_block(parent, diagram_code, attributes)
96
+ attributes.delete('target')
97
+
98
+ result = generate_text(parent, diagram_code)
99
+
100
+ result.force_encoding(Encoding::UTF_8)
101
+ Asciidoctor::Block.new parent, :literal, :source => result, :attributes => attributes
102
+ end
103
+
104
+ def code_checksum(code)
105
+ md5 = Digest::MD5.new
106
+ md5 << code
107
+ md5.hexdigest
108
+ end
109
+ end
110
+ end
111
+ end