asciidoctor-mermaid 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5fd8e240d77dc5516d7e9865d394bd2a276b132f3aca1220b58e03d87f252773
4
+ data.tar.gz: b2344c6ad7e4c282d89d53e830b20ac29cb8a7a2b49629609d1e64573bd56500
5
+ SHA512:
6
+ metadata.gz: 49e0bae98b9d3e0d6406af0095f0dd7c841242099d3ab5eae6b1c12781410e464db769099499dd57d092a6e21bf826548953742769a2a9b0c01927e181410a42
7
+ data.tar.gz: 60e61df09a7cc640e7953671ad3797d3676802371ae5b37566098d8a54eedd1322b5a842d8ee41715cc48b6b92ad38919c72a9d0e785c391347350a258fc2ed2
@@ -0,0 +1,20 @@
1
+ require 'open3'
2
+
3
+ module Asciidoctor
4
+ module Mermaid
5
+ class Cli
6
+ def self.run(content, *args)
7
+ stdout, stderr, status =
8
+ Open3.capture3('mmdc', *args, stdin_data: content)
9
+
10
+ exit = status.exitstatus
11
+
12
+ if exit != 0
13
+ raise "mermaid-cli failed: #{stdout.empty? ? stderr : stdout}"
14
+ end
15
+
16
+ stdout
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,41 @@
1
+ require 'asciidoctor/extensions'
2
+ require 'digest/md5'
3
+ require 'tempfile'
4
+ require_relative 'cli'
5
+
6
+ class MermaidTreeProcessor < Asciidoctor::Extensions::TreeProcessor
7
+ def process(document)
8
+ document.blocks.map! do |block|
9
+ if block.attributes['style'] === 'source' &&
10
+ block.attributes['language'] === 'mermaid'
11
+ self.convert_block(block)
12
+ else
13
+ block
14
+ end
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ def convert_block(block)
21
+ Asciidoctor::Block.new block.parent,
22
+ :pass,
23
+ source: self.render_svg(block.source).lines,
24
+ attributes: {
25
+ 'style' => 'pass',
26
+ }
27
+ end
28
+
29
+ def render_svg(content)
30
+ file_name = Digest::MD5.hexdigest(content)
31
+ output_file = Tempfile.new([file_name, '.svg'])
32
+ begin
33
+ ::Asciidoctor::Mermaid::Cli.run(content, "-o#{output_file.path}")
34
+ File.read(output_file.path)
35
+ ensure
36
+ output_file.unlink
37
+ end
38
+ end
39
+ end
40
+
41
+ Asciidoctor::Extensions.register { treeprocessor MermaidTreeProcessor }
@@ -0,0 +1,5 @@
1
+ module Asciidoctor
2
+ module Mermaid
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require_relative 'asciidoctor-mermaid/extension'
@@ -0,0 +1,19 @@
1
+ require 'asciidoctor'
2
+ require 'asciidoctor-mermaid'
3
+ require 'pry'
4
+
5
+ MERMAID_DOC = <<-eos
6
+ lorem ipsum
7
+
8
+ ```mermaid
9
+ flowchart LR
10
+ id1[flowchart node text]
11
+ ```
12
+ eos
13
+
14
+ describe 'extension' do
15
+ it 'renders a basic mermaid diagram' do
16
+ doc = Asciidoctor.convert MERMAID_DOC
17
+ expect(doc).to include('flowchart node text')
18
+ end
19
+ end
@@ -0,0 +1,100 @@
1
+ require 'rspec/snapshot'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
+ RSpec.configure do |config|
19
+ # rspec-expectations config goes here. You can use an alternate
20
+ # assertion/expectation library such as wrong or the stdlib/minitest
21
+ # assertions if you prefer.
22
+ config.expect_with :rspec do |expectations|
23
+ # This option will default to `true` in RSpec 4. It makes the `description`
24
+ # and `failure_message` of custom matchers include text for helper methods
25
+ # defined using `chain`, e.g.:
26
+ # be_bigger_than(2).and_smaller_than(4).description
27
+ # # => "be bigger than 2 and smaller than 4"
28
+ # ...rather than:
29
+ # # => "be bigger than 2"
30
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31
+ end
32
+
33
+ # rspec-mocks config goes here. You can use an alternate test double
34
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
35
+ config.mock_with :rspec do |mocks|
36
+ # Prevents you from mocking or stubbing a method that does not exist on
37
+ # a real object. This is generally recommended, and will default to
38
+ # `true` in RSpec 4.
39
+ mocks.verify_partial_doubles = true
40
+ end
41
+
42
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43
+ # have no way to turn it off -- the option exists only for backwards
44
+ # compatibility in RSpec 3). It causes shared context metadata to be
45
+ # inherited by the metadata hash of host groups and examples, rather than
46
+ # triggering implicit auto-inclusion in groups with matching metadata.
47
+ config.shared_context_metadata_behavior = :apply_to_host_groups
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ =begin
52
+ # This allows you to limit a spec run to individual examples or groups
53
+ # you care about by tagging them with `:focus` metadata. When nothing
54
+ # is tagged with `:focus`, all examples get run. RSpec also provides
55
+ # aliases for `it`, `describe`, and `context` that include `:focus`
56
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
57
+ config.filter_run_when_matching :focus
58
+
59
+ # Allows RSpec to persist some state between runs in order to support
60
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
61
+ # you configure your source control system to ignore this file.
62
+ config.example_status_persistence_file_path = "spec/examples.txt"
63
+
64
+ # Limits the available syntax to the non-monkey patched syntax that is
65
+ # recommended. For more details, see:
66
+ # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = "doc"
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciidoctor-mermaid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Justin Bennett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-03-05 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: asciidoctor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: gem-release
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Asciidoctor mermaid extension
98
+ email:
99
+ - oss@just-be.dev
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - lib/asciidoctor-mermaid.rb
105
+ - lib/asciidoctor-mermaid/cli.rb
106
+ - lib/asciidoctor-mermaid/extension.rb
107
+ - lib/asciidoctor-mermaid/version.rb
108
+ - spec/extension_spec.rb
109
+ - spec/spec_helper.rb
110
+ homepage: https://github.com/oxidecomputer/asciidoctor-mermaid
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.1.6
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: An Asciidoctor extension that transforms Mermaid diagrams in markdown codefences
133
+ to inline svgs.
134
+ test_files:
135
+ - spec/extension_spec.rb
136
+ - spec/spec_helper.rb