jekyll_asciidoctor_pdf 0.1.2 → 0.2.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: '09550c635149441d709366d60bf401788a4bb529ebeeb02fb5375019a0c42df4'
4
- data.tar.gz: 872489f640ae593e3c4b0d52cbe0e66a89dbaa0bc8554789605ecdc4d7319bdf
3
+ metadata.gz: 4bab851fad6ffc5d464e79813ce0332c2a8daffb9f9eaa71bade8dc2de0bf9d0
4
+ data.tar.gz: b3d8938359332905113447fd0107e2c0bd2ae37417853b4ab38895c2aea4811a
5
5
  SHA512:
6
- metadata.gz: '092973c75f4944a59174674ffc09bbe7e4244cdf96734c19b3cb7aa81b56f727cc7f8649ff0b08c78c7af0b1db796524da08a4d0354bd37793f2475bb9499179'
7
- data.tar.gz: b22030fa3a38f441788823c881c759f772f51ff872847040cea7f4c27c90235bc682dc6ffc7bb01da8ddca236987b772b640640b977df8f2b4fbd0dd3cb094c5
6
+ metadata.gz: ca508404667608e35385427825f3fe37c3acd9770f57d49ba1abb7294e0132911af6f201b1561b9aa7456169850090ef740253243c88a1ec04f09d25de197454
7
+ data.tar.gz: c1b70827169817232a4a16d3aefcb49b8588e3fc6a3b5c129d68b3bf85b744805b5005fa0a51452bd658f06f1026179aaaff5125665a41a6704909032a22b6b9
@@ -15,9 +15,8 @@ module JekyllAsciidoctorPdf
15
15
  # - Execute the convert process
16
16
  # - Let the caller to collect information from the front_matter and from the file itself
17
17
  #
18
- def self.generatePdf(title, file, output_path, parameters, cover_page, theme_pdf)
18
+ def self.generatePdf(product_name, file, output_path, parameters, cover_page, theme_pdf, revision)
19
19
 
20
- #filename = SafeYAML.load_file(file)
21
20
  front_matter = {}
22
21
 
23
22
  content = File.read(file)
@@ -28,12 +27,15 @@ module JekyllAsciidoctorPdf
28
27
 
29
28
  stream_adoc = content.gsub(YAML_FRONT_MATTER_REGEXP, '')
30
29
 
30
+ # We should think about the performance of get the title in that way
31
+ adoc = Asciidoctor.load stream_adoc
32
+ title = adoc.doctitle
33
+
31
34
  filename = File.basename(file,'.*') + '.pdf'
32
35
  filename_path = output_path
33
- subtitle = 'Page'
34
36
  base_path = File.dirname(file)
35
37
 
36
- generateBookTypePdf(filename, filename_path, title, subtitle, base_path, stream_adoc, parameters, cover_page, theme_pdf)
38
+ generateBookTypePdf(filename, filename_path, product_name, title, base_path, stream_adoc, parameters, cover_page, theme_pdf, revision)
37
39
 
38
40
  yield(front_matter, stream_adoc) if block_given?
39
41
  end
@@ -61,10 +63,10 @@ module JekyllAsciidoctorPdf
61
63
  # e.i image:http://example.org/image.png
62
64
  # (we may want to block this feature is too expensive)
63
65
  #
64
- def self.generateBookTypePdf(filename, filename_path, title, subtitle, base_path, stream_adoc, parameters, cover_page, theme_pdf)
66
+ def self.generateBookTypePdf(filename, filename_path, product_name, title, base_path, stream_adoc, parameters, cover_page, theme_pdf, revision)
65
67
 
66
68
  Asciidoctor.convert(
67
- getFullsiteTemplate(title, subtitle, stream_adoc, parameters, cover_page, theme_pdf),
69
+ getFullsiteTemplate(title, product_name, stream_adoc, parameters, cover_page, theme_pdf, revision),
68
70
  backend: 'pdf',
69
71
  doctype: 'book',
70
72
  to_file: filename,
@@ -81,16 +83,21 @@ module JekyllAsciidoctorPdf
81
83
  #
82
84
  # TODO: Add more configuracion
83
85
  #
84
- def self.getFullsiteTemplate(title, subtitle, fullsite, parameters, cover_page, theme_pdf)
86
+ def self.getFullsiteTemplate(title, product_name, fullsite, parameters, cover_page, theme_pdf, revision)
85
87
  fullsite_config = parameters['fullsite']
86
88
 
87
89
  authors = fullsite_config['authors']
88
- revision = fullsite_config['revision']
90
+
91
+ if (revision.nil?)
92
+ revision_s = DateTime.now.strftime('%m/%d/%Y')
93
+ else
94
+ revision_s = revision.strftime('%m/%d/%Y')
95
+ end
89
96
 
90
97
  text = <<~TEXT
91
- = #{title} : #{subtitle}
98
+ = #{title} : #{product_name}
92
99
  #{authors}
93
- #{revision}
100
+ #{revision_s}
94
101
  :doctype: book
95
102
  :experimental:
96
103
  :reproducible:
@@ -70,7 +70,7 @@ module JekyllAsciidoctorPdf
70
70
 
71
71
  callable_attr :jekyll_config_file, '_config.yml'
72
72
 
73
- callable_attr :fullsite_title, 'NetApp'
73
+ callable_attr :product_name, 'NetApp'
74
74
 
75
75
 
76
76
  ##
@@ -207,6 +207,16 @@ module JekyllAsciidoctorPdf
207
207
  rm_rf(output_assets, quiet)
208
208
  end
209
209
 
210
+
211
+ ##
212
+ # Taken from jekyll-last-modified-at
213
+ #
214
+ def last_modified_at_unix(file)
215
+ last_commit_date = value = %x[ git log -1 --pretty="format:%ct" #{file} ]
216
+ # last_commit_date can be nil iff the file was not committed.
217
+ last_commit_date.nil? || last_commit_date.empty? ? File.mtime(file) : Time.at(last_commit_date.to_i)
218
+ end
219
+
210
220
  ##
211
221
  # Loop over each AsciiDoctor file recursively
212
222
  #
@@ -229,13 +239,16 @@ module JekyllAsciidoctorPdf
229
239
  cd absolute_source_path
230
240
  FileList["**/*.adoc"].each do |file|
231
241
 
242
+ last_modified_at = last_modified_at_unix(file)
243
+
232
244
  output_path = File.join(pdf_pages,File.dirname(file))
233
245
  mkdir_p_if_not_exist(output_path)
234
246
 
235
- JekyllAsciidoctorPdf::ADoc.generatePdf(fullsite_title, file,pdf_pages, parameters, absolute_cover_page, absolute_theme_pdf ) do |front_matter, stream_adoc|
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|
236
249
  if front_matter.key?('permalink')
237
250
  name = File.join('/', front_matter['permalink'])
238
- data = PermalinkData.new(front_matter['sidebar'], stream_adoc, file)
251
+ data = PermalinkData.new(front_matter['sidebar'], stream_adoc, file, last_modified_at)
239
252
  permalinks[name] = data
240
253
  end
241
254
  end
@@ -256,7 +269,7 @@ module JekyllAsciidoctorPdf
256
269
  #
257
270
  # <output_path>
258
271
  # |__ <sidebar>/<section>.pdf -> Section output
259
- # |__ fullsite/fullsite_<sidebar>.pdf -> whole sidebar content (a.k.a. fullsite PDF)
272
+ # |__ fullsite/<sidebar>.pdf -> whole sidebar content (a.k.a. fullsite PDF)
260
273
  #
261
274
  def generate_fullsite_adoc
262
275
 
@@ -267,7 +280,7 @@ module JekyllAsciidoctorPdf
267
280
  name = File.basename(file).ext('')
268
281
 
269
282
  JekyllAsciidoctorPdf::SidebarYAML.new(
270
- fullsite_title,
283
+ product_name,
271
284
  name,
272
285
  file,
273
286
  permalinks,
@@ -7,11 +7,12 @@ module JekyllAsciidoctorPdf
7
7
  # We use to create a dictionary of all permalinks a its content (without frontmatter)
8
8
  #
9
9
  class PermalinkData
10
- attr_reader :sidebar, :content, :filename
11
- def initialize(sidebar, content, filename)
10
+ attr_reader :sidebar, :content, :filename, :last_modified_at
11
+ def initialize(sidebar, content, filename, last_modified_at)
12
12
  @sidebar = sidebar
13
13
  @content = content
14
14
  @filename = filename
15
+ @last_modified_at = last_modified_at
15
16
  end
16
17
  end
17
18
  end
@@ -48,18 +48,18 @@ module JekyllAsciidoctorPdf
48
48
  #
49
49
  class SidebarYAML
50
50
 
51
- attr_reader :title, :name, :file, :permalinks, :parameters, :section_output_path, :sidebar_output_path, :base_path, :cover_page, :theme_pdf
51
+ attr_reader :product_name, :name, :file, :permalinks, :parameters, :section_output_path, :sidebar_output_path, :base_path, :cover_page, :theme_pdf
52
52
 
53
53
 
54
- def initialize(title, name, file, permalinks, parameters, output_path, base_path, cover_page, theme_pdf )
55
- @title = title
56
- @name = name
57
- @file = file
58
- @permalinks = permalinks
59
- @parameters = parameters
60
- @base_path = base_path
61
- @cover_page = cover_page
62
- @theme_pdf = theme_pdf
54
+ def initialize(product_name, name, file, permalinks, parameters, output_path, base_path, cover_page, theme_pdf )
55
+ @product_name = product_name
56
+ @name = name
57
+ @file = file
58
+ @permalinks = permalinks
59
+ @parameters = parameters
60
+ @base_path = base_path
61
+ @cover_page = cover_page
62
+ @theme_pdf = theme_pdf
63
63
 
64
64
  @section_output_path = File.join(output_path,name)
65
65
  @sidebar_output_path = File.join(output_path,'/fullsite')
@@ -139,14 +139,17 @@ module JekyllAsciidoctorPdf
139
139
  node.add_content(":leveloffset: -1 \n")
140
140
  filename = node.title.gsub(/[^0-9A-Z]/i, '_') + '.pdf'
141
141
 
142
- JekyllAsciidoctorPdf::ADoc.generateBookTypePdf(filename, section_output_path, title, node.title, base_path, node.content, parameters, cover_page, theme_pdf)
142
+ JekyllAsciidoctorPdf::ADoc.generateBookTypePdf(filename, section_output_path, product_name, node.title, base_path, node.content, parameters, cover_page, theme_pdf,nil)
143
143
  else
144
144
  # This is the root of the sidebar
145
- subtitle = 'Docs'
145
+ # WARNING: We are assuming too much!. We are getting the title from the first child
146
+ first_child = children[0];
147
+ title = first_child['title']
148
+
146
149
  filename = File.basename(file).ext('.pdf')
147
150
  filename_path = sidebar_output_path
148
151
 
149
- JekyllAsciidoctorPdf::ADoc.generateBookTypePdf(filename, filename_path, title, subtitle, base_path, node.content, parameters, cover_page, theme_pdf)
152
+ JekyllAsciidoctorPdf::ADoc.generateBookTypePdf(filename, filename_path, product_name, title, base_path, node.content, parameters, cover_page, theme_pdf,nil)
150
153
  end
151
154
 
152
155
  return node
@@ -1,3 +1,3 @@
1
1
  module JekyllAsciidoctorPdf
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.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.1.2
4
+ version: 0.2.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-03-25 00:00:00.000000000 Z
11
+ date: 2020-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler