jekyll_asciidoctor_pdf 0.2.1 → 0.3.0

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: 9c7baeda17a015c813d1081ac35e2241af1f6fd722af24a2bbfd45a5067737d5
4
- data.tar.gz: 8e0a31816601b5241e1fb0f95945af92853d9b9fbcea4ac077e767174f01bf02
3
+ metadata.gz: b29afdc7f4b9576e8bd9a63f147add555327c85d5c11ead433b0144dada30efa
4
+ data.tar.gz: 1d99eb123d43e9c41642ca629d968d02a6ffe2a977eb70352ba3f2f6218f0c97
5
5
  SHA512:
6
- metadata.gz: 8e43bc13d66a6b2513e76f7fe731b9b9a607dd0db369f9f63e0229c228d9bd8adbaa34d4d9c5a9bd1d687dc54e768ea04bea74ad02a690fd873052f27b11b9dd
7
- data.tar.gz: a332b9b64a1ae676252cd75d0863244c7afae34c75db5801bc7b0d3f4de55eed06aa81475344c83d65a40eccb6669e39aa0c16870d77944202d84e8fe8225888
6
+ metadata.gz: bd1a561f9f3b6a8498687b395871a7e78b4e5025e5e7fc28e10d3d18eb7c04d2566d6c2811ba81dd3f9594b7d41580a673fcd2a4668d1466af3cefc6258f55c7
7
+ data.tar.gz: b660f73123430215b6a576677609da1167cec6606ae600767a4a02825c5c262a09f42e622629b3808da8cfa17a16f18fe07b2632c0479f5325aacd3c9daaa1dc
data/README.adoc CHANGED
@@ -2,7 +2,7 @@
2
2
  :gem-name: jekyll_asciidoctor_pdf
3
3
  :gh-branch: master
4
4
  :badge-style: flat
5
- :release-version: 0.1.2
5
+ :release-version: 0.3.0
6
6
 
7
7
  image:https://img.shields.io/gem/v/{gem-name}.svg?style={badge-style}[Gem Version, link="https://rubygems.org/gems/{gem-name}"]
8
8
  image:https://travis-ci.com/NetAppDocs/jekyll-asciidoctor-pdf.svg?token=jmKxRqiJdAgY6ceg7i2d&branch=master["Build Status", link="https://travis-ci.com/NetAppDocs/jekyll-asciidoctor-pdf"]
@@ -43,7 +43,9 @@ require 'rake_jekyll_asciidoctor_pdf'
43
43
 
44
44
  RakeJekyllAsciidoctorPdf::BuildTask.new('buildAll') do |t|
45
45
  t.jekyll_config_file = '_config.yml'
46
- t.fullsite_title = ENV['PRODUCT_NAME']
46
+ t.product_name = ENV['PRODUCT_NAME']
47
+ t.repo_name = ENV['REPO_NAME']
48
+ t.git_token = ENV['GH_API_TOKEN']
47
49
  end
48
50
  ----
49
51
 
@@ -124,7 +126,7 @@ A complex directory structure could be like this
124
126
  * Gif files need prawn-gmagick
125
127
  * Absolute URL not supported in the sidebar.yml
126
128
  * Problems with image labels like that
127
- * Problems with interal *links:*
129
+ * Problems with internal *links:*
128
130
  * Unicode characters are not supported by AsciiDocPdf (e.i. ✓)
129
131
 
130
132
  [source,asciidoc]
@@ -144,6 +146,9 @@ image:diagram_networking_cloud.png["service, a"]
144
146
  * [x] Generate a PDF for each section
145
147
  * [ ] Support multiple sidebar.yml like HCI (Partial)
146
148
  * [x] Support basic recursion over directories
149
+ * [x] Add Copyright page
150
+ * [x] Support remote authors information with GitHub API
151
+
147
152
 
148
153
 
149
154
 
@@ -43,6 +43,8 @@ Gem::Specification.new do |spec|
43
43
  spec.add_runtime_dependency 'rake', '>= 10.0'
44
44
  spec.add_runtime_dependency 'fileutils', '>= 1.1'
45
45
  spec.add_runtime_dependency 'safe_yaml', '>= 1.0.5'
46
+ spec.add_runtime_dependency 'json', '>= 2.1.0'
47
+ spec.add_runtime_dependency 'rest-client', '>= 2.0.0'
46
48
  spec.add_runtime_dependency 'asciidoctor-pdf', '>= 1.5.1'
47
49
 
48
50
  end
@@ -25,7 +25,7 @@ module JekyllAsciidoctorPdf
25
25
  # - Execute the convert process
26
26
  # - Let the caller to collect information from the front_matter and from the file itself
27
27
  #
28
- def self.generatePdf(product_name, file, output_path, parameters, cover_page, theme_pdf, revision)
28
+ def self.generatePdf(product_name, file, output_path, parameters, cover_page, theme_pdf, revision, authors)
29
29
 
30
30
  front_matter = {}
31
31
 
@@ -44,7 +44,7 @@ module JekyllAsciidoctorPdf
44
44
  filename = File.basename(file,'.*') + '.pdf'
45
45
  filename_path = output_path
46
46
  base_path = File.dirname(file)
47
- authors = getAuthorsList(file)
47
+ #authors = getAuthorsList(file)
48
48
 
49
49
  generateBookTypePdf(filename, filename_path, product_name, title, base_path, stream_adoc, parameters, cover_page, theme_pdf, revision, authors)
50
50
 
@@ -95,6 +95,8 @@ module JekyllAsciidoctorPdf
95
95
  # TODO: Add more configuracion
96
96
  #
97
97
  def self.getFullsiteTemplate(title, product_name, fullsite, parameters, cover_page, theme_pdf, revision, authors)
98
+
99
+ copyright = getCopyright()
98
100
  fullsite_config = parameters['fullsite']
99
101
 
100
102
  if (authors.nil?)
@@ -135,6 +137,54 @@ module JekyllAsciidoctorPdf
135
137
  :leveloffset: +1
136
138
  #{fullsite}
137
139
  :leveloffset: -1
140
+ #{copyright}
141
+ TEXT
142
+
143
+ return text
144
+ end
145
+
146
+ def self.getCopyright()
147
+ text = <<~TEXT
148
+ <<<
149
+ *Copyright Information*
150
+
151
+ Copyright © 2019–2020 NetApp, Inc. All rights reserved. Printed in the U.S. No part of this document
152
+ covered by copyright may be reproduced in any form or by any means-graphic, electronic, or
153
+ mechanical, including photocopying, recording, taping, or storage in an electronic retrieval system-
154
+ without prior written permission of the copyright owner.
155
+
156
+ Software derived from copyrighted NetApp material is subject to the following license and disclaimer:
157
+
158
+ THIS SOFTWARE IS PROVIDED BY NETAPP “AS IS” AND WITHOUT ANY EXPRESS OR IMPLIED
159
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
160
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WHICH ARE HEREBY
161
+ DISCLAIMED. IN NO EVENT SHALL NETAPP BE LIABLE FOR ANY DIRECT, INDIRECT,
162
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
163
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
164
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
165
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
166
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
167
+ THE POSSIBILITY OF SUCH DAMAGE.
168
+
169
+ NetApp reserves the right to change any products described herein at any time, and without notice.
170
+ NetApp assumes no responsibility or liability arising from the use of products described herein,
171
+ except as expressly agreed to in writing by NetApp. The use or purchase of this product does not
172
+ convey a license under any patent rights, trademark rights, or any other intellectual property
173
+ rights of NetApp.
174
+
175
+ The product described in this manual may be protected by one or more U.S. patents,
176
+ foreign patents, or pending applications.
177
+
178
+ RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the government is subject to
179
+ restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and
180
+ Computer Software clause at DFARS 252.277-7103 (October 1988) and FAR 52-227-19 (June 1987).
181
+
182
+ *Trademark Information*
183
+
184
+
185
+ NETAPP, the NETAPP logo, and the marks listed at http://www.netapp.com/TM are trademarks of
186
+ NetApp, Inc. Other company and product names may be trademarks of their respective owners.
187
+
138
188
  TEXT
139
189
 
140
190
  return text
@@ -7,6 +7,7 @@ require 'fileutils'
7
7
  require 'asciidoctor-pdf'
8
8
  require 'asciidoctor'
9
9
  require 'jekyll_asciidoctor_pdf/adoc'
10
+ require 'jekyll_asciidoctor_pdf/gitinfo'
10
11
  require 'jekyll_asciidoctor_pdf/logger'
11
12
  require 'jekyll_asciidoctor_pdf/sidebar'
12
13
  require 'jekyll_asciidoctor_pdf/permalink'
@@ -65,12 +66,15 @@ module JekyllAsciidoctorPdf
65
66
 
66
67
  attr_reader :absolute_cover_page
67
68
  attr_reader :absolute_theme_pdf
69
+ attr_reader :git_info
68
70
 
69
71
  attr_reader :quiet
70
72
 
71
73
  callable_attr :jekyll_config_file, '_config.yml'
72
74
 
73
75
  callable_attr :product_name, 'NetApp'
76
+ callable_attr :repo_name, ''
77
+ callable_attr :git_token, ''
74
78
 
75
79
 
76
80
  ##
@@ -87,6 +91,7 @@ module JekyllAsciidoctorPdf
87
91
 
88
92
  yield self if block_given?
89
93
 
94
+ @git_info = GitInfo.new(git_token, repo_name)
90
95
  @absolute_config_file = File.join(@absolute_working_path, jekyll_config_file);
91
96
 
92
97
  do_jekyll_config_ok? do |t|
@@ -244,8 +249,9 @@ module JekyllAsciidoctorPdf
244
249
  output_path = File.join(pdf_pages,File.dirname(file))
245
250
  mkdir_p_if_not_exist(output_path)
246
251
 
247
-
248
- JekyllAsciidoctorPdf::ADoc.generatePdf(product_name, file, output_path, parameters, absolute_cover_page, absolute_theme_pdf, last_modified_at ) do |front_matter, stream_adoc|
252
+ authors = git_info.getAuthorsList(file)
253
+
254
+ JekyllAsciidoctorPdf::ADoc.generatePdf(product_name, file, output_path, parameters, absolute_cover_page, absolute_theme_pdf, last_modified_at, authors ) do |front_matter, stream_adoc|
249
255
  if front_matter.key?('permalink')
250
256
  name = File.join('/', front_matter['permalink'])
251
257
  data = PermalinkData.new(front_matter['sidebar'], stream_adoc, file, last_modified_at)
@@ -0,0 +1,142 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+
4
+ module JekyllAsciidoctorPdf
5
+
6
+ ##
7
+ # Abstract structure for a hash dictionary
8
+ #
9
+ # We use to create a dictionary of all github users to avoid multiple requests
10
+ #
11
+ class Gituser
12
+ attr_reader :username, :name
13
+ def initialize(username, name)
14
+ @username = username
15
+ @name = name
16
+ end
17
+ end
18
+
19
+ class GitInfo
20
+ attr_accessor :authors_hash
21
+ attr_accessor :remote
22
+ def initialize(token, repo)
23
+ @authors_hash = Hash.new
24
+ @token = token
25
+ @repo = repo
26
+ if (token.empty? || token.nil?)
27
+ @remote = false
28
+ else
29
+ @remote = true
30
+ end
31
+ end
32
+
33
+
34
+ ##
35
+ # Get the real user name or return the login name
36
+ #
37
+ # Avoid unexpected terminations / Best Effort approach
38
+ #
39
+ def getRealUser(login_name)
40
+ headers = {Authorization: "token #{@token}"}
41
+ uri = "https://api.github.com/users/#{login_name.to_s}"
42
+
43
+ if authors_hash.key?(login_name)
44
+ return authors_hash[login_name]
45
+ end
46
+ begin
47
+ response = RestClient.get(uri, headers)
48
+ if response.code == 200
49
+ userResponse = response.body
50
+ unless userResponse.nil? || userResponse.empty?
51
+ hash = JSON.parse(userResponse)
52
+ if (hash.key?('name'))
53
+ authors_hash[login_name] = hash['name']
54
+ return hash['name']
55
+ end
56
+ end
57
+ else
58
+ puts "Error Code: #{response.code.to_s}"
59
+ end
60
+ rescue => e
61
+ puts "Error Message: #{e.to_s}"
62
+ end
63
+ return login_name
64
+ end
65
+
66
+
67
+ ##
68
+ # List of contributors order by commits
69
+ #
70
+ # Avoid unexpected terminations / Best Effort approach
71
+ #
72
+ def getContributors(file)
73
+ headers = {Authorization: "token #{@token}"}
74
+ uri = "https://api.github.com/repos/#{@repo}/commits?path=#{file.to_s}"
75
+
76
+ contributors = Hash.new;
77
+ begin
78
+ response = RestClient.get(uri, headers)
79
+ if response.code == 200
80
+ responseBody = response.body;
81
+
82
+ unless responseBody.nil? || responseBody.empty?
83
+ commits = JSON.parse(responseBody);
84
+ if commits.nil? || commits.empty?
85
+ puts "Warning: Unable to find contributors for page in github repository.";
86
+ else
87
+ commits.each do |commit|
88
+ author = commit['author']
89
+ name = getRealUser(author["login"])
90
+ if contributors.key?(name)
91
+ contributors[name] = contributors[name] + 1;
92
+ else
93
+ contributors[name] = 1;
94
+ end
95
+ end
96
+ end
97
+ end
98
+ else
99
+ puts "Warning: Invalid Response code received for page: #{uri.to_s}. Response headers set to #{response.headers.to_str}";
100
+ end
101
+ rescue => e
102
+ puts "Error Message: #{e.to_s}";
103
+ end
104
+
105
+ authors = contributors.sort_by{|name, commits| [-commits, name]}.transpose[0]
106
+
107
+ if (authors.nil? || authors.empty? )
108
+ return 'NetApp'
109
+ end
110
+
111
+ return authors.join(', ')
112
+ end
113
+
114
+ ##
115
+ # Get authors information from git log
116
+ #
117
+ def getContributorsWithoutGithubToken(file)
118
+ names = %x[ git log --pretty=format:"%an" #{file} | sort | uniq ]
119
+ # last_commit_date can be nil iff the file was not committed.
120
+ if (names.nil? || names.empty?)
121
+ return 'NetApp'
122
+ end
123
+
124
+ return names.split(/\n+/).join(', ')
125
+ end
126
+
127
+
128
+ ##
129
+ # Get authors information
130
+ #
131
+ def getAuthorsList(file)
132
+ if (remote)
133
+ return getContributors(file);
134
+ else
135
+ return getContributorsWithoutGithubToken(file);
136
+ end
137
+ end
138
+
139
+ end
140
+
141
+ end
142
+
@@ -1,3 +1,3 @@
1
1
  module JekyllAsciidoctorPdf
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_asciidoctor_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guido Genzone
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-02 00:00:00.000000000 Z
11
+ date: 2020-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.0.5
97
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 2.1.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.1.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rest-client
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 2.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 2.0.0
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: asciidoctor-pdf
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -126,6 +154,7 @@ files:
126
154
  - lib/jekyll_asciidoctor_pdf.rb
127
155
  - lib/jekyll_asciidoctor_pdf/adoc.rb
128
156
  - lib/jekyll_asciidoctor_pdf/commands.rb
157
+ - lib/jekyll_asciidoctor_pdf/gitinfo.rb
129
158
  - lib/jekyll_asciidoctor_pdf/logger.rb
130
159
  - lib/jekyll_asciidoctor_pdf/permalink.rb
131
160
  - lib/jekyll_asciidoctor_pdf/sidebar.rb