ex-doc-include 0.2 → 0.4
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/lib/articles-addresser.rb +91 -0
- data/lib/ex-doc-include.rb +42 -16
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31caa3b93cfb0b3764c773b1fb9fce47ee370171f919a8e104275b5eb9d7fec0
|
|
4
|
+
data.tar.gz: 3a16089963e1fbc6e6d142a180c5a5206329e9f8701673073e63401b43a54c71
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b06dc8f66955087d82e76cf0c65a4bee8a0ae415fc192d5cbe56035e3a9eb4c565904ff9cc06c812d1190421c96d56e7ed5f38604def5a78bba48480ca39e951
|
|
7
|
+
data.tar.gz: f29b34fa361ded28f2ec20b9c2ff5021d9b1a700bdfba0f0886409a669e82c374b88a00f41b58d55b98936ba8211471f6ebc3138ad96476ad30e35245e776718
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Provides facilities to identify key traits of the included articles.
|
|
2
|
+
# Relative references found at inclusion location, are supposed to be
|
|
3
|
+
# relative to the location of:
|
|
4
|
+
# - the master (including) document, when referencing a source
|
|
5
|
+
# - the master's destination folder, when referencing an output document
|
|
6
|
+
# (e.g. a rendered linked article)
|
|
7
|
+
|
|
8
|
+
class ArticleReference
|
|
9
|
+
|
|
10
|
+
# The initialization requires the master document as received by the
|
|
11
|
+
# process function from the parser to let the constructed object be
|
|
12
|
+
# informed of:
|
|
13
|
+
# - the value of document option `:to_dir`
|
|
14
|
+
# - the value of the document attribute `docdir`
|
|
15
|
+
#
|
|
16
|
+
# In case the document option `:to_dir` is not defined (happen when
|
|
17
|
+
# not converting to file), the destination directory is assumed to be
|
|
18
|
+
# the same as the one of the master document; that is `docdir`
|
|
19
|
+
|
|
20
|
+
def initialize (doc)
|
|
21
|
+
@to_dir = doc.options[:to_dir]
|
|
22
|
+
@root = if doc.attributes.key? 'docdir' then doc.attributes['docdir'] else '' end
|
|
23
|
+
if @to_dir == nil then
|
|
24
|
+
@to_dir = @root
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# The method process_article collect additional information of an article
|
|
29
|
+
# linked in the document. It fixed article informations that are used to
|
|
30
|
+
# feed the other methods, therefore `process_article` must be called prior
|
|
31
|
+
# the read of any other property.
|
|
32
|
+
# While not optimal, this is necessary because the information provided
|
|
33
|
+
# actually refer to an included article, and multiple included
|
|
34
|
+
# articles might happen to be in the same document - then their references
|
|
35
|
+
# resolved by the same `ArticleReference` object.
|
|
36
|
+
#
|
|
37
|
+
# The last call to `process_article` fixes the *processing article*.
|
|
38
|
+
|
|
39
|
+
def process_article target, attributes
|
|
40
|
+
@target = target
|
|
41
|
+
@base_target = File.basename(target, '.*')
|
|
42
|
+
|
|
43
|
+
@articles_folder = if attributes.key? 'articles-dir' then
|
|
44
|
+
attributes['articles-dir']
|
|
45
|
+
else
|
|
46
|
+
''
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
@link = if attributes.key? 'link' then
|
|
50
|
+
attributes['link']
|
|
51
|
+
else
|
|
52
|
+
@base_target
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Provides the relative path of the processing article in the output space.
|
|
57
|
+
# The path is relative to the output folder of the master document.
|
|
58
|
+
#
|
|
59
|
+
# i.e. <articles-dir>/<target>.html
|
|
60
|
+
def article
|
|
61
|
+
if @articles_folder.empty? then
|
|
62
|
+
"#{@base_target}.html"
|
|
63
|
+
else
|
|
64
|
+
File.join( @articles_folder, @base_target) + ".html"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Rebases the article path to the destination folder.
|
|
69
|
+
def abs_article
|
|
70
|
+
File.join(@to_dir, article)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Makes the target path relative to the master document folder.
|
|
74
|
+
# If available, the master document folder is an absolute path, then the
|
|
75
|
+
# result is also an absolute path.
|
|
76
|
+
# When the master document folder is not known, the result is
|
|
77
|
+
# the target itself, whenever it is absolute or relative.
|
|
78
|
+
def abs_target
|
|
79
|
+
if @root == nil then
|
|
80
|
+
return @target
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
return File.absolute_path(@target, @root)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Provides the alias to be used at link location in the master document.
|
|
87
|
+
def link
|
|
88
|
+
return @link
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
data/lib/ex-doc-include.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
require 'asciidoctor'
|
|
2
|
+
require_relative 'articles-addresser'
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
class DocBlocksExtractor
|
|
4
6
|
|
|
@@ -64,32 +66,56 @@ class DocBlocksExtractor
|
|
|
64
66
|
end
|
|
65
67
|
|
|
66
68
|
|
|
69
|
+
|
|
67
70
|
class ExDocIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
|
|
71
|
+
|
|
68
72
|
def handles? target
|
|
69
73
|
target.end_with? '.h', '.hpp', '.cpp'
|
|
70
74
|
end
|
|
71
75
|
|
|
76
|
+
def expand? attributes
|
|
77
|
+
return attributes.key? 'expand'
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def link? attributes
|
|
81
|
+
return not expand? attributes
|
|
82
|
+
end
|
|
83
|
+
|
|
72
84
|
def process doc, reader, target, attributes
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
log = doc.logger
|
|
86
|
+
|
|
87
|
+
article_refs = ArticleReference.new( doc)
|
|
88
|
+
article_refs.process_article(target, attributes)
|
|
89
|
+
|
|
90
|
+
if link? attributes
|
|
91
|
+
log.info "Linking ex-doc from #{target}"
|
|
92
|
+
log.info " Creating the linked article in #{ article_refs.abs_article}"
|
|
93
|
+
log.info " Link alias: #{article_refs.link}"
|
|
94
|
+
log.info " Link target: #{article_refs.article}"
|
|
95
|
+
|
|
96
|
+
Asciidoctor.convert(
|
|
97
|
+
"include::#{article_refs.abs_target}[expand=true]",
|
|
98
|
+
to_file: article_refs.abs_article,
|
|
99
|
+
to_dir: doc.options[:to_dir],
|
|
100
|
+
standalone: doc.options[:standalone],
|
|
101
|
+
attributes: doc.options[:attributes],
|
|
102
|
+
safe: :unsafe,
|
|
103
|
+
mkdirs: true)
|
|
104
|
+
|
|
105
|
+
content = ["link:#{article_refs.article}[#{ article_refs.link}]"]
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
if expand? attributes
|
|
109
|
+
log.info "Expanding ex-doc from #{article_refs.abs_target}"
|
|
110
|
+
|
|
85
111
|
content =
|
|
86
|
-
IO.readlines(
|
|
112
|
+
IO.readlines( article_refs.abs_target )
|
|
87
113
|
.map( &DocBlocksExtractor.new() )
|
|
88
114
|
.compact
|
|
89
|
-
#content = ["linked"]
|
|
90
115
|
end
|
|
91
|
-
|
|
92
|
-
|
|
116
|
+
|
|
117
|
+
reader.push_include content, nil, nil, 1, attributes
|
|
118
|
+
|
|
93
119
|
end
|
|
94
120
|
end
|
|
95
121
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ex-doc-include
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '0.
|
|
4
|
+
version: '0.4'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Giuseppe Puoti
|
|
@@ -14,6 +14,7 @@ extensions: []
|
|
|
14
14
|
extra_rdoc_files: []
|
|
15
15
|
files:
|
|
16
16
|
- assets/style.css
|
|
17
|
+
- lib/articles-addresser.rb
|
|
17
18
|
- lib/ex-doc-include.rb
|
|
18
19
|
homepage: https://github.com/gpuoti/ex-doc-include
|
|
19
20
|
licenses:
|