@@ -15,32 +15,34 @@ class OperationBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
15
15
def process ( parent , operation , attributes )
16
16
snippets_dir = parent . document . attributes [ 'snippets' ] . to_s
17
17
snippet_names = attributes . fetch 'snippets' , ''
18
- content = read_snippets ( snippets_dir , snippet_names , parent . level + 1 ,
19
- operation )
20
- add_snippets_block ( content , parent . document , parent ) unless content . empty?
18
+ content = read_snippets ( snippets_dir , snippet_names , parent , operation )
19
+ add_blocks ( content , parent . document , parent ) unless content . empty?
21
20
nil
22
21
end
23
22
24
- def read_snippets ( snippets_dir , snippet_names , section_level , operation )
23
+ def read_snippets ( snippets_dir , snippet_names , parent , operation )
25
24
snippets = snippets_to_include ( snippet_names , snippets_dir , operation )
26
25
if snippets . empty?
27
26
warn "No snippets were found for operation #{ operation } in" \
28
27
"#{ snippets_dir } "
29
28
"No snippets found for operation::#{ operation } "
30
29
else
31
- do_read_snippets ( snippets , section_level , operation )
30
+ do_read_snippets ( snippets , parent , operation )
32
31
end
33
32
end
34
33
35
- def do_read_snippets ( snippets , section_level , operation )
34
+ def do_read_snippets ( snippets , parent , operation )
36
35
content = StringIO . new
36
+ section_level = parent . level + 1
37
+ section_id = parent . id
37
38
snippets . each do |snippet |
38
- append_snippet_block ( content , snippet , section_level , operation )
39
+ append_snippet_block ( content , snippet , section_level , section_id ,
40
+ operation )
39
41
end
40
42
content . string
41
43
end
42
44
43
- def add_snippets_block ( content , doc , parent )
45
+ def add_blocks ( content , doc , parent )
44
46
options = { safe : doc . options [ :safe ] ,
45
47
attributes : { 'fragment' => '' ,
46
48
'projectdir' => doc . attr ( :projectdir ) } }
@@ -71,8 +73,9 @@ def all_snippets(snippets_dir, operation)
71
73
. map { |file | Snippet . new ( File . join ( operation_dir , file ) , file [ 0 ..-6 ] ) }
72
74
end
73
75
74
- def append_snippet_block ( content , snippet , section_level , operation )
75
- write_title content , snippet , section_level
76
+ def append_snippet_block ( content , snippet , section_level , section_id ,
77
+ operation )
78
+ write_title content , snippet , section_level , section_id
76
79
write_content content , snippet , operation
77
80
end
78
81
@@ -88,8 +91,9 @@ def write_content(content, snippet, operation)
88
91
end
89
92
end
90
93
91
- def write_title ( content , snippet , level )
94
+ def write_title ( content , snippet , level , id )
92
95
section_level = '=' * ( level + 1 )
96
+ content . puts "[[#{ id } _#{ snippet . name . sub '-' , '_' } ]]"
93
97
content . puts "#{ section_level } #{ snippet . title } "
94
98
content . puts ''
95
99
end
0 commit comments