asciidoctor-interdoc-reftext 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.adoc +32 -3
- data/lib/asciidoctor/interdoc_reftext/inline_node_mixin.rb +28 -18
- data/lib/asciidoctor/interdoc_reftext/processor.rb +16 -5
- data/lib/asciidoctor/interdoc_reftext/resolver.rb +19 -7
- data/lib/asciidoctor/interdoc_reftext/version.rb +1 -1
- data/lib/asciidoctor/interdoc_reftext.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd232240b5668fc37f4552d6ee419f46028815c0aec5015fd7f70dd4a110c3cc
|
4
|
+
data.tar.gz: f68b54e05dd2cd7d32fc3f3f0c48b852ab50e3d4ec7cda4bcf54c1891ef0d8f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7ddcf13d9d125c3071507ebaca379af4bfc41933df4f4920c6be70f8e12053e804cd586146da565389d9f29cc8fb7e6f174db2d4db129105a66cbc02447e1d2
|
7
|
+
data.tar.gz: 19432fd2fac94e39a36d4c20ac45870d45733b904f3485f4dc37413b8fa47664e6b92bae2603a6a583867ff0fa9385871e289ef139c804b679585445477e51e1
|
data/README.adoc
CHANGED
@@ -11,6 +11,7 @@ image:https://travis-ci.org/{gh-name}.svg?branch={gh-branch}[Build Status, link=
|
|
11
11
|
image:https://api.codacy.com/project/badge/Coverage/{codacy-id}["Test Coverage", link="https://www.codacy.com/app/{gh-name}"]
|
12
12
|
image:https://api.codacy.com/project/badge/Grade/{codacy-id}["Codacy Code quality", link="https://www.codacy.com/app/{gh-name}"]
|
13
13
|
image:https://img.shields.io/gem/v/{gem-name}.svg?style=flat[Gem Version, link="https://rubygems.org/gems/{gem-name}"]
|
14
|
+
image:https://img.shields.io/npm/v/{gem-name}.svg?style=flat[npm Version, link="https://www.npmjs.org/package/{gem-name}"]
|
14
15
|
image:https://img.shields.io/badge/yard-docs-blue.svg[Yard Docs, link="http://www.rubydoc.info/github/{gh-name}/{gh-branch}"]
|
15
16
|
endif::env-github[]
|
16
17
|
|
@@ -61,7 +62,9 @@ where “The First Section” is *title* of the section with id _sec1_ in _other
|
|
61
62
|
|
62
63
|
== Installation
|
63
64
|
|
64
|
-
|
65
|
+
=== Ruby
|
66
|
+
|
67
|
+
Install {gem-name} from Rubygems:
|
65
68
|
|
66
69
|
[source, subs="+attributes"]
|
67
70
|
gem install {gem-name}
|
@@ -72,21 +75,47 @@ or to install the latest development version:
|
|
72
75
|
gem install {gem-name} --pre
|
73
76
|
|
74
77
|
|
78
|
+
=== Node.js
|
79
|
+
|
80
|
+
Install {gem-name} from npmjs.com:
|
81
|
+
|
82
|
+
[source, sh, subs="+attributes"]
|
83
|
+
npm install --save {gem-name}
|
84
|
+
|
85
|
+
|
75
86
|
== Usage
|
76
87
|
|
77
|
-
|
88
|
+
=== CLI
|
89
|
+
|
78
90
|
If you invoke Asciidoctor from command-line, use option `-r` to load the extension:
|
79
91
|
|
80
92
|
[source, subs="+attributes"]
|
81
93
|
asciidoctor -r {gem-name} README.adoc
|
82
94
|
|
83
|
-
|
95
|
+
|
96
|
+
=== Ruby
|
97
|
+
|
98
|
+
Just `require '{gem-name}'`.
|
99
|
+
However, if you don’t want the extension to be automatically registered in Asciidoctor, `require 'asciidoctor/interdoc_reftext/processor'` instead.
|
84
100
|
|
85
101
|
IMPORTANT: Bundler automatically _requires_ all the specified gems.
|
86
102
|
To prevent it, use +
|
87
103
|
`gem '{gem-name}', require: false`.
|
88
104
|
|
89
105
|
|
106
|
+
=== Node.js
|
107
|
+
|
108
|
+
[source, js, subs="+attributes"]
|
109
|
+
----
|
110
|
+
// Load asciidoctor.js and {gem-name}.
|
111
|
+
const asciidoctor = require('asciidoctor.js')()
|
112
|
+
require('{gem-name}')
|
113
|
+
|
114
|
+
// Convert the file to HTML.
|
115
|
+
asciidoctor.convertFile("./README.adoc")
|
116
|
+
----
|
117
|
+
|
118
|
+
|
90
119
|
== License
|
91
120
|
|
92
121
|
This project is licensed under http://opensource.org/licenses/MIT/[MIT License].
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'asciidoctor' unless RUBY_PLATFORM == 'opal'
|
2
3
|
require 'asciidoctor/interdoc_reftext/version'
|
3
|
-
require 'asciidoctor'
|
4
4
|
|
5
5
|
module Asciidoctor::InterdocReftext
|
6
6
|
# Mixin intended to be prepended into `Asciidoctor::Inline`.
|
@@ -10,29 +10,39 @@ module Asciidoctor::InterdocReftext
|
|
10
10
|
# represents an inter-document cross reference).
|
11
11
|
module InlineNodeMixin
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
if RUBY_PLATFORM == 'opal'
|
14
|
+
# Opal does not support `Module#prepend`, so we have to fallback to
|
15
|
+
# `include` with poor alias method chain approach.
|
16
|
+
def self.included(base_klass)
|
17
|
+
base_klass.send(:alias_method, :text_without_reftext, :text)
|
18
|
+
base_klass.send(:define_method, :text) do
|
19
|
+
text_without_reftext || interdoc_reftext
|
20
|
+
end
|
21
|
+
end
|
22
|
+
else
|
23
|
+
# Returns text of this inline element.
|
24
|
+
#
|
25
|
+
# @note This method will override the same name attribute reader in
|
26
|
+
# class `Asciidoctor::Inline`.
|
27
|
+
def text
|
28
|
+
super || interdoc_reftext
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
29
32
|
private
|
30
33
|
|
31
|
-
#
|
32
|
-
#
|
33
|
-
|
34
|
+
# Returns resolved reftext of this inline node if it is a valid
|
35
|
+
# inter-document cross-reference, otherwise returns nil.
|
36
|
+
#
|
37
|
+
# @return [String, nil]
|
38
|
+
def interdoc_reftext
|
39
|
+
# If this node is not an inter-document cross reference...
|
40
|
+
return if @node_name != 'inline_anchor' || @attributes['path'].nil?
|
41
|
+
|
34
42
|
# This variable is injected into the document by {Processor}.
|
35
|
-
@document.instance_variable_get(Processor::RESOLVER_VAR_NAME)
|
43
|
+
if (resolver = @document.instance_variable_get(Processor::RESOLVER_VAR_NAME))
|
44
|
+
@text = resolver.call(@attributes['refid'])
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
38
48
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'asciidoctor'
|
3
|
-
require 'asciidoctor/extensions'
|
2
|
+
require 'asciidoctor' unless RUBY_PLATFORM == 'opal'
|
3
|
+
require 'asciidoctor/extensions' unless RUBY_PLATFORM == 'opal'
|
4
4
|
require 'asciidoctor/interdoc_reftext/inline_node_mixin'
|
5
5
|
require 'asciidoctor/interdoc_reftext/resolver'
|
6
6
|
require 'asciidoctor/interdoc_reftext/version'
|
@@ -34,7 +34,7 @@ module Asciidoctor::InterdocReftext
|
|
34
34
|
#
|
35
35
|
# Eh, this is really nasty... The least evil way how to achieve the goal
|
36
36
|
# seems to be monkey-patching of the `Asciidoctor::Inline` class. This is
|
37
|
-
# done via {InlineNodeMixin} which is prepended into the `Inline` class on
|
37
|
+
# done via {InlineNodeMixin} which is prepended* into the `Inline` class on
|
38
38
|
# initialization of this processor.
|
39
39
|
#
|
40
40
|
# The actual logic that resolves reflabel for the given *refid* is
|
@@ -43,11 +43,16 @@ module Asciidoctor::InterdocReftext
|
|
43
43
|
# it into instance variable {RESOLVER_VAR_NAME} in the document, so
|
44
44
|
# {InlineNodeMixin} can access it.
|
45
45
|
#
|
46
|
-
# Prepending {InlineNodeMixin} into the `Asciidoctor::Inline` class has
|
46
|
+
# Prepending* {InlineNodeMixin} into the `Asciidoctor::Inline` class has
|
47
47
|
# (obviously) a global effect. However, if {RESOLVER_VAR_NAME} is not
|
48
48
|
# injected in the document object (e.g. extension is not active), `Inline`
|
49
49
|
# behaves the same as without {InlineNodeMixin}.
|
50
50
|
#
|
51
|
+
# _\* If running under Opal (JavaScript), {InlineNodeMixin} is not prepended
|
52
|
+
# into the `Asciidoctor::Inline`, because Opal does not support that. Thus
|
53
|
+
# it's included and the `#text` method is overriden using poor alias method
|
54
|
+
# chain approach.
|
55
|
+
#
|
51
56
|
# NOTE: We use _reftext_ and _reflabel_ as interchangeable terms in this gem.
|
52
57
|
class Processor < ::Asciidoctor::Extensions::TreeProcessor
|
53
58
|
|
@@ -65,7 +70,13 @@ module Asciidoctor::InterdocReftext
|
|
65
70
|
|
66
71
|
# Monkey-patch Asciidoctor::Inline unless already patched.
|
67
72
|
unless ::Asciidoctor::Inline.include? InlineNodeMixin
|
68
|
-
|
73
|
+
if RUBY_PLATFORM == 'opal'
|
74
|
+
# Opal does not support `Module#prepend`, so we have to fallback to
|
75
|
+
# `include` with poor alias method chain approach.
|
76
|
+
::Asciidoctor::Inline.send(:include, InlineNodeMixin)
|
77
|
+
else
|
78
|
+
::Asciidoctor::Inline.send(:prepend, InlineNodeMixin)
|
79
|
+
end
|
69
80
|
end
|
70
81
|
end
|
71
82
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'asciidoctor' unless RUBY_PLATFORM == 'opal'
|
3
|
+
require 'logger' unless RUBY_PLATFORM == 'opal'
|
2
4
|
require 'asciidoctor/interdoc_reftext/version'
|
3
|
-
require 'asciidoctor'
|
4
|
-
require 'logger'
|
5
5
|
|
6
6
|
module Asciidoctor::InterdocReftext
|
7
7
|
# Resolver of inter-document cross reference texts.
|
@@ -20,8 +20,17 @@ module Asciidoctor::InterdocReftext
|
|
20
20
|
|
21
21
|
logger ||= if defined? ::Asciidoctor::LoggerManager
|
22
22
|
::Asciidoctor::LoggerManager.logger
|
23
|
-
|
23
|
+
elsif defined? ::Logger
|
24
24
|
::Logger.new(STDERR)
|
25
|
+
else
|
26
|
+
# Fake logger for Opal.
|
27
|
+
# TODO: Remove after update to Asciidoctor 1.5.7 or Opal with Logger.
|
28
|
+
Object.new.tap do |o|
|
29
|
+
# rubocop: disable MethodMissing
|
30
|
+
def o.method_missing(_, *args)
|
31
|
+
STDERR.puts(*args)
|
32
|
+
end
|
33
|
+
end
|
25
34
|
end
|
26
35
|
|
27
36
|
@document = document
|
@@ -48,8 +57,9 @@ module Asciidoctor::InterdocReftext
|
|
48
57
|
path = resolve_target_path(path) or return nil
|
49
58
|
|
50
59
|
@cache["#{path}##{fragment}".freeze] ||= begin
|
51
|
-
|
52
|
-
|
60
|
+
read_file(path) do |lines|
|
61
|
+
parse_reftext(lines, fragment)
|
62
|
+
end
|
53
63
|
rescue => e # rubocop: disable RescueWithoutErrorClass
|
54
64
|
raise if @raise_exceptions
|
55
65
|
@logger.error "interdoc-reftext: #{e}"
|
@@ -93,9 +103,11 @@ module Asciidoctor::InterdocReftext
|
|
93
103
|
end
|
94
104
|
|
95
105
|
# @param path [String] path of the file to read.
|
96
|
-
# @
|
106
|
+
# @yield [Enumerable<String>] gives lines of the file.
|
97
107
|
def read_file(path)
|
98
|
-
::
|
108
|
+
::File.open(path) do |f|
|
109
|
+
yield f.each_line
|
110
|
+
end
|
99
111
|
end
|
100
112
|
|
101
113
|
# @param input [Enumerable<String>] lines of the AsciiDoc document.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'asciidoctor'
|
3
|
-
require 'asciidoctor/extensions'
|
2
|
+
require 'asciidoctor' unless RUBY_PLATFORM == 'opal'
|
3
|
+
require 'asciidoctor/extensions' unless RUBY_PLATFORM == 'opal'
|
4
4
|
require 'asciidoctor/interdoc_reftext/version'
|
5
5
|
require 'asciidoctor/interdoc_reftext/processor'
|
6
6
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-interdoc-reftext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Jirutka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
173
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.7.
|
174
|
+
rubygems_version: 2.7.7
|
175
175
|
signing_key:
|
176
176
|
specification_version: 4
|
177
177
|
summary: Asciidoctor extension providing implicit (automatic) reference text (label)
|