gem_docs 0.1.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46cf522895c0d4958b6547d69fbb1f28146d6981b2c73ba448be8a12c05ed407
4
- data.tar.gz: dfc8f1ff2ce78bb680ddaeb0384718a47d80b7aa718a17ce5fef678f630c4957
3
+ metadata.gz: 5e1d29bbce836d7be31883f9748134af47f3c2d6e160b35639f7195cf3ab23d6
4
+ data.tar.gz: f01a2d4a987020c7dad7f18a3d4ebd3145c2326d069ad9b3b5e20348e6b56d4e
5
5
  SHA512:
6
- metadata.gz: 3d419c689f20a889a207d27cc16c8552611d5e150e1672921bf934f3f83edefb61aad9aa5792138984f6b147fdfa5b2b5939a902dd3920d097ca0173369cc722
7
- data.tar.gz: b938002904d804b90c6eb96374adac93ff60ee4d23e08b47ccdd29ea27ac81684c90be6d3e5d22e00c68943f0d84ba493453905b278a4b4c519b9ed737575c95
6
+ metadata.gz: 2163336ebab1ea2d2e7eed04b98aa8f2bb6da856a3184342fcb6e6d675e73a131fe6eeaf5707ddae1e35681c873d31044f85cf9c0c90f9ccb8d94972f32adbfa
7
+ data.tar.gz: 41f5ca7c522e9fd18d462e1b5f9a5a020e6a0ee4a5cbeab645b93c76b8342c37cf2064acf27eae6d657497485a036ca9a8502cf9b314bf13e3dc3a32764737a7
@@ -20,6 +20,7 @@ module GemDocs
20
20
  #+PROPERTY: header-args:ruby :results value :colnames no :hlines yes :exports both :dir "./"
21
21
  #+PROPERTY: header-args:ruby+ :wrap example :session %n_session :eval yes
22
22
  #+PROPERTY: header-args:ruby+ :prologue "$:.unshift('./lib') unless $:.first == './lib'; require '%n'"
23
+ #+PROPERTY: header-args:ruby+ :ruby "bundle exec irb"
23
24
  #+PROPERTY: header-args:sh :exports code :eval no
24
25
  #+PROPERTY: header-args:bash :exports code :eval no
25
26
  HEADER
@@ -3,9 +3,10 @@
3
3
  module GemDocs
4
4
  module Emacs
5
5
  def self.tangle
6
- # ensure_saved
7
6
  expr = <<~ELISP
8
7
  (save-window-excursion
8
+ (if (get-buffer "#{session_name}")
9
+ (kill-buffer "#{session_name}"))
9
10
  (with-current-buffer (find-file-noselect "#{README_ORG}")
10
11
  (save-buffer)
11
12
  (require 'ob-ruby)
@@ -14,24 +15,43 @@ module GemDocs
14
15
  "OK"))
15
16
  ELISP
16
17
 
17
- if system("emacsclient", "--quiet", "--eval", expr)
18
- FileUtils.touch(STAMP)
19
- else
18
+ unless system("emacsclient", "--quiet", "--eval", expr)
20
19
  abort "Babel execution failed"
21
20
  end
22
21
  end
23
22
 
24
- def self.export
25
- # ensure_saved
23
+ def self.export_readme
26
24
  expr = <<~ELISP
27
25
  (save-window-excursion
28
26
  (with-current-buffer (find-file-noselect "#{README_ORG}")
29
27
  (save-buffer)
30
28
  (require 'ox-gfm)
31
- (org-gfm-export-to-markdown)))
29
+ (org-gfm-export-to-markdown))
30
+ (with-current-buffer (find-file-noselect "#{CHANGELOG_ORG}")
31
+ (save-buffer)
32
+ (require 'ox-gfm)
33
+ (org-gfm-export-to-markdown))
34
+ "Export README complete")
32
35
  ELISP
33
36
 
34
37
  system("emacsclient", "--quiet", "--eval", expr)
35
38
  end
39
+
40
+ def self.export_changelog
41
+ expr = <<~ELISP
42
+ (save-window-excursion
43
+ (with-current-buffer (find-file-noselect "#{CHANGELOG_ORG}")
44
+ (save-buffer)
45
+ (require 'ox-gfm)
46
+ (org-gfm-export-to-markdown))
47
+ "Export CHANGELOG complete")
48
+ ELISP
49
+
50
+ system("emacsclient", "--quiet", "--eval", expr)
51
+ end
52
+
53
+ def self.session_name
54
+ "*#{Repo.from_gemspec.name}_session*"
55
+ end
36
56
  end
37
57
  end
@@ -18,6 +18,17 @@ module GemDocs
18
18
  prelim.any? { |h| h.match?(PROPERTY_RE) }
19
19
  end
20
20
 
21
+ def self.org_headers
22
+ repo = Repo.from_gemspec
23
+ GemDocs.config.headers
24
+ .gsub('%n', repo.name)
25
+ .gsub('%h', repo.host)
26
+ .gsub('%u', repo.user)
27
+ .gsub('%r', repo.root)
28
+ .gsub('%b', repo.branch)
29
+ .gsub('%w', repo.workflow)
30
+ end
31
+
21
32
  class << self
22
33
  private
23
34
 
@@ -38,17 +49,6 @@ module GemDocs
38
49
  end
39
50
  [prelim, body]
40
51
  end
41
-
42
- def org_headers
43
- repo = Repo.from_gemspec
44
- GemDocs.config.headers
45
- .gsub('%n', repo.name)
46
- .gsub('%h', repo.host)
47
- .gsub('%u', repo.user)
48
- .gsub('%r', repo.root)
49
- .gsub('%b', repo.branch)
50
- .gsub('%w', repo.workflow)
51
- end
52
52
  end
53
53
  end
54
54
  end
@@ -2,11 +2,9 @@
2
2
 
3
3
  module GemDocs
4
4
  module Skeleton
5
- PROPERTY_RE = /^#\+PROPERTY:\s+header-args:ruby/
6
-
7
5
  # @return String The overview from README per config
8
6
  def self.make_readme?
9
- return false if present?
7
+ return false if readme_present?
10
8
 
11
9
  repo = Repo.from_gemspec
12
10
  content = <<~SKEL
@@ -47,8 +45,31 @@ module GemDocs
47
45
  File.write(README_ORG, content) > 0
48
46
  end
49
47
 
50
- def self.present?
48
+ def self.readme_present?
51
49
  File.exist?(README_ORG)
52
50
  end
51
+
52
+ def self.make_changelog?
53
+ return false if changelog_present?
54
+
55
+ content = <<~SKEL
56
+ * COMMENT CHANGELOG tips:
57
+ 1. Don't dump your git change logs into this file, write them yourself.
58
+ 2. Keep entries short and user-focused,
59
+ 3. Use non-technical language, but do speak in the vocabulary of your gem.
60
+ 4. Don't document changes only of interest to the programmers, just those the
61
+ user would find useful.
62
+ 5. Give each heading a version number and an inactive date (C-c ! is useful here).
63
+
64
+ * Version 0.3.0 [2025-12-27 Sat]
65
+ - First change
66
+ - Second change
67
+ SKEL
68
+ File.write(CHANGELOG_ORG, content) > 0
69
+ end
70
+
71
+ def self.changelog_present?
72
+ File.exist?(CHANGELOG_ORG)
73
+ end
53
74
  end
54
75
  end
@@ -1,35 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GemDocs
4
- extend Rake::DSL
5
-
6
- STAMP = ".tangle-stamp"
7
-
8
4
  def self.install
9
5
  extend Rake::DSL
10
6
 
11
- # README.org → README.md when README.org is newer
12
7
  file README_MD => README_ORG do
13
8
  print "Exporting \"#{README_ORG}\" → "
14
- GemDocs::Emacs.export
9
+ GemDocs::Emacs.export_readme
15
10
  end
16
11
 
17
- # Evaluate code blocks only when README.org changes
18
- file STAMP => README_ORG do
19
- print "Executing code blocks in #{README_ORG} ... "
20
- GemDocs::Emacs.tangle
21
- FileUtils.touch(STAMP)
12
+ file CHANGELOG_MD => CHANGELOG_ORG do
13
+ print "Exporting \"#{CHANGELOG_ORG}\" "
14
+ GemDocs::Emacs.export_changelog
22
15
  end
23
16
 
24
17
  namespace :docs do
25
18
  desc "Evaluate code blocks in README.org"
26
- task :tangle => [:skeleton, STAMP]
19
+ task :tangle => ["docs:skeleton:readme"] do
20
+ print "Executing code blocks in #{README_ORG} ... "
21
+ GemDocs::Emacs.tangle
22
+ end
27
23
 
28
24
  desc "Export README.org → README.md"
29
- task :export => [:badge, README_MD]
25
+ task :export => [:badge, README_MD, CHANGELOG_MD]
30
26
 
31
27
  desc "Extract overview from README.org and embed in lib/<gem>.rb for ri/yard"
32
- task :overview => [:skeleton, README_ORG] do
28
+ task :overview => ["docs:skeleton:readme", README_ORG] do
33
29
  print "Embedding overview extracted from #{GemDocs::README_ORG} into main gem file ... "
34
30
  if GemDocs::Overview.write_overview?
35
31
  puts "added"
@@ -38,17 +34,28 @@ module GemDocs
38
34
  end
39
35
  end
40
36
 
41
- desc "Create skeleton README.org if one does not exist"
42
- task :skeleton do
43
- if GemDocs::Skeleton.make_readme?
44
- puts "README.org added"
45
- else
46
- puts "README.org already present"
37
+ namespace :skeleton do
38
+ desc "Create skeleton README.org if one does not exist"
39
+ task :readme do
40
+ if GemDocs::Skeleton.make_readme?
41
+ puts "README.org added"
42
+ else
43
+ puts "README.org already present"
44
+ end
45
+ end
46
+
47
+ desc "Create skeleton CHANGELOG.org if one does not exist"
48
+ task :changelog do
49
+ if GemDocs::Skeleton.make_changelog?
50
+ puts "CHANGELOG.org added"
51
+ else
52
+ puts "CHANGELOG.org already present"
53
+ end
47
54
  end
48
55
  end
49
56
 
50
57
  desc "Insert #+PROPERTY headers at top of README.org for code blocks"
51
- task :header => :skeleton do
58
+ task :header => "docs:skeleton:readme" do
52
59
  print "Inserting headers ... "
53
60
  if GemDocs::Header.write_header?
54
61
  puts "added"
@@ -64,9 +71,8 @@ module GemDocs
64
71
  end
65
72
 
66
73
  desc "Ensure GitHub Actions badge exists in README.org"
67
- task :badge => :skeleton do
74
+ task :badge => "docs:skeleton:readme" do
68
75
  print "Ensuring badges are in README.org ... "
69
-
70
76
  if GemDocs::Badge.ensure!
71
77
  puts "added"
72
78
  else
@@ -75,7 +81,7 @@ module GemDocs
75
81
  end
76
82
 
77
83
  desc "Run all documentation tasks (examples, readme, overview, yard, ri)"
78
- task :all => [:skeleton, :header, :tangle, :export, :overview, :yard]
84
+ task :all => ["docs:skeleton:readme", "docs:skeleton:changelog", :header, :tangle, :export, :overview, :yard]
79
85
  end
80
86
  end
81
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GemDocs
4
- VERSION = "0.1.2"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/gem_docs.rb CHANGED
@@ -11,10 +11,7 @@ require "fileutils"
11
11
 
12
12
  # Gem Overview (extracted from README.org by gem_docs)
13
13
  #
14
- #
15
- #
16
14
  # * Overview
17
- #
18
15
  # One of the more onerous tasks when writing a ~gem~ or other ~github~ project
19
16
  # is maintaining the documentation, and keeping it consistent and up-to-date.
20
17
  # One of the better options for writing the ~README~ file that gets displayed by
@@ -40,24 +37,32 @@ require "fileutils"
40
37
  # of the library,
41
38
  # - running the code block examples in a ~README.org~ by invoking ~emacsclient~,
42
39
  # - exporting ~README.org~ to Git-flavored markdown in ~README.md~
40
+ # - exporting ~CHANGELOG.org~ to Git-flavored markdown in ~CHANGELOG.md~
43
41
  # - ensuring a workflow or ci badge is present in the ~README.md~
44
42
  # - generating yard documents for your repo, and
45
43
  # - copying the introductory contents of the README as a leading comment in your
46
44
  # main gem library file so it gets picked up as an overview for ~ri~ and ~yri~
47
45
  #
48
46
  # * Usage
49
- #
50
47
  # ** Create a skeleton README.org file
51
48
  # This is a simple task that creates a bare-bones ~README.org~ file to get
52
49
  # started with. It does create the file with the name of the gem and other repo
53
50
  # detains filled in. If there is already a README.org file, it does nothing.
54
51
  #
55
52
  # #+begin_src ruby :eval no
56
- # rake docs:skeleton
53
+ # rake docs:skeleton:readme
54
+ # #+end_src
55
+ #
56
+ # ** Create a skeleton CHANGELOG.org file
57
+ # This is a simple task that creates a bare-bones ~CHANGELOG.org~ file to get
58
+ # started with. It only contains some tips for writing a change log and a
59
+ # sample heading. If there is already a CHANGELOG.org file, it does nothing.
60
+ #
61
+ # #+begin_src ruby :eval no
62
+ # rake docs:skeleton:changelog
57
63
  # #+end_src
58
64
  #
59
65
  # ** Add proper ~#+PROPERTY~ headers in ~README.org~: ~rake docs:headers~
60
- # **
61
66
  # Getting emacs code blocks to render well in your ~README.org~ takes proper
62
67
  # configuration of the code block headers in Emacs.
63
68
  #
@@ -113,7 +118,13 @@ require "fileutils"
113
118
  # the gem, etc. Of course, you can override this for particular code blocks.
114
119
  #
115
120
  # Those headers are in fact what I am using in this ~README~, and here is how
116
- # they work:
121
+ # they work.
122
+ #
123
+ # *** Output Tables
124
+ # You can build table for ~org~ to display in the output by returning an array
125
+ # of arrays, which org-mode renders as a table in the output. You can add an
126
+ # hline to the output table by simply adding ~nil~ to the outer array where you
127
+ # want the hline to occur.
117
128
  #
118
129
  # #+begin_src ruby
119
130
  # result = []
@@ -142,10 +153,25 @@ require "fileutils"
142
153
  # | 3.3333333333333335 | 28.03162489452614 |
143
154
  # #+end_example
144
155
  #
145
- # I built the table in the output by returning an array of arrays, which
146
- # org-mode renders as a table in the output. Notice that I added an hline to
147
- # the output by simply adding ~nil~ to the outer array where I wanted the hline
148
- # to occur.
156
+ # *** Output Values
157
+ # Sometimes, however, you just want the result of the code block evaluated
158
+ # without building a table. To do so, just set the block header to ~:results
159
+ # value raw~.
160
+ #
161
+ # To compute the value of an $1,000 asset gaining 5% continuously compounding
162
+ # interest over four years, you might do this:
163
+ #
164
+ # #+begin_src ruby :results value raw
165
+ # rate = 0.05
166
+ # time = 4
167
+ # principal = 1000
168
+ # principal * Math.exp(rate * time)
169
+ # #+end_src
170
+ #
171
+ # #+RESULTS:
172
+ # #+begin_example
173
+ # 1221.40275816017
174
+ # #+end_example
149
175
  #
150
176
  # Apart from all the convenient markup that ~org-mode~ allows, the ability to
151
177
  # easily demonstrate your gem's code in this way is the real killer feature of
@@ -174,6 +200,11 @@ require "fileutils"
174
200
  # rake docs:tangle
175
201
  # #+end_src
176
202
  #
203
+ # With the default headers provided by `rake docs:headers`, the buffer is
204
+ # evaluated in a session so that code blocks can build on one another. However,
205
+ # `docs:tangle` kills any existing session buffer before it runs so that each
206
+ # buffer evaluation is independent of earlier runs.
207
+ #
177
208
  # ** Ensure that a Badge is Present in ~README.md~: ~rake docs:badge~
178
209
  # It is reassuring to consumers of your gem that your gem passes its workflow
179
210
  # tests on github. This task checks to see if a "badge" indicating success or
@@ -187,7 +218,7 @@ require "fileutils"
187
218
  # If there is already a badge present, the task will not modify the ~README.org~
188
219
  # file.
189
220
  #
190
- # ** Export ~README.org~ to ~README.md~: ~rake docs:export~
221
+ # ** Export ~README.org~ and ~CHANGELOG.org~ to Markdown: ~rake docs:export~
191
222
  # You can write the ~README~ in Emacs org-mode, using all its features
192
223
  # including the execution of code blocks, and then export to git-flavored
193
224
  # markdown.
@@ -208,6 +239,10 @@ require "fileutils"
208
239
  # you want to have one for your own purposes, just set the ~:noexport~ tag on it
209
240
  # so it doesn't get put into the ~README.md~
210
241
  #
242
+ # Less important, but still handy, you can also write the CHANGELOG in org mode
243
+ # and this task will convert it to markdown for display on github and
244
+ # rubygems.org.
245
+ #
211
246
  # #+begin_src ruby :eval no
212
247
  # rake docs:export
213
248
  # #+end_src
@@ -254,6 +289,8 @@ module GemDocs
254
289
 
255
290
  README_ORG = "README.org"
256
291
  README_MD = "README.md"
292
+ CHANGELOG_ORG = "CHANGELOG.org"
293
+ CHANGELOG_MD = "CHANGELOG.md"
257
294
 
258
295
  # Auto-detect project root (handles being run from subdirs)
259
296
  def self.project_root
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.1.2
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel E. Doherty
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-12-23 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubygems_version: 3.6.3
79
+ rubygems_version: 4.0.3
80
80
  specification_version: 4
81
81
  summary: Documentation automation for Ruby gems
82
82
  test_files: []