living_document 2.0.0 → 2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd6766fedfe5bb15663673387072f43334a43fe590b5651721439c16c9b6d5d8
4
- data.tar.gz: c561e58301674a99838f44c7b14b12474708dc3182b7efc1df6c6572315135bb
3
+ metadata.gz: 3680ab9cf85cc909a679c876a1dcdc5ce3f5e870419efa17770208f4c7359bb5
4
+ data.tar.gz: 76edf601a178c8afc1d88040f591a4b8e4026282bdf5d4dec3c4b415f36af01e
5
5
  SHA512:
6
- metadata.gz: bf6d65cf5d6e555dfd490e5bc7275d818a4713670995ec26c8794102cd9d069a28abd73eadba0975c2aacda87a2d4fca1f5e32de0df3d30fcbced4e622053c45
7
- data.tar.gz: ebc0761b7f74e662d7eb7b32cb6509926504237c7437b47be53b20dd14074a6fda5a8d529eb4ae1a335f56d2e7bed1b3cb0f49c6b5fb225e8194184f4f5ff221
6
+ metadata.gz: 5173bd8e3e6d4c96017db480009272e8016af8b2735281ccafbef5a673ed079dd0163a43bea963222e603a8be84e5cf0081c641dc92fbb68fd0bf0da295e9bc5
7
+ data.tar.gz: 2ebc0946d141e3b18b5d84cc792ce88d88f1f749745294efa566f6074a23063665596064e8a672e9c5cf504343261bf8d0af8ee0dd0003da0e7634c87ea9e8b4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v2.1.0 (2025-02-05)
2
+ - Offer to create the provided target file, if it doesn't yet exist.
3
+ - Document compatibility with VS Code and NeoVim.
4
+ - Automatically open the target file in editor, if `$EDITOR` is set.
5
+
1
6
  ## v2.0.0 (2025-02-05)
2
7
  - **BREAKING:** Use `rb-inotify` (not `listen`) to watch for file changes. This means that the gem is now only compatible with Linux.
3
8
  - Support listening to files outside of the current directory.
data/Gemfile.lock CHANGED
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- living_document (2.0.0)
12
+ living_document (2.1.0)
13
13
  activesupport (>= 6)
14
14
  memo_wise (>= 1.7)
15
15
  rb-inotify (>= 0.11.1)
@@ -211,7 +211,7 @@ CHECKSUMS
211
211
  irb (1.15.1) sha256=d9bca745ac4207a8b728a52b98b766ca909b86ff1a504bcde3d6f8c84faae890
212
212
  json (2.9.1) sha256=d2bdef4644052fad91c1785d48263756fe32fcac08b96a20bb15840e96550d11
213
213
  language_server-protocol (3.17.0.4) sha256=c484626478664fd13482d8180947c50a8590484b1258b99b7aedb3b69df89669
214
- living_document (2.0.0)
214
+ living_document (2.1.0)
215
215
  logger (1.6.5) sha256=c3cfe56d01656490ddd103d38b8993d73d86296adebc5f58cefc9ec03741e56b
216
216
  memo_wise (1.10.0) sha256=ae40ff8e7799697ff5d59d739b8766f76be22eba69c7c8468edb42ab83c94c3f
217
217
  method_source (1.1.0) sha256=181301c9c45b731b4769bc81e8860e72f9161ad7d66dd99103c9ab84f560f5c5
data/README.md CHANGED
@@ -39,6 +39,9 @@ In other words, the special markers `###` and `# =>` tell LivingDocument to eval
39
39
  * [Linux only <g-emoji class="g-emoji" alias="warning">⚠️</g-emoji>](#️-linux-only-️)
40
40
  * [Installation](#installation)
41
41
  * [Usage](#usage)
42
+ * [Editor compatibility](#editor-compatibility)
43
+ * [VS Code](#vs-code)
44
+ * [NeoVim](#neovim)
42
45
  * [Markdown support](#markdown-support)
43
46
  * [Time is frozen](#time-is-frozen)
44
47
  * [Development](#development)
@@ -46,7 +49,7 @@ In other words, the special markers `###` and `# =>` tell LivingDocument to eval
46
49
  * [License](#license)
47
50
 
48
51
  <!-- Created by https://github.com/ekalinin/github-markdown-toc -->
49
- <!-- Added by: david, at: Wed Feb 5 09:31:36 PM CST 2025 -->
52
+ <!-- Added by: david, at: Wed Feb 5 11:12:42 PM CST 2025 -->
50
53
 
51
54
  <!--te-->
52
55
 
@@ -102,6 +105,28 @@ puts('This is one great string!')
102
105
 
103
106
  Then, edit the file and save it again. You'll see that the `# => ` comments are automatically and immediately updated to reflect your edits.
104
107
 
108
+ ## Editor compatibility
109
+
110
+ ### VS Code
111
+
112
+ LivingDocument should work with VS Code "out of the box".
113
+
114
+ ### NeoVim
115
+
116
+ For LivingDocument to work with NeoVim, you will need to add config like this to your `init.lua`:
117
+
118
+ ```lua
119
+ -- Auto-reload files changed outside NeoVim.
120
+ vim.opt.autoread = true
121
+ -- Preserve inodes when saving / modify files in place.
122
+ vim.opt.backupcopy = 'yes'
123
+ -- Check for changes when switching buffers, cursor idles, or NeoVim regains focus.
124
+ vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "CursorHoldI", "FocusGained" }, {
125
+ command = "if mode() != 'c' | checktime | endif",
126
+ pattern = { "*" },
127
+ })
128
+ ```
129
+
105
130
  ## Markdown support
106
131
 
107
132
  LivingDocument can also handle Markdown code, which is especially convenient when developing
data/exe/livdoc CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  # frozen_string_literal: true
4
4
 
5
+ require 'io/console'
5
6
  require 'optparse'
6
7
  require 'rb-inotify'
7
8
 
@@ -34,6 +35,26 @@ def evaluate_code_and_update_source_file(file_path, evaluation_reason:)
34
35
 
35
36
  puts('waiting for changes.')
36
37
  end
38
+
39
+ def ask_to_create_file_if_needed(expanded_path)
40
+ if !File.exist?(expanded_path)
41
+ puts(<<~QUESTION)
42
+ The target file (#{expanded_path}) does not exist.
43
+ Would you like living_document to create it? [y]n
44
+ QUESTION
45
+
46
+ case $stdin.getch
47
+ when 'n', "\u0003" # Ctrl-C
48
+ puts('Okay, then, exiting.')
49
+ exit(0)
50
+ when 'y', "\r"
51
+ FileUtils.touch(expanded_path)
52
+ else
53
+ puts("\nThat's not an option.\n\n")
54
+ ask_to_create_file_if_needed(expanded_path)
55
+ end
56
+ end
57
+ end
37
58
  # rubocop:enable Style/TopLevelMethodDefinition
38
59
 
39
60
  file_path = ARGV[0]
@@ -44,6 +65,13 @@ if file_path.nil?
44
65
  end
45
66
 
46
67
  expanded_path = File.expand_path(file_path)
68
+
69
+ ask_to_create_file_if_needed(expanded_path)
70
+
71
+ if system('[ -n "$EDITOR" ]')
72
+ system("$EDITOR #{expanded_path}")
73
+ end
74
+
47
75
  notifier = INotify::Notifier.new
48
76
  last_file_update = Time.now
49
77
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LivingDocument
4
- VERSION = '2.0.0'
4
+ VERSION = '2.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: living_document
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Runger