asciidoctor-git-include 1.0.0 → 1.1.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor-git-include.rb +24 -0
  3. metadata +2 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7d8c1b4ad1989815ac1c7d48b5eb38266804cdcae48aeeabc88fba0aaa57995
4
- data.tar.gz: 3facff4687ba1987ea71b12d24f25d0586b969604fea0a5b986b91fa488ada72
3
+ metadata.gz: 5177a48bd23b29740f870018e5603e8677a76105d0991668d851e3e8a9f36ab1
4
+ data.tar.gz: 542dd9ddcae0b7762c5ecb11c5cc9be23d41964bb41033301127b54a61fc885c
5
5
  SHA512:
6
- metadata.gz: bce9989f570a271db90ebdb8914754589f24a79b333e6bceaa96818f68f4921db05dfd8b71cb1a976a14889784c30101d91bb8fb6de7a59d82de44b930248cdc
7
- data.tar.gz: 3dc70bd01f12c4d9a5864ee5911619721664be8e5fa380ccd1fde282411a529bc015b7a50c519306ac6e3ee39e4cc920925150b50b55537ebfeccff1beaff4cc
6
+ metadata.gz: e357995f3f6b3d9a32981c16a65a5b16cc357a3621ca4372b266d5bab19f21005879e6f21a28e6a283635826c5563a2674887d7c02ec9165394f4cd97f5271a8
7
+ data.tar.gz: 74ae0db05208795e6266a62c3740358771e82d241e4348e2e2ed288313a5d5a63949cc4d21f40d92f69c88edffaae5aca494ba2489ca68a8ff0600174c6e2a49
@@ -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.1
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
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.12'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.12'
41
27
  description: Asciidoctor extension for including files from Git repositories
42
28
  email:
43
29
  - jakub@zalas.pl