asciidoctor-git-include 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7d8c1b4ad1989815ac1c7d48b5eb38266804cdcae48aeeabc88fba0aaa57995
4
- data.tar.gz: 3facff4687ba1987ea71b12d24f25d0586b969604fea0a5b986b91fa488ada72
3
+ metadata.gz: 13eceb9f645fc858526b41f9deb27cbdd9ce8405b66d8563a9ae74ebdb6dc695
4
+ data.tar.gz: 67a0474c66d26a41038e483e1f64702a92b5ff68120977733b42faee51389751
5
5
  SHA512:
6
- metadata.gz: bce9989f570a271db90ebdb8914754589f24a79b333e6bceaa96818f68f4921db05dfd8b71cb1a976a14889784c30101d91bb8fb6de7a59d82de44b930248cdc
7
- data.tar.gz: 3dc70bd01f12c4d9a5864ee5911619721664be8e5fa380ccd1fde282411a529bc015b7a50c519306ac6e3ee39e4cc920925150b50b55537ebfeccff1beaff4cc
6
+ metadata.gz: b1d062e7b22b08848fa3c3379c338f0af75c48c2a462dd45b7889c33e333e47fae4b197b39e90421b7dc3fa7a06b763ece5778c4b5fb7de16a47c1acbab3caf9
7
+ data.tar.gz: 88d9a0cd83cee9bbcd5f8f6f4473b871e1c9a4b14a40b00efabe119b1a7f769a56aea3035504b423ceab005079ae9b5ea8e486107a47abee2fb47499877bcb9a
@@ -13,13 +13,37 @@ class GitIncludeMacro < Asciidoctor::Extensions::IncludeProcessor
13
13
  target.slice! "git@"
14
14
  repository = attributes.fetch('repository', '.')
15
15
  revision = attributes.fetch('revision', 'HEAD')
16
+ lines = attributes.fetch('lines', '')
16
17
 
17
18
  cmd = %(git -C #{repository} show #{revision}:#{target})
18
19
  content = %x(#{cmd})
19
20
 
21
+ content = process_line_selection(content, lines) unless lines == ""
22
+
20
23
  reader.push_include content, target, target, 1, attributes
21
24
  reader
22
25
  end
26
+
27
+ # inspired by https://github.com/tkfu/asciidoctor-github-include/blob/410e0079b2300596ca2b16c94c23c63459e6d0f8/lib/asciidoctor-github-include.rb#LL79C7-L79C29
28
+ def process_line_selection content, lines
29
+ snipped_content = []
30
+ selected_lines = []
31
+ text = content.split(/\n/)
32
+
33
+ lines.split(/[,;]/).each do |linedef|
34
+ if linedef.include?('..')
35
+ from, to = linedef.split('..', 2).map {|it| it.to_i }
36
+ to = text.length if to == -1
37
+ selected_lines.concat ::Range.new(from, to).to_a
38
+ else
39
+ selected_lines << linedef.to_i
40
+ end
41
+ end
42
+ selected_lines.sort.uniq.each do |i|
43
+ snipped_content << text[i-1]
44
+ end
45
+ snipped_content
46
+ end
23
47
  end
24
48
 
25
49
  Asciidoctor::Extensions.register do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-git-include
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Zalas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-30 00:00:00.000000000 Z
11
+ date: 2023-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor