asciidoctor-indir_ext 0.1.0

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: ac1cb1e933768661f4dc12cc953cb837f4fa90c688b5de8ab3a207dad4900899
4
+ data.tar.gz: 11c4ebd2d95bf894373814071a085e9203b9bdac5cc72b1bdb5ebe18641c1532
5
+ SHA512:
6
+ metadata.gz: 2626b1f64f3352831589bc5bdaf699f6f418d316d5bc2d89544045c5433da432f091ffa9993c12374f27b85ead4a1bc1f29bf46d05a6d7460730a66298c08fb3
7
+ data.tar.gz: 40517971948052677c1c8c8da6d706c34c175e97a1751bf372e78111325dcb047aaa31d8adf3745aa51c3a09ecf53caabe138a81fa5fa99bc332301a675c6e5a
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Johannes Harms
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Asciidoctor::IndirExt
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/asciidoctor/indir_ext`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'asciidoctor-indir_ext'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install asciidoctor-indir_ext
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ * After checking out the repo, run `bundle install` to install dependencies.
30
+ * To list all available rake tasks, run `bundle exec rake -T`.
31
+ * To build a gem package on your local machine, run `bundle exec rake build`.
32
+ * To install this gem onto your local machine, run `bundle exec rake install`.
33
+ * To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/asciidoctor-indir_ext.
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "asciidoctor/indir_ext/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "asciidoctor-indir_ext"
8
+ spec.version = Asciidoctor::IndirExt::VERSION
9
+ spec.authors = ["johannesjh"]
10
+ spec.email = ["johannesjh@users.noreply.github.com"]
11
+
12
+ spec.summary = "An Asciidoctor extension that adds a variable `indir`, which always points to the directory of the currently included asciidoc file"
13
+ spec.description = %q(This Asciidoctor extension exposes a variable `indir`, which holds the path to the directory where the current asciidoc file is located.
14
+ The value of this variable changes to always reflect the location of the current, included subdocument.
15
+ (Note, this is in contrast to the `docfile` variable, which remains the same throughout an entire document).)
16
+ spec.homepage = "https://github.com/johannesjh/asciidoctor-indir_ext"
17
+ spec.license = "MIT"
18
+
19
+ spec.metadata = {
20
+ 'bug_tracker_uri' => 'https://github.com/johannesjh/asciidoctor-indir_ext/issues',
21
+ 'source_code_uri' => 'https://github.com/johannesjh/asciidoctor-indir_ext'
22
+ }
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ spec.files = Dir['lib/**/*', '*.gemspec', 'LICENSE*', 'README*']
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_runtime_dependency 'asciidoctor', '~> 1.5.6'
29
+ spec.add_runtime_dependency 'concurrent-ruby', '~> 1.1.3'
30
+ spec.add_runtime_dependency 'asciidoctor-include-ext', '~> 0.3.0'
31
+
32
+ spec.add_development_dependency 'asciidoctor-pdf', '~> 1.5.0.alpha.16' # to build a pdf of the example folder
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'indir_ext/extension'
2
+
3
+ Asciidoctor::Extensions.register do
4
+ include_processor Asciidoctor::IndirExt::IndirIncludeProcessor
5
+ end
@@ -0,0 +1,82 @@
1
+ require 'asciidoctor/include_ext/include_processor'
2
+
3
+ module Asciidoctor
4
+ module IndirExt
5
+ ##
6
+ # Asciidoctor extension that adds a variable "indir", pointing at the directory of included asciidoc files.
7
+ #
8
+ # The indir variable always points at the directory where the current asciidoc file is located.
9
+ # The value of the indir variable changes to always reflect the location of the current, included subdocument.
10
+ # (Note: This is in contrast to the docfile variable, which remains the same throughout an entire document).
11
+ # The indir variable can be used to construct image paths relative to included subdocuments.
12
+ #
13
+ # Background:
14
+ # This extension was created to ease the handling of image paths in nested subdocuments,
15
+ # see https://github.com/asciidoctor/asciidoctor/issues/650#issuecomment-433946605.
16
+ #
17
+ # Motivation:
18
+ # The usage scenario that motivates this extension is a nested folder structure with asciidoc files,
19
+ # with images stored next to the asciidoc file where they are used.
20
+ # For example, an asciidoc file "sub/sub1.adoc" may use an image located at "sub/images/img1.svg".
21
+ # In this scenario, we want to be able to compile the asciidoc files in two ways,
22
+ # as standalone documents, and included into a parent document.
23
+ # The image paths should resolve fine in both cases.
24
+ #
25
+ # Intended Usage of the Extension:
26
+ #
27
+ # 1. In the beginning of a subdocument, add this line:
28
+ # ifndef::indir[:indir: .]
29
+ #
30
+ # 2. Include images like this:
31
+ # image::{indir}/images/example.svg[]
32
+ #
33
+ # 3. When compiling a master document (that includes other subdocuments), require this extension.
34
+ # The extension will set the indir variable to always point at the directory of the included asciidoc file,
35
+ # to that the an image path like "{indir}/images/example.svg" is resolved relative to the included subdocument.
36
+ #
37
+ # Note that the subdocuments compile just fine without the extension.
38
+ # This can be handy to use an editor's built-in preview feature.
39
+ # The extension is only needed when compiling a master document (that includes other subdocuments).
40
+ #
41
+ # Caveats, Future Work:
42
+ # This extension, once registered, claims to handle any includes
43
+ # (because it does not overwrite the "handles?" method of its parent class, which always return true).
44
+ # In consequence, it is difficult to use this extension together with other include processor extensions.
45
+ # A better solution with finer-grained control could be based on https://github.com/jirutka/asciidoctor-include-ext.
46
+ class IndirIncludeProcessor < Asciidoctor::IncludeExt::IncludeProcessor
47
+ def initialize(*args, &block)
48
+ # temporary storage helper that won't be frozen by Asciidoctor
49
+ @tmp = { }
50
+ super
51
+ end
52
+
53
+ def process(document, reader, target, attributes)
54
+ @tmp[:document] = document
55
+ @tmp[:reader] = reader
56
+ super
57
+ end
58
+
59
+ def read_lines(filename, selector)
60
+ # read content using functionality from super
61
+ content = super(filename, selector)
62
+
63
+ # split content into a list of lines if it has been provided as string
64
+ if content.is_a? String then content = content.lines end
65
+
66
+ # Set variables at the beginning of the included content
67
+ included_docfile = filename
68
+ included_docdir = ::File.dirname filename
69
+ content.unshift ''
70
+ content.unshift %(:indir: #{included_docdir})
71
+
72
+ # Reset the variables at the end of the included content
73
+ parent_docfile = @tmp[:reader].include_stack&.dig(-1, 1) || (@tmp[:document].attr 'docfile')
74
+ parent_docdir = ::File.dirname parent_docfile
75
+ content << ''
76
+ content << %(:indir: #{parent_docdir})
77
+
78
+ return content
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,5 @@
1
+ module Asciidoctor
2
+ module IndirExt
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciidoctor-indir_ext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - johannesjh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: asciidoctor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.6
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.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: concurrent-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: asciidoctor-include-ext
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: asciidoctor-pdf
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.0.alpha.16
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.0.alpha.16
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.16'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.16'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: |-
112
+ This Asciidoctor extension exposes a variable `indir`, which holds the path to the directory where the current asciidoc file is located.
113
+ The value of this variable changes to always reflect the location of the current, included subdocument.
114
+ (Note, this is in contrast to the `docfile` variable, which remains the same throughout an entire document).
115
+ email:
116
+ - johannesjh@users.noreply.github.com
117
+ executables: []
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - LICENSE.txt
122
+ - README.md
123
+ - asciidoctor-indir_ext.gemspec
124
+ - lib/asciidoctor/indir_ext.rb
125
+ - lib/asciidoctor/indir_ext/extension.rb
126
+ - lib/asciidoctor/indir_ext/version.rb
127
+ homepage: https://github.com/johannesjh/asciidoctor-indir_ext
128
+ licenses:
129
+ - MIT
130
+ metadata:
131
+ bug_tracker_uri: https://github.com/johannesjh/asciidoctor-indir_ext/issues
132
+ source_code_uri: https://github.com/johannesjh/asciidoctor-indir_ext
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.7.7
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: An Asciidoctor extension that adds a variable `indir`, which always points
153
+ to the directory of the currently included asciidoc file
154
+ test_files: []