asciidoctor-diagram-cacoo 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 40b4cb0bdb3da01a484c1c04da271cc433f7e694
4
+ data.tar.gz: 6a2b98b103042457c5e42693ff4755587497731c
5
+ SHA512:
6
+ metadata.gz: 5f5d4a80c7737437c7e1f8b2e89541160d462419b7ecac5e105a631de0972e5029480f8224a89c296ac36aea297d645334d4fba2e93252ae4edfce35f6b2adf6
7
+ data.tar.gz: d96a410aa0826a5b265a22867f961006b39be1759d5e091ed687cda8d6ee5ef6e8c306f2e9574140101756bf4512c4e6c9d1fd9363983b1d4c2676dbd38df9b4
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asciidoctor-diagram-cacoo.gemspec
4
+ gemspec
5
+
6
+ gem 'asciidoctor-diagram'
7
+ gem 'nokogiri'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Hiroaki Nakamura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,90 @@
1
+ # Asciidoctor::Diagram::Cacoo
2
+
3
+ A ruby gem for adding support for [Cacoo](https://cacoo.com) to [asciidoctor-diagram](https://github.com/asciidoctor/asciidoctor-diagram).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'asciidoctor-diagram-cacoo'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install asciidoctor-diagram-cacoo
18
+
19
+ If you enable downloading contents.xml for cacoo diagrams, you also need to install [Nokogiri](http://www.nokogiri.org/)
20
+
21
+ $ gem install nokogiri
22
+
23
+ ## Usage
24
+
25
+ You must have an account of [Cacoo](https://cacoo.com/).
26
+ You need to create an Caoo API Key at [Cacoo API key config page](https://cacoo.com/profile/api)
27
+ and set it to the environment variable `CACOO_API_KEY`.
28
+
29
+ If you use bash or zsh, you can set it like the following:
30
+
31
+ ```
32
+ export CACOO_API_KEY=_Your_Cacoo_API_key_here_
33
+ ```
34
+
35
+
36
+ When you would like to add a diagram on Cacoo, you need the diagram ID.
37
+ For example, if your diagram's URL is https://cacoo.com/diagrams/f0MLos8tgXXxaTB,
38
+ your diagram ID is f0MLos8tgXXxaTBv.
39
+
40
+ You can add a diagram to your application, like the following example:
41
+
42
+ ```
43
+ acoo::f0MLos8tgXXxaTBv["png", alt="alt text"]
44
+ ```
45
+
46
+ ### Complete example
47
+
48
+ sample.adoc
49
+
50
+ ```
51
+ = asciidoctor-diagram-cacoo-example
52
+
53
+ :cacoo_does_download_contents: true
54
+ :cacoo_contents_xml_indent: 0
55
+
56
+ .DiagramBlockProcessor class diagram
57
+ cacoo::f0MLos8tgXXxaTBv["png", alt="DiagramBlockProcessor class"]
58
+
59
+ .Source class diagram
60
+ cacoo::Vsw9cGkj8bJjEBr6["png", alt="Source class"]
61
+ ```
62
+
63
+ Optional asciidoc document attributes
64
+
65
+ * cacoo_does_download_contents: true|false. Enable downlaoding contents.xml for cacoo diagrams. This is not needed to generate documents. However it is useful to see differences in diagrams if you put these contents.xml in version control system like git. Filename will be "cacoo-#{diagram_id}-contents.xml"
66
+ * cacoo_contents_xml_indent: 0|2|4|0. Number of spaces for indent of contents.xml.
67
+
68
+
69
+ You can load asciidoctor-diagram and asciidoctor-diagram-cacoo (this gem) with `-r` option
70
+ of asciidoctor like below:
71
+
72
+ ```
73
+ $ asciidoctor -r asciidoctor-diagram -r asciidoctor-diagram-cacoo sample.adoc
74
+ ```
75
+
76
+ For a complete example, see https://github.com/hnakamur/asciidoctor-diagram-cacoo-example
77
+
78
+ ## Credits
79
+
80
+ [asciidoctor-diagram-cacoo/extension.rb]( https://github.com/hnakamur/asciidoctor-diagram-cacoo/blob/master/lib/asciidoctor-diagram-cacoo/extension.rb ) is based on https://gist.github.com/pepijnve/2d4059db5d827462b5cd by [pepijnve (Pepijn Van Eeckhoudt)]( https://github.com/pepijnve ).
81
+
82
+ Thanks!
83
+
84
+ ## Contributing
85
+
86
+ 1. Fork it ( https://github.com/hnakamur/asciidoctor-diagram-cacoo/fork )
87
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
88
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
89
+ 4. Push to the branch (`git push origin my-new-feature`)
90
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
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-cacoo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "asciidoctor-diagram-cacoo"
8
+ spec.version = Asciidoctor::Diagram::Cacoo::VERSION
9
+ spec.authors = ["Hiroaki Nakamura"]
10
+ spec.email = ["hnakamur@gmail.com"]
11
+ spec.summary = %q{a ruby gem for asciidoctor-diagram to use Cacoo diagrams}
12
+ spec.description = %q{}
13
+ spec.homepage = "https://github.com/hnakamur/asciidoctor-diagram-cacoo"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,8 @@
1
+ require "asciidoctor-diagram-cacoo/version"
2
+ require 'asciidoctor/extensions'
3
+
4
+ Asciidoctor::Extensions.register do
5
+ require_relative 'asciidoctor-diagram-cacoo/extension'
6
+ block Asciidoctor::Diagram::CacooBlockProcessor, :cacoo
7
+ block_macro Asciidoctor::Diagram::CacooBlockMacroProcessor, :cacoo
8
+ end
@@ -0,0 +1,125 @@
1
+ require 'json'
2
+ require 'time'
3
+ require 'asciidoctor-diagram/extensions'
4
+ require 'nokogiri'
5
+
6
+ module Asciidoctor
7
+ module Diagram
8
+ # @private
9
+ module Cacoo
10
+ def self.get_diagram_metadata(diagram_id, api_key)
11
+ # NOTE: See API document at https://cacoo.com/lang/en/api and
12
+ # https://cacoo.com/lang/en/api_image
13
+ unless @diagrams
14
+ diagrams = JSON.parse(get("/api/v1/diagrams.json?apiKey=#{api_key}"))
15
+ @diagrams = diagrams['result'].each_with_object({}) { |d, h| h[d['diagramId']] = d }
16
+ end
17
+
18
+ @diagrams[diagram_id]
19
+ end
20
+
21
+ def self.get_diagram(diagram_id, api_key)
22
+ # NOTE: See API document at https://cacoo.com/lang/en/api and
23
+ # https://cacoo.com/lang/en/api_image
24
+ get("/api/v1/diagrams/#{diagram_id}.png?apiKey=#{api_key}")
25
+ end
26
+
27
+ def self.get_diagram_contents(diagram_id, api_key)
28
+ # NOTE: See API document at https://cacoo.com/lang/en/api and
29
+ # https://cacoo.com/lang/en/api_diagram_contents
30
+ get("/api/v1/diagrams/#{diagram_id}/contents.xml?returnValues=textStyle,shapeStyle,uid,position,point&apiKey=#{api_key}")
31
+ end
32
+
33
+ def self.save_diagram_contents(filename, contents, indent)
34
+ doc = Nokogiri.XML(contents)
35
+ File.open(filename, 'w') do |f|
36
+ f.write doc.to_xml(indent: indent)
37
+ end
38
+ end
39
+
40
+ def self.get(url)
41
+ https = Net::HTTP.new('cacoo.com', 443)
42
+ https.use_ssl = true
43
+ https.start do
44
+ response = https.get(url)
45
+ raise "Cacoo response status code was #{response.code}" if response.code != '200'
46
+ response.body
47
+ end
48
+ end
49
+
50
+ def self.included(mod)
51
+ mod.register_format(:png, :image) do |c, p|
52
+ if c.options[:does_download_contents]
53
+ contents = Cacoo.get_diagram_contents(c.diagram_id, c.api_key)
54
+ Cacoo.save_diagram_contents("#{c.image_name}-contents.xml", contents, c.options[:contents_xml_indent])
55
+ end
56
+ Cacoo.get_diagram(c.diagram_id, c.api_key)
57
+ end
58
+ end
59
+
60
+ class Source < Extensions::BasicSource
61
+ attr_accessor :diagram_id
62
+ attr_accessor :api_key
63
+ attr_accessor :options
64
+
65
+ def initialize(diagram_id, api_key, options)
66
+ @diagram_id = diagram_id
67
+ @api_key = api_key
68
+ @options = options
69
+ end
70
+
71
+ def image_name
72
+ "cacoo-#{diagram_id}"
73
+ end
74
+
75
+ def code
76
+ diagram_id
77
+ end
78
+
79
+ def should_process?(image_file, image_metadata)
80
+ Time.rfc2822(cacoo_metadata['updated']) < Time.rfc2822(image_metadata['updated'])
81
+ end
82
+
83
+ def create_image_metadata
84
+ { 'updated' => cacoo_metadata['updated'] }
85
+ end
86
+
87
+ def cacoo_metadata
88
+ Cacoo.get_diagram_metadata(diagram_id, api_key)
89
+ end
90
+ end
91
+ end
92
+
93
+ class CacooBlockProcessor < Extensions::DiagramBlockProcessor
94
+ include Cacoo
95
+
96
+ def create_source(parent, reader, attributes)
97
+ api_key = ENV['CACOO_API_KEY'] || parent.document.attributes['cacoo_api_key']
98
+ raise "Please specify your Cacoo API key using the CACOO_API_KEY environment variable or cacoo_api_key document attribute" unless api_key
99
+ does_download_contents = parent.document.attributes['cacoo_does_download_contents'] || false
100
+ contents_xml_indent = (parent.document.attributes['cacoo_contents_xml_indent'] || '2').to_i
101
+ options = {
102
+ does_download_contents: does_download_contents,
103
+ contents_xml_indent: contents_xml_indent
104
+ }
105
+ Cacoo::Source.new(reader.read.strip, api_key, options)
106
+ end
107
+ end
108
+
109
+ class CacooBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
110
+ include Cacoo
111
+
112
+ def create_source(parent, target, attributes)
113
+ api_key = ENV['CACOO_API_KEY'] || parent.document.attributes['cacoo_api_key']
114
+ raise "Please specify your Cacoo API key using the CACOO_API_KEY environment variable or cacoo_api_key document attribute" unless api_key
115
+ does_download_contents = parent.document.attributes['cacoo_does_download_contents'] || false
116
+ contents_xml_indent = (parent.document.attributes['cacoo_contents_xml_indent'] || '2').to_i
117
+ options = {
118
+ does_download_contents: does_download_contents,
119
+ contents_xml_indent: contents_xml_indent
120
+ }
121
+ Cacoo::Source.new(target.strip, api_key, options)
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,7 @@
1
+ module Asciidoctor
2
+ module Diagram
3
+ module Cacoo
4
+ VERSION = "0.2.2"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciidoctor-diagram-cacoo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Hiroaki Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ''
42
+ email:
43
+ - hnakamur@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - asciidoctor-diagram-cacoo.gemspec
54
+ - lib/asciidoctor-diagram-cacoo.rb
55
+ - lib/asciidoctor-diagram-cacoo/extension.rb
56
+ - lib/asciidoctor-diagram-cacoo/version.rb
57
+ homepage: https://github.com/hnakamur/asciidoctor-diagram-cacoo
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: a ruby gem for asciidoctor-diagram to use Cacoo diagrams
81
+ test_files: []