pbsimply 3.0.1 → 3.1.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pbsimply/hooks.rb +32 -3
  3. data/lib/pbsimply.rb +11 -6
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8646259ef8d789b45379e1a72d861f96dc6d17b7c11fb5a8efd8211abed803f2
4
- data.tar.gz: 26624a779547dd0620130266dfad5bfebf0c23c65b3e6d4c2d6e2f937dc81b87
3
+ metadata.gz: 5c2cee1a598dad5d08c823c51768afebae4d8e0459b3507658ca10a613c33bc4
4
+ data.tar.gz: c13273c93cc68212ad5bb72b785dc01a640415c03bc5be98faccee449f8c54ee
5
5
  SHA512:
6
- metadata.gz: 6f80e3b59ec6a78e9630602d4090af1ae1b5b444946fb638c6e60bbb1e47f3c6ee9c0f8e9869c82321d0db4884622cedd57fd1c24aff12a7675942fb7b2fc495
7
- data.tar.gz: 57d20e28c25f2eb944d61557a63321ae4799b17e135ede66321a6957598a531c858b27ff80350b33a4295721b3962dfe38f046dbdc599440644aea8653171da6
6
+ metadata.gz: 1e90c599fc508e0e44aa1e882dca4de285f150dde10eecfaf7c22d20ca674cd4b29be5ace1a139a8fe36b5581afd1d81438c168c2823739a0ef1ddfbeacf1116
7
+ data.tar.gz: e0a079093ca72cc0575b7858a687e838a8c848ff9c9eff036cba99e7678ee9de4f098890d619e1b5078049252f4b277bb20fc09c50d4db0488c4fb148e88ed58
@@ -16,7 +16,17 @@ class PBSimply::Hooks
16
16
  @hooks << proc
17
17
  end
18
18
 
19
- alias :add :<<
19
+ def add(&proc)
20
+ @hooks << proc
21
+ end
22
+
23
+ # Invoke command updating files
24
+ def cmd(*cmdarg)
25
+ proc = ->(arg) do
26
+ system(*cmdarg)
27
+ end
28
+ self << proc
29
+ end
20
30
 
21
31
  def run(arg)
22
32
  STDERR.puts "Hooks processing (#{@name})"
@@ -32,14 +42,32 @@ class PBSimply::Hooks
32
42
  end
33
43
  end
34
44
 
45
+ # Timing Object for pre, process
46
+ class HooksHolderPre < HooksHolder
47
+ # Invoke command as filter.
48
+ def filter(*cmdarg)
49
+ proc = ->(arg) do
50
+ IO.popen(cmdarg, "w+") do |io|
51
+ io.print File.read ENV["pbsimply_currentdoc"]
52
+ io.close_write
53
+ File.open(ENV["pbsimply_currentdoc"], "w") do |f|
54
+ f.write io.read
55
+ end
56
+ end
57
+ end
58
+ self << proc
59
+ end
60
+ end
61
+
35
62
  def initialize(pbsimply)
36
63
  @pbsimply = pbsimply
64
+ @hooks_loaded = false
37
65
 
38
66
  # Called first phase before generate. This hooks called before blessing.
39
67
  #
40
68
  # Argument: frontmatter, procdoc.
41
69
  # procdoc is processing source document path.
42
- @pre = HooksHolder.new "pre"
70
+ @pre = HooksHolderPre.new "pre"
43
71
 
44
72
  # Called after document was generated.
45
73
  #
@@ -73,7 +101,8 @@ class PBSimply::Hooks
73
101
  def load
74
102
  if File.file?("./.pbsimply-hooks.rb")
75
103
  require './.pbsimply-hooks.rb'
76
- PBSimply::Hooks.load_hooks(self)
104
+ PBSimply::Hooks.load_hooks(self) unless @hooks_loaded
105
+ @hooks_loaded = true
77
106
  end
78
107
  end
79
108
 
data/lib/pbsimply.rb CHANGED
@@ -201,6 +201,8 @@ class PBSimply
201
201
  # Push to target documents without checking modification.
202
202
  target_docs.push([filename, frontmatter, pos])
203
203
  end
204
+ ENV.delete("pbsimply_currentdoc")
205
+ ENV.delete("pbsimply_filename")
204
206
 
205
207
  delete_turn_draft draft_articles
206
208
 
@@ -236,6 +238,8 @@ class PBSimply
236
238
  # Proccess documents
237
239
  target_docs.each do |filename, frontmatter, pos|
238
240
  ext = File.extname filename
241
+ ENV["pbsimply_currentdoc"] = File.join(@workdir, "current_document#{ext}")
242
+ ENV["pbsimply_filename"] = filename
239
243
  @index = frontmatter
240
244
  File.open(File.join(@dir, filename)) do |f|
241
245
  f.seek(pos)
@@ -396,21 +400,22 @@ class PBSimply
396
400
  modify = false if frontmatter["changes"] == index["changes"]
397
401
  when "mtimesize"
398
402
  # Use mtime and file size.
399
- modify = false if frontmatter["_mtime"] <= frontmatter["_last_proced"] && frontmatter["_size"] == index["_size"]
403
+ modify = false if frontmatter["_mtime"] <= (index["_last_proced"] || 0) && frontmatter["_size"] == index["_size"]
400
404
  else
401
405
  # Default method, use mtime.
402
- modify = false if frontmatter["_mtime"] <= frontmatter["_last_proced"]
406
+ modify = false if frontmatter["_mtime"] <= (index["_last_proced"] || 0)
403
407
  end
404
408
 
405
409
 
406
410
  if modify
407
- STDERR.puts "#{path[1]} last modified at #{frontmatter["_mtime"]}, last processed at #{@indexes_orig[path[1]]&.[]("_last_proced") || 0}"
408
- frontmatter["_last_proced"] = @now.to_i
409
- frontmatter["last_update"] = @now.strftime("%Y-%m-%d %H:%M:%S")
411
+ STDERR.puts "#{filename} last modified at #{frontmatter["_mtime"]}, last processed at #{@indexes_orig[filename]&.[]("_last_proced") || 0}"
410
412
  else
411
- STDERR.puts "#{path[1]} is not modified."
413
+ STDERR.puts "#{filename} is not modified."
412
414
  end
413
415
 
416
+ frontmatter["_last_proced"] = @now.to_i
417
+ frontmatter["last_update"] = @now.strftime("%Y-%m-%d %H:%M:%S")
418
+
414
419
  if @refresh
415
420
  # Refresh (force update) mode.
416
421
  true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pbsimply
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Haruka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-15 00:00:00.000000000 Z
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Pre compile, static serving website builder.
14
14
  email: