asciidoctor-diagram-office 0.1.1

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: 2a2eec6d98bfb52e75ee34bf14e2ba4f95f5d2dc
4
+ data.tar.gz: 46519dbfa6d0e4d709cf4cc760fea1f97065e506
5
+ SHA512:
6
+ metadata.gz: d4d9bb9cf57eb0d4cb926a6cbf8e87388b02df9cd356d336b97730fddf9bf45e7ffe05bc30993e74ebc4d719c1fb205f6f17ff05cc56a0c5b4b1fb507cd17fe0
7
+ data.tar.gz: 0f35a6099deca0f41a03ab736fde1a9f3ec0c3712ad9d48ae6043178eba9ee32e5344d65222e8df348d3f35282ebf1b64f5ff4bba2fe6e3719bf7bb3941ecbf5
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Hiroyuki Wada
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.
22
+
@@ -0,0 +1,24 @@
1
+ require 'rake/clean'
2
+
3
+ default_tasks = []
4
+
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.rspec_opts = ['-c']
9
+ end
10
+ default_tasks << :spec
11
+ rescue LoadError
12
+ end
13
+
14
+ begin
15
+ require 'bundler/gem_tasks'
16
+ default_tasks << :build
17
+ rescue LoadError
18
+ warn 'asciidoctor-diagram-office: Bundler is required to build this gem.
19
+ You can install Bundler using `gem install` command:
20
+
21
+ $ [sudo] gem install bundler' + %(\n\n)
22
+ end
23
+
24
+ task :default => default_tasks unless default_tasks.empty?
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('lib/asciidoctor-diagram-office/version',
3
+ File.dirname(__FILE__))
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'asciidoctor-diagram-office'
7
+ s.version = Asciidoctor::Diagram::Office::VERSION
8
+ s.date = '2018-03-22'
9
+ s.summary = "Asciidoctor diagram extension, with support for Office documents"
10
+ s.description = "An Asciidoctor extension to convert office document to SVG or PNG"
11
+ s.authors = ["Hiroyuki Wada"]
12
+ s.email = 'wadahiro@gmail.com'
13
+ s.files = `git ls-files -z`.split("\x0")
14
+ s.homepage =
15
+ 'https://github.com/wadahiro/asciidoctor-diagram-office'
16
+ s.license = 'MIT'
17
+
18
+ s.add_dependency 'asciidoctor-diagram', '~> 1.5'
19
+ end
@@ -0,0 +1,9 @@
1
+ require "asciidoctor-diagram-office/version"
2
+ require 'asciidoctor/extensions'
3
+
4
+ Asciidoctor::Extensions.register do
5
+ require_relative 'asciidoctor-diagram-office/extension'
6
+
7
+ block Asciidoctor::Diagram::OfficeBlockProcessor, :office
8
+ block_macro Asciidoctor::Diagram::OfficeBlockMacroProcessor, :office
9
+ end
@@ -0,0 +1,115 @@
1
+ require 'asciidoctor-diagram/extensions'
2
+ require 'asciidoctor-diagram/util/cli'
3
+ require 'asciidoctor-diagram/util/cli_generator'
4
+ require 'asciidoctor-diagram/util/platform'
5
+ require 'asciidoctor-diagram/util/which'
6
+
7
+ module Asciidoctor
8
+ module Diagram
9
+ # @private
10
+ module OfficeServer
11
+ def self.listen
12
+ unless defined?(@office_listener) && @office_listener
13
+ pid = spawn('unoconv --listener')
14
+ thr = Process.detach(pid)
15
+ at_exit do
16
+ begin
17
+ Process.kill(:TERM, pid)
18
+ rescue => e
19
+ end
20
+ end
21
+ @office_listener = true
22
+ end
23
+ end
24
+ end
25
+
26
+ # @private
27
+ module Office
28
+ include CliGenerator
29
+ include Which
30
+
31
+ def self.included(mod)
32
+ [:png, :svg].each do |f|
33
+ mod.register_format(f, :image) do |parent, source|
34
+ office(parent, source, f)
35
+ end
36
+ end
37
+ end
38
+
39
+ def office(parent_block, source, format)
40
+ inherit_prefix = name
41
+
42
+ options = {}
43
+
44
+ unoconv = which(parent_block, 'unoconv', :raise_on_error => false)
45
+ inkscape = which(parent_block, 'inkscape', :raise_on_error => false)
46
+
47
+ if unoconv
48
+ OfficeServer.listen
49
+ options[:page] = source.attr('page', '1', inherit_prefix)
50
+ run_convert(unoconv, inkscape, source, format, options)
51
+ end
52
+ end
53
+
54
+ private
55
+ def run_convert(unoconv, inkscape, source, format, options = {})
56
+ # office document => PDF
57
+ pdf = generate_file(unoconv, 'office', 'pdf', source.to_s) do |tool_path, input_path, output_path|
58
+ args = [tool_path, '-f', 'pdf', '-e', "PageRange=#{options[:page]}-#{options[:page]}", '-o', Platform.native_path(output_path), Platform.native_path(input_path)]
59
+ args
60
+ end
61
+
62
+ # PDF => target format
63
+ if inkscape
64
+ generate_file(inkscape, 'pdf', format.to_s, pdf) do |tool_path, input_path, output_path|
65
+ case format.to_s
66
+ when 'png'
67
+ args = [tool_path, '-f', Platform.native_path(input_path), '-e', Platform.native_path(output_path)]
68
+ when 'svg'
69
+ args = [tool_path, '-f', Platform.native_path(input_path), '-l', Platform.native_path(output_path)]
70
+ end
71
+ args
72
+ end
73
+ else
74
+ generate_file(unoconv, 'pdf', format.to_s, pdf) do |tool_path, input_path, output_path|
75
+ args = [tool_path, '-f', format.to_s, '-o', Platform.native_path(output_path), Platform.native_path(input_path)]
76
+ args
77
+ end
78
+ end
79
+ end
80
+
81
+ class Source < Extensions::FileSource
82
+ def initialize(parent_block, file_name, attributes)
83
+ super(parent_block, file_name, attributes)
84
+ end
85
+
86
+ def image_name
87
+ name = super
88
+ page = attr('page', 1, @parent_block)
89
+ name + '-' + page
90
+ end
91
+
92
+ def code
93
+ File.read(@file_name)
94
+ end
95
+ end
96
+ end
97
+
98
+ class OfficeBlockProcessor < Extensions::DiagramBlockProcessor
99
+ include Office
100
+
101
+ def create_source(parent, target, attributes)
102
+ Office::Source.new(parent, apply_target_subs(parent, target), attributes)
103
+ end
104
+ end
105
+
106
+ class OfficeBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
107
+ include Office
108
+
109
+ def create_source(parent, target, attributes)
110
+ Office::Source.new(parent, apply_target_subs(parent, target), attributes)
111
+ end
112
+ end
113
+ end
114
+ end
115
+
@@ -0,0 +1,7 @@
1
+ module Asciidoctor
2
+ module Diagram
3
+ module Office
4
+ VERSION = "0.1.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciidoctor-diagram-office
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Hiroyuki Wada
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: asciidoctor-diagram
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ description: An Asciidoctor extension to convert office document to SVG or PNG
28
+ email: wadahiro@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - Gemfile
34
+ - LICENSE
35
+ - Rakefile
36
+ - asciidoctor-diagram-office.gemspec
37
+ - lib/asciidoctor-diagram-office.rb
38
+ - lib/asciidoctor-diagram-office/extension.rb
39
+ - lib/asciidoctor-diagram-office/version.rb
40
+ homepage: https://github.com/wadahiro/asciidoctor-diagram-office
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.6.8
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Asciidoctor diagram extension, with support for Office documents
64
+ test_files: []