asciidoctor-diagram-stupid 0.1.0

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: ae732d1f02393da28cab9b35c94ba718515bc85f
4
+ data.tar.gz: 2d08ed937a17552e02ca8c8b1887f0f02e2daa2a
5
+ SHA512:
6
+ metadata.gz: b8e307fb4506bb3fedbda2d6651e6f7a7684013725e566d6590d72b192736d1dcd8aec15dcf4f7e3ad8196cbd43dd56cabfc840d12ce4773f1379f663f98e669
7
+ data.tar.gz: 013cb7e8e12d3a5c16a2d1f6d8ae3d8918a58ac822a5457a33a837e416baf1dab04af287fbc68167fe302931e597d2b5cd2fbeff636e73a10f4219dcf1158171
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asciidoctor-diagram-stupid.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2016 Wilhem Barbier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # Asciidoctor::Diagram::Stupid
2
+
3
+ Generate Stupid diagrams with Asciidoctor.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "asciidoctor-diagram-stupid"
8
+ spec.version = Asciidoctor::Diagram::Stupid::VERSION
9
+ spec.authors = ["Wilhem Barbier"]
10
+ spec.email = ["nounoursheureux@openmailbox.org"]
11
+
12
+ spec.summary = %q{Generate Stupid diagrams with Asciidoctor.}
13
+ spec.description = %q{Generate Stupid diagrams with Asciidoctor.}
14
+ spec.homepage = "https://github.com/nounoursheureux/asciidoctor-diagram-stupid"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+
23
+ spec.add_runtime_dependency "asciidoctor", "~> 1.5"
24
+ spec.add_runtime_dependency "asciidoctor-diagram", "~> 1.5"
25
+ end
@@ -0,0 +1,103 @@
1
+ require 'asciidoctor' unless defined? ::Asciidoctor::VERSION
2
+ require 'asciidoctor-diagram' unless defined? ::Asciidoctor::Diagram::VERSION
3
+
4
+ module Asciidoctor
5
+ module Diagram
6
+ # @private
7
+ module CliGenerator
8
+ def generate_stdin(tool, format, code)
9
+ tool_name = File.basename(tool)
10
+
11
+ target_file = Tempfile.new([tool_name, ".#{format}"])
12
+ begin
13
+ target_file.close
14
+
15
+ opts = yield tool, target_file.path
16
+
17
+ generate(opts, target_file, :stdin_data => code)
18
+ ensure
19
+ target_file.unlink
20
+ end
21
+ end
22
+
23
+ def generate_file(tool, input_ext, output_ext, code)
24
+ tool_name = File.basename(tool)
25
+
26
+ source_file = Tempfile.new([tool_name, ".#{input_ext}"])
27
+ begin
28
+ File.write(source_file.path, code)
29
+
30
+ target_file = Tempfile.new([tool_name, ".#{output_ext}"])
31
+ begin
32
+ target_file.close
33
+
34
+ opts = yield tool, source_file.path, target_file.path
35
+
36
+ generate(opts, target_file)
37
+ ensure
38
+ target_file.unlink
39
+ end
40
+ ensure
41
+ source_file.unlink
42
+ end
43
+ end
44
+
45
+ def generate(opts, target_file, open3_opts = {})
46
+ case opts
47
+ when Array
48
+ args = opts
49
+ out_file = nil
50
+ when Hash
51
+ args = opts[:args]
52
+ out_file = opts[:out_file]
53
+ else
54
+ raise "Block passed to generate_file should return an Array or a Hash"
55
+ end
56
+
57
+ output = ::Asciidoctor::Diagram::Cli.run(*args, open3_opts)
58
+
59
+ raise "#{args[0]} failed: #{output}" unless File.exist?(out_file || target_file.path)
60
+
61
+ if out_file
62
+ File.rename(out_file, target_file.path)
63
+ end
64
+
65
+ File.binread(target_file.path)
66
+ end
67
+ end
68
+
69
+ # @private
70
+ module Stupid
71
+ include CliGenerator
72
+ include Which
73
+
74
+ def self.included(mod)
75
+ [:png, :svg].each do |f|
76
+ mod.register_format(f, :image) do |parent, source|
77
+ stupid(parent, source, f)
78
+ end
79
+ end
80
+ end
81
+
82
+ def stupid(parent, source, format)
83
+ generate_stdin(which(parent, 'stupid'), format.to_s, source.to_s) do |tool_path, output_path|
84
+ args = [tool_path, 'render', format.to_s, Platform.native_path(output_path).chomp(".#{format.to_s}")]
85
+ args
86
+ end
87
+ end
88
+ end
89
+
90
+ class StupidBlockProcessor < Extensions::DiagramBlockProcessor
91
+ include Stupid
92
+ end
93
+
94
+ class StupidBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
95
+ include Stupid
96
+ end
97
+ end
98
+ end
99
+
100
+ Asciidoctor::Extensions.register do
101
+ block Asciidoctor::Diagram::StupidBlockProcessor, :stupid
102
+ block_macro Asciidoctor::Diagram::StupidBlockMacroProcessor, :stupid
103
+ end
@@ -0,0 +1,7 @@
1
+ module Asciidoctor
2
+ module Diagram
3
+ module Stupid
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciidoctor-diagram-stupid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wilhem Barbier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-13 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: asciidoctor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: asciidoctor-diagram
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ description: Generate Stupid diagrams with Asciidoctor.
70
+ email:
71
+ - nounoursheureux@openmailbox.org
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - asciidoctor-diagram-stupid.gemspec
82
+ - lib/asciidoctor-diagram-stupid.rb
83
+ - lib/version.rb
84
+ homepage: https://github.com/nounoursheureux/asciidoctor-diagram-stupid
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.5.1
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Generate Stupid diagrams with Asciidoctor.
108
+ test_files: []