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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82735343deff232e1a0c4eeebb632ac7a0d66545cd2f5be0825e1e41f2a5e253
4
- data.tar.gz: ec97ab375ae697d6920f1f766f344d65cb3c5d1d572981c1745d9ae5750e6a61
3
+ metadata.gz: 31caa3b93cfb0b3764c773b1fb9fce47ee370171f919a8e104275b5eb9d7fec0
4
+ data.tar.gz: 3a16089963e1fbc6e6d142a180c5a5206329e9f8701673073e63401b43a54c71
5
5
  SHA512:
6
- metadata.gz: 37348ca9e62132d709a573b3388114a521553f7937e71dc668c13a072ac2d99046e22a0811a507d17f0adb21afb5e958fba7cf7f2cae5c4262f2b703bd2410bf
7
- data.tar.gz: 1ee732f617a0d25750c11069e45fe26d770f5690065f0d82ce2edc8824e8c13ba7c0326bdaab01d0fefa0f6b6f35369b5148f13b40a11ed6cf6d2c2419a3dbc4
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
@@ -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
- if not attributes.key? 'expand'
74
- target_name = File.basename(target,'.*')
75
- expanded_target = "#{target_name}.html"
76
- if attributes.key? 'out-dir'
77
- expanded_target = attributes["out-dir"] + "/" + expanded_target
78
- end
79
-
80
- Asciidoctor.convert("include::#{target}[expand=true]", to_file: expanded_target, attributes: doc.attributes)
81
-
82
- text = if attributes.key? 'link' then attributes["link"] else target_name end
83
- content = ["link:#{expanded_target}[#{text}]"]
84
- else
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(target)
112
+ IO.readlines( article_refs.abs_target )
87
113
  .map( &DocBlocksExtractor.new() )
88
114
  .compact
89
- #content = ["linked"]
90
115
  end
91
- reader.push_include content, target, target, 1, attributes
92
- return reader
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.2'
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: