gem_docs 0.4.0 → 0.4.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.
- checksums.yaml +4 -4
- data/lib/gem_docs/badge.rb +21 -24
- data/lib/gem_docs/emacs.rb +7 -1
- data/lib/gem_docs/header.rb +17 -2
- data/lib/gem_docs/skeleton.rb +1 -1
- data/lib/gem_docs/tasks.rb +1 -1
- data/lib/gem_docs/version.rb +1 -1
- data/lib/gem_docs.rb +98 -7
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 766622a7e98d51da26731a84ebec1df8ac860e8ac4bf3bde8e27d16005320200
|
|
4
|
+
data.tar.gz: df6f41e202078bb67817deb9340bfe2f208061c071ff423b729a079c5e90224b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 737ce19b973ebe32963fd7294c1480552d790fe9c8ef3b72b935400b959d608261ef7a400e6c86acedabfd9255170637b02668d51e8792e32779528b64384712
|
|
7
|
+
data.tar.gz: 63cb5740fa77028f19f8e0dfbf7edd6a0e6bfe62d47578960002ef0cdb75827a304c15169f431cc2c74d1a2a5b3295b0358721375ab69567e4e03d625231f7be
|
data/lib/gem_docs/badge.rb
CHANGED
|
@@ -53,34 +53,31 @@ module GemDocs
|
|
|
53
53
|
File.write(README_ORG, updated)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
#
|
|
57
|
-
#
|
|
56
|
+
# Newly generated metadata precedes Org's TOC. Explicit TOC locations
|
|
57
|
+
# and #badge markers remain under the author's control.
|
|
58
58
|
def insert_after_header(content, block)
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
header = content[/\A(?:#\+(?!(?:TOC:|BEGIN_))[^\n]*(?:\n|\z))*/i]
|
|
60
|
+
body = content.delete_prefix(header)
|
|
61
|
+
version = body[/\A\s*# gem_docs:version begin\n.*?^# gem_docs:version end\n?/m].to_s
|
|
62
|
+
body = body.delete_prefix(version)
|
|
63
|
+
toc = ''
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
elsif in_header && !line.match?(/\A\s*\#\+/)
|
|
69
|
-
in_header = false
|
|
70
|
-
block_added = true
|
|
71
|
-
if line.match?(/\A\s*\z/)
|
|
72
|
-
line + block + "\n\n"
|
|
73
|
-
else
|
|
74
|
-
"\n" + block + "\n\n" + line
|
|
75
|
-
end
|
|
76
|
-
elsif !in_header && !block_added
|
|
77
|
-
block_added = true
|
|
78
|
-
block + "\n\n" + line
|
|
79
|
-
else
|
|
80
|
-
line
|
|
65
|
+
unless content.match?(/^#\+TOC:/i)
|
|
66
|
+
depth = nil
|
|
67
|
+
header = header.gsub(/^#\+OPTIONS:.*$/i) do |line|
|
|
68
|
+
line.gsub(/(?<=\s)toc:(\S+)/i) do
|
|
69
|
+
depth = Regexp.last_match(1)
|
|
70
|
+
'toc:nil'
|
|
81
71
|
end
|
|
72
|
+
end
|
|
73
|
+
unless depth&.casecmp?('nil')
|
|
74
|
+
header += "#+OPTIONS: toc:nil\n" unless depth
|
|
75
|
+
toc = "#+TOC: headlines#{" #{depth}" if depth&.match?(/\A\d+\z/)}\n\n"
|
|
76
|
+
end
|
|
82
77
|
end
|
|
83
|
-
|
|
78
|
+
|
|
79
|
+
header + "\n" + block.rstrip + "\n\n" +
|
|
80
|
+
(version.empty? ? '' : version.strip + "\n\n") + toc + body.sub(/\A(?:[ \t]*\n)*/, '')
|
|
84
81
|
end
|
|
85
82
|
|
|
86
83
|
def insert_at_marker(marker, content, block)
|
data/lib/gem_docs/emacs.rb
CHANGED
|
@@ -16,8 +16,14 @@ module GemDocs
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
expr = <<~ELISP
|
|
19
|
-
(with-current-buffer (
|
|
19
|
+
(with-current-buffer (or (get-file-buffer #{path.dump})
|
|
20
|
+
(find-file-noselect #{path.dump}))
|
|
21
|
+
(unless (verify-visited-file-modtime (current-buffer))
|
|
22
|
+
(if (buffer-modified-p)
|
|
23
|
+
(error "README.org changed on disk and has unsaved Emacs edits; reconcile them before running docs:tangle")
|
|
24
|
+
(revert-buffer t t)))
|
|
20
25
|
(save-buffer)
|
|
26
|
+
(org-set-regexps-and-options)
|
|
21
27
|
(require 'ob-ruby)
|
|
22
28
|
(let ((eligible nil))
|
|
23
29
|
(let ((org-confirm-babel-evaluate nil))
|
data/lib/gem_docs/header.rb
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module GemDocs
|
|
4
4
|
module Header
|
|
5
|
-
PROPERTY_RE = /^#\+PROPERTY:\s+header-args:ruby/
|
|
5
|
+
PROPERTY_RE = /^#\+PROPERTY:\s+header-args:ruby\+?(?:\s|$)/i
|
|
6
6
|
|
|
7
7
|
# @return String The overview from README per config
|
|
8
8
|
def self.write_header?
|
|
9
|
-
return
|
|
9
|
+
return write_ruby_command? if present?
|
|
10
10
|
|
|
11
11
|
prelim, body = extract_prelim_body
|
|
12
12
|
new_org = prelim.join.strip + "\n" + org_headers.strip + "\n\n" + body.join
|
|
@@ -32,6 +32,21 @@ module GemDocs
|
|
|
32
32
|
class << self
|
|
33
33
|
private
|
|
34
34
|
|
|
35
|
+
# Add only the missing interpreter default; retain all author overrides.
|
|
36
|
+
def write_ruby_command?
|
|
37
|
+
prelim, body = extract_prelim_body
|
|
38
|
+
headers = prelim.grep(/^#\+PROPERTY:\s+header-args(?:\:ruby)?\+?\s/i)
|
|
39
|
+
return false if headers.any? { |line| line.match?(/\s:ruby\s/) }
|
|
40
|
+
|
|
41
|
+
command = GemDocs.config.headers[/\s:ruby\s+("[^"]*"|'[^']*'|\S+)/, 1]
|
|
42
|
+
return false unless command
|
|
43
|
+
|
|
44
|
+
updated = prelim.join
|
|
45
|
+
updated += "\n" unless updated.end_with?("\n")
|
|
46
|
+
updated += "#+PROPERTY: header-args:ruby+ :ruby #{command}\n"
|
|
47
|
+
File.write(README_ORG, updated + body.join) > 0
|
|
48
|
+
end
|
|
49
|
+
|
|
35
50
|
# Returns the preliminary comment, blank, and header lines from README.org
|
|
36
51
|
def extract_prelim_body
|
|
37
52
|
prelim = []
|
data/lib/gem_docs/skeleton.rb
CHANGED
|
@@ -59,7 +59,7 @@ module GemDocs
|
|
|
59
59
|
content.sub(VERSION_BLOCK_RE, block)
|
|
60
60
|
else
|
|
61
61
|
# Keep the version below the initial Org metadata and near the CI badge.
|
|
62
|
-
header = content[/\A(?:#\+[^\n]*\n)*/]
|
|
62
|
+
header = content[/\A(?:#\+(?!(?:TOC:|BEGIN_))[^\n]*\n)*/i]
|
|
63
63
|
header + "\n" + block + "\n" + content.delete_prefix(header)
|
|
64
64
|
end
|
|
65
65
|
return false if File.exist?(README_ORG) && updated == content
|
data/lib/gem_docs/tasks.rb
CHANGED
data/lib/gem_docs/version.rb
CHANGED
data/lib/gem_docs.rb
CHANGED
|
@@ -42,12 +42,41 @@ require "fileutils"
|
|
|
42
42
|
# - generating yard documents for your repo, and
|
|
43
43
|
# - copying the introductory contents of the README as a leading comment in your
|
|
44
44
|
# main gem library file so it gets picked up as an overview for ~ri~ and ~yri~
|
|
45
|
-
#
|
|
46
45
|
# * Usage
|
|
46
|
+
# ** Check documentation setup: ~rake docs:doctor~
|
|
47
|
+
# Run the advisory doctor before generating documentation:
|
|
48
|
+
#
|
|
49
|
+
# #+begin_src sh :eval no
|
|
50
|
+
# bundle exec rake docs:doctor
|
|
51
|
+
# #+end_src
|
|
52
|
+
#
|
|
53
|
+
# The doctor suggests improvements for missing or empty configured overview
|
|
54
|
+
# sections, Ruby example headers, missing or stale version markers, missing or
|
|
55
|
+
# possibly stale Markdown exports, and YARD configuration and generated files.
|
|
56
|
+
# It uses ~c.overview_headings~ (by default, ~["Introduction"]~); to use an
|
|
57
|
+
# existing top-level ~Overview~ section, configure:
|
|
58
|
+
#
|
|
59
|
+
# #+begin_src ruby :eval no
|
|
60
|
+
# GemDocs.configure do |c|
|
|
61
|
+
# c.overview_headings = ["Overview"]
|
|
62
|
+
# end
|
|
63
|
+
# #+end_src
|
|
64
|
+
#
|
|
65
|
+
# This is a read-only, advisory task with no generation prerequisites. It does
|
|
66
|
+
# not start Emacs or execute examples, and suggestions do not make the task
|
|
67
|
+
# fail. Header checks are static suggestions, not full Org validation: inherited
|
|
68
|
+
# and per-block settings may intentionally differ. READMEs without Ruby examples
|
|
69
|
+
# do not receive Ruby-header suggestions. Export freshness uses file timestamps;
|
|
70
|
+
# it does not prove that saved example results are current.
|
|
71
|
+
#
|
|
47
72
|
# ** Create a skeleton README.org file
|
|
48
73
|
# This is a simple task that creates a bare-bones ~README.org~ file to get
|
|
49
74
|
# started with. It does create the file with the name of the gem and other repo
|
|
50
|
-
#
|
|
75
|
+
# details filled in. The task also inserts or refreshes a version block near
|
|
76
|
+
# the top using the consuming gem's gemspec version, preserving existing content.
|
|
77
|
+
# This version is refreshed by ~docs:export~ and ~docs:all~ as well.
|
|
78
|
+
# New skeletons include the configured code-block headers, defaulting to
|
|
79
|
+
# ~:eval never-export~. Existing README headers are preserved.
|
|
51
80
|
#
|
|
52
81
|
# #+begin_src ruby :eval no
|
|
53
82
|
# rake docs:skeleton:readme
|
|
@@ -71,13 +100,17 @@ require "fileutils"
|
|
|
71
100
|
# #+end_src
|
|
72
101
|
#
|
|
73
102
|
# By default, the ~gem_docs~ ~rake docs:headers~ task will add the following
|
|
74
|
-
# headers to the top of your ~README.org~ file.
|
|
75
|
-
#
|
|
103
|
+
# headers to the top of your ~README.org~ file. Existing Ruby headers are
|
|
104
|
+
# preserved, with one migration: if no file-level ~:ruby~ interpreter is set,
|
|
105
|
+
# the configured interpreter (by default ~"bundle exec irb"~) is appended.
|
|
106
|
+
# Explicit interpreters and per-block overrides remain in control. A custom
|
|
107
|
+
# header configuration without ~:ruby~ opts out of this migration.
|
|
76
108
|
#
|
|
77
109
|
# #+begin_example
|
|
78
110
|
# #+PROPERTY: header-args:ruby :results value :colnames no :hlines yes :exports both :dir "./"
|
|
79
|
-
# #+PROPERTY: header-args:ruby+ :wrap example :session gem_docs_session
|
|
111
|
+
# #+PROPERTY: header-args:ruby+ :wrap example :session gem_docs_session :eval never-export
|
|
80
112
|
# #+PROPERTY: header-args:ruby+ :prologue "$:.unshift('./lib') unless $:.first == './lib'; require '%n'"
|
|
113
|
+
# #+PROPERTY: header-args:ruby+ :ruby "bundle exec irb"
|
|
81
114
|
# #+PROPERTY: header-args:sh :exports code :eval no
|
|
82
115
|
# #+PROPERTY: header-args:bash :exports code :eval no
|
|
83
116
|
# #+end_example
|
|
@@ -205,6 +238,41 @@ require "fileutils"
|
|
|
205
238
|
# `docs:tangle` kills any existing session buffer before it runs so that each
|
|
206
239
|
# buffer evaluation is independent of earlier runs.
|
|
207
240
|
#
|
|
241
|
+
# ~docs:tangle~ first runs ~docs:headers~ and refreshes Org's cached header
|
|
242
|
+
# properties before checking or executing blocks. Unmodified open buffers are
|
|
243
|
+
# reloaded when the file changes on disk. Conflicting unsaved Emacs edits cause
|
|
244
|
+
# an error so neither version is silently overwritten. Bundled IRB uses the
|
|
245
|
+
# project's dependencies; this does not repair inf-ruby's version parser if
|
|
246
|
+
# the bundled interpreter itself prints warnings before its version.
|
|
247
|
+
#
|
|
248
|
+
# If there are no executable blocks, ~docs:tangle~ skips execution. If blocks
|
|
249
|
+
# are present, Org resolves inherited and per-block headers; when all blocks
|
|
250
|
+
# disable evaluation with ~:eval no~ or ~:eval never~, the existing session is
|
|
251
|
+
# left alone. Blocks that override those headers are still evaluated.
|
|
252
|
+
#
|
|
253
|
+
# The default ~:eval never-export~ executes examples with ~docs:tangle~ and
|
|
254
|
+
# reuses saved results during ~docs:export~, avoiding double execution in
|
|
255
|
+
# ~docs:all~. After editing examples, run ~docs:tangle~ before exporting, or
|
|
256
|
+
# run ~docs:all~, to refresh their results. Existing READMEs retain their
|
|
257
|
+
# headers; change ~:eval yes~ to ~:eval never-export~ to adopt this behavior.
|
|
258
|
+
#
|
|
259
|
+
# Execution and export fail on Emacs errors or interactive confirmation prompts
|
|
260
|
+
# instead of silently succeeding or waiting for a hidden prompt. Resolve
|
|
261
|
+
# confirmation requests in Emacs before retrying; ~:eval query~ blocks must be
|
|
262
|
+
# run interactively or have their evaluation policy changed explicitly.
|
|
263
|
+
#
|
|
264
|
+
# Each Emacs call has a 120-second timeout. For longer examples, configure:
|
|
265
|
+
#
|
|
266
|
+
# #+begin_src ruby :eval no
|
|
267
|
+
# GemDocs.configure do |c|
|
|
268
|
+
# c.emacs_timeout = 300
|
|
269
|
+
# end
|
|
270
|
+
# #+end_src
|
|
271
|
+
#
|
|
272
|
+
# The timeout stops Rake from waiting and attempts to interrupt the operation in
|
|
273
|
+
# Emacs. It cannot guarantee that code running in the shared Emacs server has
|
|
274
|
+
# stopped. Inspect Emacs and any running session before retrying a timed-out task.
|
|
275
|
+
#
|
|
208
276
|
# ** Ensure that a Badge is Present in ~README.md~: ~rake docs:badge~
|
|
209
277
|
# It is reassuring to consumers of your gem that your gem passes its workflow
|
|
210
278
|
# tests on github. This task checks to see if a "badge" indicating success or
|
|
@@ -215,10 +283,33 @@ require "fileutils"
|
|
|
215
283
|
# special comment ~#badge~ where you want the badge located and the task will
|
|
216
284
|
# place it there.
|
|
217
285
|
#
|
|
218
|
-
#
|
|
219
|
-
#
|
|
286
|
+
# When inserting a badge automatically, the task places it and the managed
|
|
287
|
+
# version block before the table of contents. It converts an automatic TOC to
|
|
288
|
+
# an explicit ~#+TOC:~ directive, preserving its depth. A disabled TOC stays
|
|
289
|
+
# disabled; explicit TOC locations and ~#badge~ markers are preserved.
|
|
290
|
+
#
|
|
291
|
+
# An existing badge is left alone. The task also inserts or refreshes the
|
|
292
|
+
# managed version block from the gemspec through ~docs:skeleton:readme~.
|
|
220
293
|
#
|
|
221
294
|
# ** Export ~README.org~ and ~CHANGELOG.org~ to Markdown: ~rake docs:export~
|
|
295
|
+
# Generated ~README.md~ files start with this hidden ownership marker:
|
|
296
|
+
#
|
|
297
|
+
# #+begin_example
|
|
298
|
+
# <!-- Generated by gem_docs -->
|
|
299
|
+
# #+end_example
|
|
300
|
+
#
|
|
301
|
+
# An existing ~README.md~ without that exact first line is protected: export
|
|
302
|
+
# fails without changing it. This includes handwritten Markdown and files
|
|
303
|
+
# exported by older gem_docs versions. To adopt an older generated README,
|
|
304
|
+
# review and back it up, then explicitly add the marker as its first line.
|
|
305
|
+
# Do not add it to a README you intend to maintain by hand.
|
|
306
|
+
#
|
|
307
|
+
# ~docs:all~ and ~docs:export~ check this before their generation prerequisites.
|
|
308
|
+
# The README exporter also checks directly, writes to a temporary file, and
|
|
309
|
+
# replaces the destination only after a successful export. ~docs:doctor~ explains
|
|
310
|
+
# when a README is protected. This policy applies to ~README.md~; changelog
|
|
311
|
+
# export behavior is unchanged.
|
|
312
|
+
#
|
|
222
313
|
# You can write the ~README~ in Emacs org-mode, using all its features
|
|
223
314
|
# including the execution of code blocks, and then export to git-flavored
|
|
224
315
|
# markdown.
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gem_docs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel E. Doherty
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-11-23 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rake
|